Skip to content

Commit b81acaa

Browse files
committed
Add impl docs for optional impls
1 parent 4f80c32 commit b81acaa

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/types/mod.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ impl RawFromSql for json::Json {
346346
}
347347

348348
macro_rules! from_map_impl(
349-
($($expected:pat)|+, $t:ty, $blk:expr) => (
349+
($($expected:pat)|+, $t:ty, $blk:expr $(, $a:meta)*) => (
350+
$(#[$a])*
350351
impl FromSql for Option<$t> {
351352
fn from_sql(ty: &Type, raw: &Option<Vec<u8>>)
352353
-> Result<Option<$t>> {
@@ -358,6 +359,7 @@ macro_rules! from_map_impl(
358359
}
359360
}
360361

362+
$(#[$a])*
361363
impl FromSql for $t {
362364
fn from_sql(ty: &Type, raw: &Option<Vec<u8>>)
363365
-> Result<$t> {
@@ -374,11 +376,11 @@ macro_rules! from_map_impl(
374376
)
375377

376378
macro_rules! from_raw_from_impl(
377-
($($expected:pat)|+, $t:ty) => (
379+
($($expected:pat)|+, $t:ty $(, $a:meta)*) => (
378380
from_map_impl!($($expected)|+, $t, |buf: &Vec<u8>| {
379381
let mut reader = BufReader::new(buf[]);
380382
RawFromSql::raw_from_sql(&mut reader)
381-
})
383+
} $(, $a)*)
382384
)
383385
)
384386

@@ -392,7 +394,7 @@ from_raw_from_impl!(Int8, i64)
392394
from_raw_from_impl!(Float4, f32)
393395
from_raw_from_impl!(Float8, f64)
394396
#[cfg(feature = "uuid_type")]
395-
from_raw_from_impl!(Uuid, uuid::Uuid)
397+
from_raw_from_impl!(Uuid, uuid::Uuid, doc = "requires the \"uuid_type\" feature")
396398
from_raw_from_impl!(Json, json::Json)
397399

398400
from_raw_from_impl!(Timestamp | TimestampTZ, Timespec)
@@ -401,7 +403,7 @@ from_raw_from_impl!(Int8Range, Range<i64>)
401403
from_raw_from_impl!(TsRange | TstzRange, Range<Timespec>)
402404

403405
macro_rules! from_array_impl(
404-
($($oid:ident)|+, $t:ty) => (
406+
($($oid:ident)|+, $t:ty $(, $a:meta)*) => (
405407
from_map_impl!($($oid)|+, ArrayBase<Option<$t>>, |buf: &Vec<u8>| {
406408
let mut rdr = BufReader::new(buf[]);
407409

@@ -431,7 +433,7 @@ macro_rules! from_array_impl(
431433
}
432434

433435
Ok(ArrayBase::from_raw(elements, dim_info))
434-
})
436+
} $(, $a)*)
435437
)
436438
)
437439

@@ -444,7 +446,7 @@ from_array_impl!(TextArray | CharNArray | VarcharArray | NameArray, String)
444446
from_array_impl!(Int8Array, i64)
445447
from_array_impl!(TimestampArray | TimestampTZArray, Timespec)
446448
#[cfg(feature = "uuid_type")]
447-
from_array_impl!(UuidArray, uuid::Uuid)
449+
from_array_impl!(UuidArray, uuid::Uuid, doc = "requires the \"uuid_type\" feature")
448450
from_array_impl!(JsonArray, json::Json)
449451
from_array_impl!(Float4Array, f32)
450452
from_array_impl!(Float8Array, f64)
@@ -630,7 +632,8 @@ impl RawToSql for json::Json {
630632
}
631633

632634
macro_rules! to_option_impl(
633-
($($oid:pat)|+, $t:ty) => (
635+
($($oid:pat)|+, $t:ty $(,$a:meta)*) => (
636+
$(#[$a])*
634637
impl ToSql for Option<$t> {
635638
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
636639
check_types!($($oid)|+, ty)
@@ -660,7 +663,8 @@ macro_rules! to_option_impl_lifetime(
660663
)
661664

662665
macro_rules! to_raw_to_impl(
663-
($($oid:ident)|+, $t:ty) => (
666+
($($oid:ident)|+, $t:ty $(, $a:meta)*) => (
667+
$(#[$a])*
664668
impl ToSql for $t {
665669
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
666670
check_types!($($oid)|+, ty)
@@ -671,15 +675,15 @@ macro_rules! to_raw_to_impl(
671675
}
672676
}
673677

674-
to_option_impl!($($oid)|+, $t)
678+
to_option_impl!($($oid)|+, $t $(, $a)*)
675679
)
676680
)
677681

678682
to_raw_to_impl!(Bool, bool)
679683
to_raw_to_impl!(ByteA, Vec<u8>)
680684
to_raw_to_impl!(Varchar | Text | CharN | Name, String)
681685
#[cfg(feature = "uuid_type")]
682-
to_raw_to_impl!(Uuid, uuid::Uuid)
686+
to_raw_to_impl!(Uuid, uuid::Uuid, doc = "requires the \"uuid_type\" feature")
683687
to_raw_to_impl!(Json, json::Json)
684688
to_raw_to_impl!(Char, i8)
685689
to_raw_to_impl!(Int2, i16)
@@ -712,7 +716,8 @@ to_option_impl_lifetime!(ByteA, &'a [u8])
712716
to_raw_to_impl!(Timestamp | TimestampTZ, Timespec)
713717

714718
macro_rules! to_array_impl(
715-
($($oid:ident)|+, $t:ty) => (
719+
($($oid:ident)|+, $t:ty $(, $a:meta)*) => (
720+
$(#[$a])*
716721
impl ToSql for ArrayBase<Option<$t>> {
717722
fn to_sql(&self, ty: &Type) -> Result<Option<Vec<u8>>> {
718723
check_types!($($oid)|+, ty)
@@ -744,7 +749,7 @@ macro_rules! to_array_impl(
744749
}
745750
}
746751

747-
to_option_impl!($($oid)|+, ArrayBase<Option<$t>>)
752+
to_option_impl!($($oid)|+, ArrayBase<Option<$t>> $(, $a)*)
748753
)
749754
)
750755

@@ -762,7 +767,7 @@ to_array_impl!(Int4RangeArray, Range<i32>)
762767
to_array_impl!(TsRangeArray | TstzRangeArray, Range<Timespec>)
763768
to_array_impl!(Int8RangeArray, Range<i64>)
764769
#[cfg(feature = "uuid_type")]
765-
to_array_impl!(UuidArray, uuid::Uuid)
770+
to_array_impl!(UuidArray, uuid::Uuid, doc = "requires the \"uuid_type\" feature")
766771
to_array_impl!(JsonArray, json::Json)
767772

768773
impl ToSql for HashMap<String, Option<String>> {

0 commit comments

Comments
 (0)