formatting fixup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-07-30 15:20:55 +02:00
parent d5ee03da9f
commit 2a4af329a7
2 changed files with 47 additions and 31 deletions

View File

@ -673,22 +673,28 @@ fn wrap_serialize_with(
with: &syn::Path, with: &syn::Path,
) -> (TokenStream, Ident) { ) -> (TokenStream, Ident) {
let helper_name = Ident::new( let helper_name = Ident::new(
&format!("SerializeWith{}", crate::util::to_camel_case(&name.to_string())), &format!(
"SerializeWith{}",
crate::util::to_camel_case(&name.to_string())
),
name.span(), name.span(),
); );
(quote_spanned! { span => (
struct #helper_name<'a>(&'a #ty); quote_spanned! { span =>
struct #helper_name<'a>(&'a #ty);
impl<'a> ::serde::ser::Serialize for #helper_name<'a> { impl<'a> ::serde::ser::Serialize for #helper_name<'a> {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where where
S: ::serde::ser::Serializer, S: ::serde::ser::Serializer,
{ {
#with(self.0, serializer) #with(self.0, serializer)
}
} }
} },
}, helper_name) helper_name,
)
} }
fn named_struct_derive_serialize( fn named_struct_derive_serialize(
@ -749,28 +755,34 @@ fn wrap_deserialize_with(
with: &syn::Path, with: &syn::Path,
) -> (TokenStream, Ident) { ) -> (TokenStream, Ident) {
let helper_name = Ident::new( let helper_name = Ident::new(
&format!("DeserializeWith{}", crate::util::to_camel_case(&name.to_string())), &format!(
"DeserializeWith{}",
crate::util::to_camel_case(&name.to_string())
),
name.span(), name.span(),
); );
(quote_spanned! { span => (
struct #helper_name<'de> { quote_spanned! { span =>
value: #ty, struct #helper_name<'de> {
_lifetime: ::std::marker::PhantomData<&'de ()>, value: #ty,
} _lifetime: ::std::marker::PhantomData<&'de ()>,
impl<'de> ::serde::de::Deserialize<'de> for #helper_name<'de> {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: ::serde::de::Deserializer<'de>,
{
Ok(Self {
value: #with(deserializer)?,
_lifetime: ::std::marker::PhantomData,
})
} }
}
}, helper_name) impl<'de> ::serde::de::Deserialize<'de> for #helper_name<'de> {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: ::serde::de::Deserializer<'de>,
{
Ok(Self {
value: #with(deserializer)?,
_lifetime: ::std::marker::PhantomData,
})
}
}
},
helper_name,
)
} }
fn named_struct_derive_deserialize( fn named_struct_derive_deserialize(

View File

@ -95,11 +95,15 @@ impl<T: AsRef<str>> TestMinMaxLen<mark::Default> for T {
impl<T: AsRef<str>> TestMinMaxLen<mark::Special> for Option<T> { impl<T: AsRef<str>> TestMinMaxLen<mark::Special> for Option<T> {
#[inline] #[inline]
fn test_minimum_length(&self, minimum: usize) -> bool { fn test_minimum_length(&self, minimum: usize) -> bool {
self.as_ref().map(|x| x.as_ref().len() >= minimum).unwrap_or(true) self.as_ref()
.map(|x| x.as_ref().len() >= minimum)
.unwrap_or(true)
} }
#[inline] #[inline]
fn test_maximum_length(&self, maximum: usize) -> bool { fn test_maximum_length(&self, maximum: usize) -> bool {
self.as_ref().map(|x| x.as_ref().len() <= maximum).unwrap_or(true) self.as_ref()
.map(|x| x.as_ref().len() <= maximum)
.unwrap_or(true)
} }
} }