diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 7e94ef25..7243b53c 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -60,7 +60,7 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result { + // Parse `#[serde(crate = "foo")]` + Meta(NameValue(ref m)) if m.ident == "crate" => { if let Ok(path) = parse_lit_into_path(cx, &m.ident, &m.lit) { serde_path.set(&m.ident, path) } @@ -682,9 +683,15 @@ impl Container { self.has_flatten = true; } - pub fn serde_path(&self) -> Option<&syn::Path> { + pub fn custom_serde_path(&self) -> Option<&syn::Path> { self.serde_path.as_ref() } + + pub fn serde_path<'a>(&'a self) -> Cow<'a, syn::Path> { + self.custom_serde_path() + .map(Cow::Borrowed) + .unwrap_or_else(|| Cow::Owned(parse_quote!(_serde))) + } } fn decide_tag( diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index 8f3e357c..d5c83bc6 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -22,15 +22,16 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result(__self: &#remote #ty_generics, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error> + #vis fn serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> #serde::export::Result<__S::Ok, __S::Error> where - __S: _serde::Serializer, + __S: #serde::Serializer, { #used #body @@ -40,10 +41,10 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result(&self, __serializer: __S) -> _serde::export::Result<__S::Ok, __S::Error> + impl #impl_generics #serde::Serialize for #ident #ty_generics #where_clause { + fn serialize<__S>(&self, __serializer: __S) -> #serde::export::Result<__S::Ok, __S::Error> where - __S: _serde::Serializer, + __S: #serde::Serializer, { #body } @@ -51,7 +52,7 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result