1- //! Types.
1+ //! Conversions to and from Postgres types.
2+ //!
3+ //! This crate is used by the `tokio-postgres` and `postgres` crates. You normally don't need to depend directly on it
4+ //! unless you want to define your own `ToSql` or `FromSql` definitions.
5+ #![ warn( missing_docs) ]
26
37use fallible_iterator:: FallibleIterator ;
48use postgres_protocol;
59use postgres_protocol:: types:: { self , ArrayDimension } ;
10+ use std:: any:: type_name;
611use std:: borrow:: Cow ;
712use std:: collections:: HashMap ;
813use std:: error:: Error ;
@@ -12,12 +17,12 @@ use std::net::IpAddr;
1217use std:: sync:: Arc ;
1318use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
1419
15- use crate :: types :: type_gen:: { Inner , Other } ;
20+ use crate :: type_gen:: { Inner , Other } ;
1621
1722#[ doc( inline) ]
1823pub use postgres_protocol:: Oid ;
1924
20- pub use crate :: types :: special:: { Date , Timestamp } ;
25+ pub use crate :: special:: { Date , Timestamp } ;
2126
2227// Number of seconds from 1970-01-01 to 2000-01-01
2328const TIME_SEC_CONVERSION : u64 = 946_684_800 ;
@@ -29,9 +34,9 @@ const NSEC_PER_USEC: u64 = 1_000;
2934#[ macro_export]
3035macro_rules! accepts {
3136 ( $( $expected: ident) ,+) => (
32- fn accepts( ty: & $crate:: types :: Type ) -> bool {
37+ fn accepts( ty: & $crate:: Type ) -> bool {
3338 match * ty {
34- $( $crate:: types :: Type :: $expected) |+ => true ,
39+ $( $crate:: Type :: $expected) |+ => true ,
3540 _ => false
3641 }
3742 }
@@ -45,13 +50,13 @@ macro_rules! accepts {
4550macro_rules! to_sql_checked {
4651 ( ) => {
4752 fn to_sql_checked( & self ,
48- ty: & $crate:: types :: Type ,
53+ ty: & $crate:: Type ,
4954 out: & mut :: std:: vec:: Vec <u8 >)
50- -> :: std:: result:: Result <$crate:: types :: IsNull ,
55+ -> :: std:: result:: Result <$crate:: IsNull ,
5156 Box <dyn :: std:: error:: Error +
5257 :: std:: marker:: Sync +
5358 :: std:: marker:: Send >> {
54- $crate:: types :: __to_sql_checked( self , ty, out)
59+ $crate:: __to_sql_checked( self , ty, out)
5560 }
5661 }
5762}
@@ -91,7 +96,6 @@ mod type_gen;
9196
9297#[ cfg( feature = "with-serde_json-1" ) ]
9398pub use crate :: types:: serde_json_1:: Json ;
94- use std:: any:: type_name;
9599
96100/// A Postgres type.
97101#[ derive( PartialEq , Eq , Clone , Debug ) ]
@@ -108,7 +112,8 @@ impl fmt::Display for Type {
108112}
109113
110114impl Type {
111- pub ( crate ) fn new ( name : String , oid : Oid , kind : Kind , schema : String ) -> Type {
115+ /// Creates a new `Type`.
116+ pub fn new ( name : String , oid : Oid , kind : Kind , schema : String ) -> Type {
112117 Type ( Inner :: Other ( Arc :: new ( Other {
113118 name,
114119 oid,
@@ -176,7 +181,8 @@ pub struct Field {
176181}
177182
178183impl Field {
179- pub ( crate ) fn new ( name : String , type_ : Type ) -> Field {
184+ /// Creates a new `Field`.
185+ pub fn new ( name : String , type_ : Type ) -> Field {
180186 Field { name, type_ }
181187 }
182188
@@ -225,7 +231,8 @@ impl fmt::Display for WrongType {
225231impl Error for WrongType { }
226232
227233impl WrongType {
228- pub ( crate ) fn new < T > ( ty : Type ) -> WrongType {
234+ /// Creates a new `WrongType` error.
235+ pub fn new < T > ( ty : Type ) -> WrongType {
229236 WrongType {
230237 postgres : ty,
231238 rust : type_name :: < T > ( ) ,
0 commit comments