26
26
#![ doc( test( attr( warn( rust_2018_idioms) ) ) ) ]
27
27
// Not needed for 2018 edition and conflicts with `rust_2018_idioms`
28
28
#![ doc( test( no_crate_inject) ) ]
29
- #![ doc( html_root_url = "https://docs.rs/serde_with_macros/3.5.0 /" ) ]
29
+ #![ doc( html_root_url = "https://docs.rs/serde_with_macros/3.5.1 /" ) ]
30
30
// Necessary to silence the warning about clippy::unknown_clippy_lints on nightly
31
31
#![ allow( renamed_and_removed_lints) ]
32
32
// Necessary for nightly clippy lints
@@ -602,8 +602,8 @@ fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool {
602
602
/// It will also work if the relevant derive is behind a `#[cfg_attr]` attribute
603
603
/// and propagate the `#[cfg_attr]` to the various `#[schemars]` field attributes.
604
604
///
605
- /// [`serde_as`]: https://docs.rs/serde_with/3.5.0 /serde_with/guide/index.html
606
- /// [re-exporting `serde_as`]: https://docs.rs/serde_with/3.5.0 /serde_with/guide/serde_as/index.html#re-exporting-serde_as
605
+ /// [`serde_as`]: https://docs.rs/serde_with/3.5.1 /serde_with/guide/index.html
606
+ /// [re-exporting `serde_as`]: https://docs.rs/serde_with/3.5.1 /serde_with/guide/serde_as/index.html#re-exporting-serde_as
607
607
#[ proc_macro_attribute]
608
608
pub fn serde_as ( args : TokenStream , input : TokenStream ) -> TokenStream {
609
609
#[ derive( FromMeta ) ]
@@ -782,10 +782,19 @@ fn serde_as_add_attr_to_field(
782
782
field. attrs . push ( attr) ;
783
783
784
784
if let Some ( cfg) = schemars_config. cfg_expr ( ) {
785
+ let with_cfg = crate :: utils:: schemars_with_attr_if (
786
+ & field. attrs ,
787
+ & [ "with" , "serialize_with" , "deserialize_with" ] ,
788
+ ) ?;
785
789
let attr_inner_tokens =
786
790
quote ! ( #serde_with_crate_path:: Schema :: <#type_original, #replacement_type>)
787
791
. to_string ( ) ;
788
- let attr = parse_quote ! ( #[ cfg_attr( #cfg, schemars( with = #attr_inner_tokens) ) ] ) ;
792
+ let attr = parse_quote ! {
793
+ #[ cfg_attr(
794
+ all( #cfg, not( #with_cfg) ) ,
795
+ schemars( with = #attr_inner_tokens) )
796
+ ]
797
+ } ;
789
798
field. attrs . push ( attr) ;
790
799
}
791
800
}
@@ -800,11 +809,17 @@ fn serde_as_add_attr_to_field(
800
809
field. attrs . push ( attr) ;
801
810
802
811
if let Some ( cfg) = schemars_config. cfg_expr ( ) {
812
+ let with_cfg =
813
+ crate :: utils:: schemars_with_attr_if ( & field. attrs , & [ "with" , "deserialize_with" ] ) ?;
803
814
let attr_inner_tokens =
804
815
quote ! ( #serde_with_crate_path:: Schema :: <#type_original, #replacement_type>:: deserialize)
805
816
. to_string ( ) ;
806
- let attr =
807
- parse_quote ! ( #[ cfg_attr( #cfg, schemars( deserialize_with = #attr_inner_tokens) ) ] ) ;
817
+ let attr = parse_quote ! {
818
+ #[ cfg_attr(
819
+ all( #cfg, not( #with_cfg) ) ,
820
+ schemars( deserialize_with = #attr_inner_tokens) )
821
+ ]
822
+ } ;
808
823
field. attrs . push ( attr) ;
809
824
}
810
825
}
@@ -816,11 +831,17 @@ fn serde_as_add_attr_to_field(
816
831
field. attrs . push ( attr) ;
817
832
818
833
if let Some ( cfg) = schemars_config. cfg_expr ( ) {
834
+ let with_cfg =
835
+ crate :: utils:: schemars_with_attr_if ( & field. attrs , & [ "with" , "serialize_with" ] ) ?;
819
836
let attr_inner_tokens =
820
837
quote ! ( #serde_with_crate_path:: Schema :: <#type_original, #replacement_type>:: serialize)
821
838
. to_string ( ) ;
822
- let attr =
823
- parse_quote ! ( #[ cfg_attr( #cfg, schemars( serialize_with = #attr_inner_tokens) ) ] ) ;
839
+ let attr = parse_quote ! {
840
+ #[ cfg_attr(
841
+ all( #cfg, not( #with_cfg) ) ,
842
+ schemars( serialize_with = #attr_inner_tokens) )
843
+ ]
844
+ } ;
824
845
field. attrs . push ( attr) ;
825
846
}
826
847
}
@@ -1057,7 +1078,7 @@ fn has_type_embedded(type_: &Type, embedded_type: &syn::Ident) -> bool {
1057
1078
/// [`Display`]: std::fmt::Display
1058
1079
/// [`FromStr`]: std::str::FromStr
1059
1080
/// [cargo-toml-rename]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
1060
- /// [serde-as-crate]: https://docs.rs/serde_with/3.5.0 /serde_with/guide/serde_as/index.html#re-exporting-serde_as
1081
+ /// [serde-as-crate]: https://docs.rs/serde_with/3.5.1 /serde_with/guide/serde_as/index.html#re-exporting-serde_as
1061
1082
/// [serde-crate]: https://serde.rs/container-attrs.html#crate
1062
1083
#[ proc_macro_derive( DeserializeFromStr , attributes( serde_with) ) ]
1063
1084
pub fn derive_deserialize_fromstr ( item : TokenStream ) -> TokenStream {
@@ -1177,7 +1198,7 @@ fn deserialize_fromstr(mut input: DeriveInput, serde_with_crate_path: Path) -> T
1177
1198
/// [`Display`]: std::fmt::Display
1178
1199
/// [`FromStr`]: std::str::FromStr
1179
1200
/// [cargo-toml-rename]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
1180
- /// [serde-as-crate]: https://docs.rs/serde_with/3.5.0 /serde_with/guide/serde_as/index.html#re-exporting-serde_as
1201
+ /// [serde-as-crate]: https://docs.rs/serde_with/3.5.1 /serde_with/guide/serde_as/index.html#re-exporting-serde_as
1181
1202
/// [serde-crate]: https://serde.rs/container-attrs.html#crate
1182
1203
#[ proc_macro_derive( SerializeDisplay , attributes( serde_with) ) ]
1183
1204
pub fn derive_serialize_display ( item : TokenStream ) -> TokenStream {
0 commit comments