diff --git a/o2o-impl/benches/o2o_benchmarks.rs b/o2o-impl/benches/o2o_benchmarks.rs index 498b1e9..a3b7a3d 100644 --- a/o2o-impl/benches/o2o_benchmarks.rs +++ b/o2o-impl/benches/o2o_benchmarks.rs @@ -14,9 +14,7 @@ fn derive_simple_benchmark(c: &mut Criterion) { }; let input: DeriveInput = syn::parse2(tokens).unwrap(); - c.bench_function("derive_simple_benchmark", |b| { - b.iter(|| derive(black_box(&input.clone()))) - }); + c.bench_function("derive_simple_benchmark", |b| b.iter(|| derive(black_box(&input.clone())))); } fn derive_complex_benchmark(c: &mut Criterion) { @@ -59,9 +57,7 @@ fn derive_complex_benchmark(c: &mut Criterion) { }; let input: DeriveInput = syn::parse2(tokens).unwrap(); - c.bench_function("derive_complex_benchmark", |b| { - b.iter(|| derive(black_box(&input.clone()))) - }); + c.bench_function("derive_complex_benchmark", |b| b.iter(|| derive(black_box(&input.clone())))); } criterion_group!(benches, derive_simple_benchmark, derive_complex_benchmark); diff --git a/o2o-impl/src/ast.rs b/o2o-impl/src/ast.rs index db02c61..ab4a53c 100644 --- a/o2o-impl/src/ast.rs +++ b/o2o-impl/src/ast.rs @@ -4,9 +4,7 @@ use proc_macro2::Span; use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::token::Comma; -use syn::{ - Attribute, DataEnum, DataStruct, DeriveInput, Fields, Generics, Ident, Index, Member, Result, -}; +use syn::{Attribute, DataEnum, DataStruct, DeriveInput, Fields, Generics, Ident, Index, Member, Result}; #[derive(Default)] struct Context { @@ -59,9 +57,7 @@ impl<'a> Field { if let Some(repeat_attr) = &field.attrs.repeat { if ctx.field_attrs_to_repeat.is_some() && !field.attrs.stop_repeat { - panic!( - "Previous #[repeat] instruction must be terminated with #[stop_repeat]" - ) + panic!("Previous #[repeat] instruction must be terminated with #[stop_repeat]") } ctx.field_attrs_to_repeat = Some((field.attrs.clone(), repeat_attr.permeate)); @@ -78,12 +74,7 @@ impl<'a> Field { Ok(Field { attrs: attr::get_member_attrs(SynDataTypeMember::Field(node), bark)?, idx: i, - member: node.ident.clone().map(Member::Named).unwrap_or_else(|| { - Member::Unnamed(Index { - index: i as u32, - span: node.ty.span(), - }) - }), + member: node.ident.clone().map(Member::Named).unwrap_or_else(|| Member::Unnamed(Index { index: i as u32, span: node.ty.span() })), }) } } @@ -99,12 +90,7 @@ impl<'a> Enum<'a> { pub fn from_syn(node: &'a DeriveInput, data: &'a DataEnum) -> Result { let (attrs, bark) = attr::get_data_type_attrs(&node.attrs)?; let variants = Variant::multiple_from_syn(&data.variants, bark)?; - Ok(Enum { - attrs, - ident: &node.ident, - generics: &node.generics, - variants, - }) + Ok(Enum { attrs, ident: &node.ident, generics: &node.generics, variants }) } } @@ -118,14 +104,8 @@ pub(crate) struct Variant { } impl<'a> Variant { - fn multiple_from_syn( - variants: &'a Punctuated, - bark: bool, - ) -> Result> { - let mut ctx = Context { - variant_attrs_to_repeat: None, - field_attrs_to_repeat: None, - }; + fn multiple_from_syn(variants: &'a Punctuated, bark: bool) -> Result> { + let mut ctx = Context { variant_attrs_to_repeat: None, field_attrs_to_repeat: None }; variants .iter() @@ -139,9 +119,7 @@ impl<'a> Variant { if variant.attrs.repeat.is_some() { if ctx.variant_attrs_to_repeat.is_some() && !variant.attrs.stop_repeat { - panic!( - "Previous #[repeat] instruction must be terminated with #[stop_repeat]" - ) + panic!("Previous #[repeat] instruction must be terminated with #[stop_repeat]") } ctx.variant_attrs_to_repeat = Some(variant.attrs.clone()); @@ -154,12 +132,7 @@ impl<'a> Variant { .collect() } - fn from_syn( - ctx: &mut Context, - i: usize, - variant: &'a syn::Variant, - bark: bool, - ) -> Result { + fn from_syn(ctx: &mut Context, i: usize, variant: &'a syn::Variant, bark: bool) -> Result { let fields = Field::multiple_from_syn(ctx, &variant.fields, bark)?; let attrs = attr::get_member_attrs(SynDataTypeMember::Variant(variant), bark)?; diff --git a/o2o-impl/src/attr.rs b/o2o-impl/src/attr.rs index 86f7970..94a6a7d 100644 --- a/o2o-impl/src/attr.rs +++ b/o2o-impl/src/attr.rs @@ -48,21 +48,9 @@ pub(crate) enum DataTypeInstruction { Children(ChildrenAttr), AllowUnknown, - Misplaced { - instr: &'static str, - span: Span, - own: bool, - }, - Misnamed { - instr: &'static str, - span: Span, - guess_name: &'static str, - own: bool, - }, - UnrecognizedWithError { - instr: String, - span: Span, - }, + Misplaced { instr: &'static str, span: Span, own: bool }, + Misnamed { instr: &'static str, span: Span, guess_name: &'static str, own: bool }, + UnrecognizedWithError { instr: String, span: Span }, Unrecognized, } @@ -81,21 +69,9 @@ pub(crate) enum MemberInstruction { SkipRepeat, StopRepeat, - Misplaced { - instr: &'static str, - span: Span, - own: bool, - }, - Misnamed { - instr: &'static str, - span: Span, - guess_name: &'static str, - own: bool, - }, - UnrecognizedWithError { - instr: String, - span: Span, - }, + Misplaced { instr: &'static str, span: Span, own: bool }, + Misnamed { instr: &'static str, span: Span, guess_name: &'static str, own: bool }, + UnrecognizedWithError { instr: String, span: Span }, Unrecognized, } @@ -212,60 +188,28 @@ pub(crate) struct DataTypeAttrs { } impl<'a> DataTypeAttrs { - pub(crate) fn iter_for_kind( - &'a self, - kind: &'a Kind, - fallible: bool, - ) -> impl Iterator { - self.attrs - .iter() - .filter(move |x| x.fallible == fallible && x.applicable_to[kind]) + pub(crate) fn iter_for_kind(&'a self, kind: &'a Kind, fallible: bool) -> impl Iterator { + self.attrs.iter().filter(move |x| x.fallible == fallible && x.applicable_to[kind]) } - pub(crate) fn iter_for_kind_core( - &'a self, - kind: &'a Kind, - fallible: bool, - ) -> impl Iterator { + pub(crate) fn iter_for_kind_core(&'a self, kind: &'a Kind, fallible: bool) -> impl Iterator { self.iter_for_kind(kind, fallible).map(|x| &x.core) } - pub(crate) fn ghosts_attr( - &'a self, - container_ty: &'a TypePath, - kind: &'a Kind, - ) -> Option<&StructGhostAttrCore> { + pub(crate) fn ghosts_attr(&'a self, container_ty: &'a TypePath, kind: &'a Kind) -> Option<&StructGhostAttrCore> { self.ghosts_attrs .iter() - .find(|x| { - x.applicable_to[kind] - && x.attr.container_ty.is_some() - && x.attr.container_ty.as_ref().unwrap() == container_ty - }) - .or_else(|| { - self.ghosts_attrs - .iter() - .find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none()) - }) + .find(|x| x.applicable_to[kind] && x.attr.container_ty.is_some() && x.attr.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.ghosts_attrs.iter().find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none())) .map(|x| &x.attr) } pub(crate) fn where_attr(&'a self, container_ty: &TypePath) -> Option<&WhereAttr> { - self.where_attrs - .iter() - .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| self.where_attrs.iter().find(|x| x.container_ty.is_none())) + self.where_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.where_attrs.iter().find(|x| x.container_ty.is_none())) } pub(crate) fn children_attr(&'a self, container_ty: &TypePath) -> Option<&ChildrenAttr> { - self.children_attrs - .iter() - .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| { - self.children_attrs - .iter() - .find(|x| x.container_ty.is_none()) - }) + self.children_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.children_attrs.iter().find(|x| x.container_ty.is_none())) } } @@ -316,10 +260,7 @@ impl Parse for MemberRepeatAttr { let types: Punctuated = Punctuated::parse_terminated(input)?; if types.is_empty() { - return Ok(MemberRepeatAttr { - permeate, - repeat_for: [true, true, true, true, true], - }); + return Ok(MemberRepeatAttr { permeate, repeat_for: [true, true, true, true, true] }); } let mut repeat_for: MemberRepeatFor = [false, false, false, false, false]; @@ -327,16 +268,13 @@ impl Parse for MemberRepeatAttr { for ty in types { let str = ty.to_token_stream().to_string(); - match MEMBER_REPEAT_TYPES.iter().position(|x|*x == str.as_str()) { + match MEMBER_REPEAT_TYPES.iter().position(|x| *x == str.as_str()) { Some(idx) => repeat_for[idx] = true, - None => return Err(Error::new(ty.span(), format!("#[repeat] of instruction type '{}' is not supported. Supported types are: {}", str, MEMBER_REPEAT_TYPES.join(", ")))) + None => return Err(Error::new(ty.span(), format!("#[repeat] of instruction type '{}' is not supported. Supported types are: {}", str, MEMBER_REPEAT_TYPES.join(", ")))), }; } - Ok(MemberRepeatAttr { - permeate, - repeat_for, - }) + Ok(MemberRepeatAttr { permeate, repeat_for }) } } @@ -358,183 +296,70 @@ pub(crate) struct MemberAttrs { } impl<'a> MemberAttrs { - pub(crate) fn iter_for_kind( - &'a self, - kind: &'a Kind, - fallible: bool, - ) -> impl Iterator { - self.attrs - .iter() - .filter(move |x| x.fallible == fallible && x.applicable_to[kind]) + pub(crate) fn iter_for_kind(&'a self, kind: &'a Kind, fallible: bool) -> impl Iterator { + self.attrs.iter().filter(move |x| x.fallible == fallible && x.applicable_to[kind]) } - pub(crate) fn iter_for_kind_core( - &'a self, - kind: &'a Kind, - fallible: bool, - ) -> impl Iterator { + pub(crate) fn iter_for_kind_core(&'a self, kind: &'a Kind, fallible: bool) -> impl Iterator { self.iter_for_kind(kind, fallible).map(|x| &x.attr) } - pub(crate) fn applicable_attr( - &'a self, - kind: &'a Kind, - fallible: bool, - container_ty: &TypePath, - ) -> Option { - self.ghost(container_ty, kind) - .map(ApplicableAttr::Ghost) - .or_else(|| { - self.field_attr_core(kind, fallible, container_ty) - .or_else(|| { - if fallible { - self.field_attr_core(kind, false, container_ty) - } else { - None - } - }) - .or_else(|| { - if kind == &Kind::OwnedIntoExisting { - self.field_attr_core(&Kind::OwnedInto, fallible, container_ty) - } else { - None - } - }) - .or_else(|| { - if kind == &Kind::OwnedIntoExisting && fallible { - self.field_attr_core(&Kind::OwnedInto, false, container_ty) - } else { - None - } - }) - .or_else(|| { - if kind == &Kind::RefIntoExisting { - self.field_attr_core(&Kind::RefInto, fallible, container_ty) - } else { - None - } - }) - .or_else(|| { - if kind == &Kind::RefIntoExisting && fallible { - self.field_attr_core(&Kind::RefInto, false, container_ty) - } else { - None - } - }) - .map(ApplicableAttr::Field) - }) - } - - pub(crate) fn applicable_field_attr( - &'a self, - kind: &'a Kind, - fallible: bool, - container_ty: &TypePath, - ) -> Option<&'a MemberAttr> { + pub(crate) fn applicable_attr(&'a self, kind: &'a Kind, fallible: bool, container_ty: &TypePath) -> Option { + self.ghost(container_ty, kind).map(ApplicableAttr::Ghost).or_else(|| { + self.field_attr_core(kind, fallible, container_ty) + .or_else(|| if fallible { self.field_attr_core(kind, false, container_ty) } else { None }) + .or_else(|| if kind == &Kind::OwnedIntoExisting { self.field_attr_core(&Kind::OwnedInto, fallible, container_ty) } else { None }) + .or_else(|| if kind == &Kind::OwnedIntoExisting && fallible { self.field_attr_core(&Kind::OwnedInto, false, container_ty) } else { None }) + .or_else(|| if kind == &Kind::RefIntoExisting { self.field_attr_core(&Kind::RefInto, fallible, container_ty) } else { None }) + .or_else(|| if kind == &Kind::RefIntoExisting && fallible { self.field_attr_core(&Kind::RefInto, false, container_ty) } else { None }) + .map(ApplicableAttr::Field) + }) + } + + pub(crate) fn applicable_field_attr(&'a self, kind: &'a Kind, fallible: bool, container_ty: &TypePath) -> Option<&'a MemberAttr> { self.field_attr(kind, fallible, container_ty) - .or_else(|| { - if kind == &Kind::OwnedIntoExisting { - self.field_attr(&Kind::OwnedInto, fallible, container_ty) - } else { - None - } - }) - .or_else(|| { - if kind == &Kind::RefIntoExisting { - self.field_attr(&Kind::RefInto, fallible, container_ty) - } else { - None - } - }) + .or_else(|| if kind == &Kind::OwnedIntoExisting { self.field_attr(&Kind::OwnedInto, fallible, container_ty) } else { None }) + .or_else(|| if kind == &Kind::RefIntoExisting { self.field_attr(&Kind::RefInto, fallible, container_ty) } else { None }) } pub(crate) fn child(&'a self, container_ty: &TypePath) -> Option<&ChildAttr> { - self.child_attrs - .iter() - .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| self.child_attrs.iter().find(|x| x.container_ty.is_none())) + self.child_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.child_attrs.iter().find(|x| x.container_ty.is_none())) } - pub(crate) fn ghost( - &'a self, - container_ty: &TypePath, - kind: &'a Kind, - ) -> Option<&FieldGhostAttrCore> { + pub(crate) fn ghost(&'a self, container_ty: &TypePath, kind: &'a Kind) -> Option<&FieldGhostAttrCore> { self.ghost_attrs .iter() - .find(|x| { - x.applicable_to[kind] - && x.attr.container_ty.is_some() - && x.attr.container_ty.as_ref().unwrap() == container_ty - }) - .or_else(|| { - self.ghost_attrs - .iter() - .find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none()) - }) + .find(|x| x.applicable_to[kind] && x.attr.container_ty.is_some() && x.attr.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.ghost_attrs.iter().find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none())) .map(|x| &x.attr) } pub(crate) fn lit(&'a self, container_ty: &TypePath) -> Option<&LitAttr> { - self.lit_attrs - .iter() - .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| self.lit_attrs.iter().find(|x| x.container_ty.is_none())) + self.lit_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.lit_attrs.iter().find(|x| x.container_ty.is_none())) } pub(crate) fn pat(&'a self, container_ty: &TypePath) -> Option<&PatAttr> { - self.pat_attrs - .iter() - .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| self.pat_attrs.iter().find(|x| x.container_ty.is_none())) + self.pat_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.pat_attrs.iter().find(|x| x.container_ty.is_none())) } pub(crate) fn type_hint(&'a self, container_ty: &TypePath) -> Option<&VariantTypeHintAttr> { - self.type_hint_attrs - .iter() - .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| { - self.type_hint_attrs - .iter() - .find(|x| x.container_ty.is_none()) - }) + self.type_hint_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.type_hint_attrs.iter().find(|x| x.container_ty.is_none())) } pub(crate) fn has_parent_attr(&'a self, container_ty: &TypePath) -> bool { - self.parent_attrs - .iter() - .any(|x| x.container_ty.is_none() || x.container_ty.as_ref().unwrap() == container_ty) + self.parent_attrs.iter().any(|x| x.container_ty.is_none() || x.container_ty.as_ref().unwrap() == container_ty) } - pub(crate) fn field_attr( - &'a self, - kind: &'a Kind, - fallible: bool, - container_ty: &TypePath, - ) -> Option<&MemberAttr> { + pub(crate) fn field_attr(&'a self, kind: &'a Kind, fallible: bool, container_ty: &TypePath) -> Option<&MemberAttr> { self.iter_for_kind(kind, fallible) - .find(|x| { - x.attr.container_ty.is_some() - && x.attr.container_ty.as_ref().unwrap() == container_ty - }) - .or_else(|| { - self.iter_for_kind(kind, fallible) - .find(|x| x.attr.container_ty.is_none()) - }) - } - - pub(crate) fn field_attr_core( - &'a self, - kind: &'a Kind, - fallible: bool, - container_ty: &TypePath, - ) -> Option<&MemberAttrCore> { + .find(|x| x.attr.container_ty.is_some() && x.attr.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.iter_for_kind(kind, fallible).find(|x| x.attr.container_ty.is_none())) + } + + pub(crate) fn field_attr_core(&'a self, kind: &'a Kind, fallible: bool, container_ty: &TypePath) -> Option<&MemberAttrCore> { self.iter_for_kind_core(kind, fallible) .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| { - self.iter_for_kind_core(kind, fallible) - .find(|x| x.container_ty.is_none()) - }) + .or_else(|| self.iter_for_kind_core(kind, fallible).find(|x| x.container_ty.is_none())) } pub(crate) fn merge(&'a mut self, other: Self) { @@ -613,9 +438,9 @@ impl Parse for TraitRepeatForWrap { for ty in types { let str = ty.to_token_stream().to_string(); - match TRAIT_REPEAT_TYPES.iter().position(|x|*x == str.as_str()) { + match TRAIT_REPEAT_TYPES.iter().position(|x| *x == str.as_str()) { Some(idx) => repeat[idx] = true, - None => return Err(Error::new(ty.span(), format!("#[repeat] of instruction type '{}' is not supported. Supported types are: {}", str, TRAIT_REPEAT_TYPES.join(", ")))) + None => return Err(Error::new(ty.span(), format!("#[repeat] of instruction type '{}' is not supported. Supported types are: {}", str, TRAIT_REPEAT_TYPES.join(", ")))), }; } @@ -656,19 +481,13 @@ impl TraitAttrCore { if let Some(attr_to_repeat) = other.repeat { if attr_to_repeat[&TraitAttrType::Vars] { if self.init_data.is_some() { - Err(syn::Error::new( - self.ty.span, - "Vars will be overriden. Did you forget to use 'skip_repeat'?", - ))? + Err(syn::Error::new(self.ty.span, "Vars will be overriden. Did you forget to use 'skip_repeat'?"))? } self.init_data = other.init_data } if attr_to_repeat[&TraitAttrType::Update] { if self.update.is_some() { - Err(syn::Error::new( - self.update.span(), - "Update statement will be overriden. Did you forget to use 'skip_repeat'?", - ))? + Err(syn::Error::new(self.update.span(), "Update statement will be overriden. Did you forget to use 'skip_repeat'?"))? } self.update = other.update } @@ -699,11 +518,7 @@ impl Parse for TraitAttrCore { } else { input.parse::()?.into() }; - let type_hint = if ty.nameless_tuple { - TypeHint::Tuple - } else { - try_parse_type_hint(input)? - }; + let type_hint = if ty.nameless_tuple { TypeHint::Tuple } else { try_parse_type_hint(input)? }; let err_ty = if input.peek(Token![,]) { input.parse::()?; Some(input.parse::()?.into()) @@ -739,36 +554,20 @@ impl Parse for TraitAttrCore { } } -fn parse_trait_instruction_param_inner_1( - input: &syn::parse::ParseBuffer, - condition: bool, - setter: impl FnOnce(), - span: impl Fn(T) -> Span, - name: &str, -) -> Result { +fn parse_trait_instruction_param_inner_1(input: &syn::parse::ParseBuffer, condition: bool, setter: impl FnOnce(), span: impl Fn(T) -> Span, name: &str) -> Result { let a = input.parse::()?; if input.peek(Token![,]) { input.parse::()?; } if condition { - Err(syn::Error::new( - span(a), - format!("Instruction parameter '{}' was already set.", name), - ))? + Err(syn::Error::new(span(a), format!("Instruction parameter '{}' was already set.", name)))? } else { setter(); return Ok(true); } } -fn parse_trait_instruction_param_inner_2( - input: &syn::parse::ParseBuffer, - parser: impl Fn(ParseBuffer) -> Result, - condition: bool, - setter: impl FnOnce(U), - span: impl Fn(T) -> Span, - name: &str, -) -> Result { +fn parse_trait_instruction_param_inner_2(input: &syn::parse::ParseBuffer, parser: impl Fn(ParseBuffer) -> Result, condition: bool, setter: impl FnOnce(U), span: impl Fn(T) -> Span, name: &str) -> Result { let a = input.parse::()?; let content; parenthesized!(content in input); @@ -777,54 +576,22 @@ fn parse_trait_instruction_param_inner_2( input.parse::()?; } if condition { - Err(syn::Error::new( - span(a), - format!("Instruction parameter '{}' was already set.", name), - ))? + Err(syn::Error::new(span(a), format!("Instruction parameter '{}' was already set.", name)))? } else { setter(content); return Ok(true); } } -fn parse_trait_instruction_param( - input: &syn::parse::ParseBuffer, - attr: &mut TraitAttrCore, -) -> Result { +fn parse_trait_instruction_param(input: &syn::parse::ParseBuffer, attr: &mut TraitAttrCore) -> Result { if input.peek(kw::stop_repeat) { - return parse_trait_instruction_param_inner_1::( - input, - attr.stop_repeat, - || attr.stop_repeat = true, - |a| a.span, - "stop_repeat", - ); + return parse_trait_instruction_param_inner_1::(input, attr.stop_repeat, || attr.stop_repeat = true, |a| a.span, "stop_repeat"); } else if input.peek(kw::skip_repeat) { - return parse_trait_instruction_param_inner_1::( - input, - attr.skip_repeat, - || attr.skip_repeat = true, - |a| a.span, - "skip_repeat", - ); + return parse_trait_instruction_param_inner_1::(input, attr.skip_repeat, || attr.skip_repeat = true, |a| a.span, "skip_repeat"); } else if input.peek(kw::repeat) { - return parse_trait_instruction_param_inner_2::( - input, - |c| c.parse(), - attr.repeat.is_some(), - |x| attr.repeat = Some(x.0), - |a| a.span, - "repeat", - ); + return parse_trait_instruction_param_inner_2::(input, |c| c.parse(), attr.repeat.is_some(), |x| attr.repeat = Some(x.0), |a| a.span, "repeat"); } else if input.peek(kw::vars) { - return parse_trait_instruction_param_inner_2::>( - input, - |c| Punctuated::parse_separated_nonempty(&c), - attr.init_data.is_some(), - |x| attr.init_data = Some(x), - |a| a.span, - "vars", - ); + return parse_trait_instruction_param_inner_2::>(input, |c| Punctuated::parse_separated_nonempty(&c), attr.init_data.is_some(), |x| attr.init_data = Some(x), |a| a.span, "vars"); } else if input.peek(Token![..]) { input.parse::()?; attr.update = try_parse_action(input, true)?; @@ -838,32 +605,11 @@ fn parse_trait_instruction_param( attr.default_case = try_parse_action(input, true)?; return Ok(false); } else if input.peek(kw::attribute) { - return parse_trait_instruction_param_inner_2::( - input, - |c| c.parse(), - attr.attribute.is_some(), - |x| attr.attribute = Some(quote!(#[ #x ])), - |a| a.span, - "attribute", - ); + return parse_trait_instruction_param_inner_2::(input, |c| c.parse(), attr.attribute.is_some(), |x| attr.attribute = Some(quote!(#[ #x ])), |a| a.span, "attribute"); } else if input.peek(kw::impl_attribute) { - return parse_trait_instruction_param_inner_2::( - input, - |c| c.parse(), - attr.impl_attribute.is_some(), - |x| attr.impl_attribute = Some(quote!(#[ #x ])), - |a| a.span, - "impl_attribute", - ); + return parse_trait_instruction_param_inner_2::(input, |c| c.parse(), attr.impl_attribute.is_some(), |x| attr.impl_attribute = Some(quote!(#[ #x ])), |a| a.span, "impl_attribute"); } else if input.peek(kw::inner_attribute) { - return parse_trait_instruction_param_inner_2::( - input, - |c| c.parse(), - attr.inner_attribute.is_some(), - |x| attr.inner_attribute = Some(quote!(#![ #x ])), - |a| a.span, - "inner_attribute", - ); + return parse_trait_instruction_param_inner_2::(input, |c| c.parse(), attr.inner_attribute.is_some(), |x| attr.inner_attribute = Some(quote!(#![ #x ])), |a| a.span, "inner_attribute"); } Ok(false) @@ -931,10 +677,7 @@ impl GhostIdent { impl GhostData { pub(crate) fn get_child_path_str(&self, depth: Option) -> &str { - self.child_path - .as_ref() - .map(|x| x.get_child_path_str(depth)) - .unwrap_or("") + self.child_path.as_ref().map(|x| x.get_child_path_str(depth)).unwrap_or("") } } @@ -958,10 +701,7 @@ impl Parse for GhostData { let child_path = if !peek_ghost_field_name(input) { let child_path = Some(Punctuated::parse_separated_nonempty(input)?).map(|child_path| { let child_path_str = build_child_path_str(&child_path); - ChildPath { - child_path, - child_path_str, - } + ChildPath { child_path, child_path_str } }); input.parse::()?; child_path @@ -986,11 +726,7 @@ impl Parse for GhostData { input.parse::()?; - Ok(GhostData { - child_path, - ghost_ident, - action: try_parse_braced_action(input)?, - }) + Ok(GhostData { child_path, ghost_ident, action: try_parse_braced_action(input)? }) } } @@ -1079,9 +815,7 @@ pub(crate) struct ParentAttr { impl Parse for ParentAttr { fn parse(input: ParseStream) -> Result { - Ok(ParentAttr { - container_ty: try_parse_container_ident(input, true), - }) + Ok(ParentAttr { container_ty: try_parse_container_ident(input, true) }) } } @@ -1126,16 +860,9 @@ impl ChildAttr { impl Parse for ChildAttr { fn parse(input: ParseStream) -> Result { let container_ty = try_parse_container_ident(input, false); - let child_path: Punctuated = - Punctuated::parse_separated_nonempty(input)?; + let child_path: Punctuated = Punctuated::parse_separated_nonempty(input)?; let child_path_str = build_child_path_str(&child_path); - Ok(ChildAttr { - container_ty, - child_path: ChildPath { - child_path, - child_path_str, - }, - }) + Ok(ChildAttr { container_ty, child_path: ChildPath { child_path, child_path_str } }) } } @@ -1158,11 +885,7 @@ impl Parse for AsAttr { (None, input.parse()?) }; - Ok(AsAttr { - container_ty, - member: ident, - tokens, - }) + Ok(AsAttr { container_ty, member: ident, tokens }) } } @@ -1175,10 +898,7 @@ pub(crate) struct LitAttr { impl Parse for LitAttr { fn parse(input: ParseStream) -> Result { let container_ty = try_parse_container_ident(input, false); - Ok(LitAttr { - container_ty, - tokens: input.parse()?, - }) + Ok(LitAttr { container_ty, tokens: input.parse()? }) } } @@ -1191,10 +911,7 @@ pub(crate) struct PatAttr { impl Parse for PatAttr { fn parse(input: ParseStream) -> Result { let container_ty = try_parse_container_ident(input, false); - Ok(PatAttr { - container_ty, - tokens: input.parse()?, - }) + Ok(PatAttr { container_ty, tokens: input.parse()? }) } } @@ -1208,10 +925,7 @@ impl Parse for VariantTypeHintAttr { fn parse(input: ParseStream) -> Result { let container_ty = try_parse_container_ident(input, false); let type_hint = try_parse_type_hint(input)?; - Ok(VariantTypeHintAttr { - container_ty, - type_hint, - }) + Ok(VariantTypeHintAttr { container_ty, type_hint }) } } @@ -1224,17 +938,13 @@ pub(crate) fn get_data_type_attrs(input: &[Attribute]) -> Result<(DataTypeAttrs, continue; } else if x.path.is_ident("o2o") { x.parse_args_with(|input: ParseStream| { - let new_instrs: Punctuated = - Punctuated::parse_terminated_with(input, |input| { - let instr = input.parse::()?; - let p: OptionalParenthesizedTokenStream = input.parse()?; - parse_data_type_instruction(&instr, p.content(), true, true) - })?; - - if new_instrs - .iter() - .any(|x| matches!(x, DataTypeInstruction::AllowUnknown)) - { + let new_instrs: Punctuated = Punctuated::parse_terminated_with(input, |input| { + let instr = input.parse::()?; + let p: OptionalParenthesizedTokenStream = input.parse()?; + parse_data_type_instruction(&instr, p.content(), true, true) + })?; + + if new_instrs.iter().any(|x| matches!(x, DataTypeInstruction::AllowUnknown)) { bark = false; } @@ -1243,12 +953,7 @@ pub(crate) fn get_data_type_attrs(input: &[Attribute]) -> Result<(DataTypeAttrs, })?; } else if let Some(instr) = x.path.get_ident() { let p: OptionalParenthesizedTokenStream = syn::parse2(x.tokens.clone())?; - instrs.push(parse_data_type_instruction( - instr, - p.content(), - false, - bark, - )?); + instrs.push(parse_data_type_instruction(instr, p.content(), false, bark)?); } } @@ -1269,10 +974,7 @@ pub(crate) fn get_data_type_attrs(input: &[Attribute]) -> Result<(DataTypeAttrs, if trait_attr.core.repeat.is_some() { if trait_attr_to_repeat.is_some() && !trait_attr.core.stop_repeat { - Err(syn::Error::new( - trait_attr.core.ty.span, - "Previous repeat() instruction must be terminated with 'stop_repeat'", - ))? + Err(syn::Error::new(trait_attr.core.ty.span, "Previous repeat() instruction must be terminated with 'stop_repeat'"))? } trait_attrs_to_repeat.insert(k, trait_attr.clone()); @@ -1299,12 +1001,11 @@ pub(crate) fn get_member_attrs(input: SynDataTypeMember, bark: bool) -> Result = - Punctuated::parse_terminated_with(input, |input| { - let instr = input.parse::()?; - let p: OptionalParenthesizedTokenStream = input.parse()?; - parse_member_instruction(&instr, p.content(), true, true) - })?; + let new_instrs: Punctuated = Punctuated::parse_terminated_with(input, |input| { + let instr = input.parse::()?; + let p: OptionalParenthesizedTokenStream = input.parse()?; + parse_member_instruction(&instr, p.content(), true, true) + })?; instrs.extend(new_instrs.into_iter()); Ok(()) })?; @@ -1342,27 +1043,11 @@ pub(crate) fn get_member_attrs(input: SynDataTypeMember, bark: bool) -> Result Result { +fn parse_data_type_instruction(instr: &Ident, input: TokenStream, own_instr: bool, bark: bool) -> Result { let instr_str = &instr.to_token_stream().to_string(); match instr_str.as_ref() { "allow_unknown" if own_instr => Ok(DataTypeInstruction::AllowUnknown), - "owned_into" - | "ref_into" - | "into" - | "from_owned" - | "from_ref" - | "from" - | "map_owned" - | "map_ref" - | "map" - | "owned_into_existing" - | "ref_into_existing" - | "into_existing" => Ok(DataTypeInstruction::Map(TraitAttr { + "owned_into" | "ref_into" | "into" | "from_owned" | "from_ref" | "from" | "map_owned" | "map_ref" | "map" | "owned_into_existing" | "ref_into_existing" | "into_existing" => Ok(DataTypeInstruction::Map(TraitAttr { core: syn::parse2(input)?, fallible: false, applicable_to: [ @@ -1374,18 +1059,7 @@ fn parse_data_type_instruction( appl_ref_into_existing(instr_str), ], })), - "owned_try_into" - | "ref_try_into" - | "try_into" - | "try_from_owned" - | "try_from_ref" - | "try_from" - | "try_map_owned" - | "try_map_ref" - | "try_map" - | "owned_try_into_existing" - | "ref_try_into_existing" - | "try_into_existing" => Ok(DataTypeInstruction::Map(TraitAttr { + "owned_try_into" | "ref_try_into" | "try_into" | "try_from_owned" | "try_from_ref" | "try_from" | "try_map_owned" | "try_map_ref" | "try_map" | "owned_try_into_existing" | "ref_try_into_existing" | "try_into_existing" => Ok(DataTypeInstruction::Map(TraitAttr { core: syn::parse2(input)?, fallible: true, applicable_to: [ @@ -1410,12 +1084,7 @@ fn parse_data_type_instruction( })), "children" => Ok(DataTypeInstruction::Children(syn::parse2(input)?)), "where_clause" => Ok(DataTypeInstruction::Where(syn::parse2(input)?)), - "ghost" if bark => Ok(DataTypeInstruction::Misnamed { - instr: "ghost", - span: instr.span(), - guess_name: "ghosts", - own: own_instr, - }), + "ghost" if bark => Ok(DataTypeInstruction::Misnamed { instr: "ghost", span: instr.span(), guess_name: "ghosts", own: own_instr }), "ghost_ref" if bark => Ok(DataTypeInstruction::Misnamed { instr: "ghost_ref", span: instr.span(), @@ -1428,80 +1097,24 @@ fn parse_data_type_instruction( guess_name: "ghosts_owned", own: own_instr, }), - "child" if bark => Ok(DataTypeInstruction::Misnamed { - instr: "child", - span: instr.span(), - guess_name: "children", - own: own_instr, - }), - "parent" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "parent", - span: instr.span(), - own: own_instr, - }), - "as_type" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "as_type", - span: instr.span(), - own: own_instr, - }), - "literal" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "literal", - span: instr.span(), - own: own_instr, - }), - "pattern" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "pattern", - span: instr.span(), - own: own_instr, - }), - "repeat" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "repeat", - span: instr.span(), - own: own_instr, - }), - "skip_repeat" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "skip_repeat", - span: instr.span(), - own: own_instr, - }), - "stop_repeat" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "stop_repeat", - span: instr.span(), - own: own_instr, - }), - "type_hint" if bark => Ok(DataTypeInstruction::Misplaced { - instr: "type_hint", - span: instr.span(), - own: own_instr, - }), - _ if own_instr => Ok(DataTypeInstruction::UnrecognizedWithError { - instr: instr_str.clone(), - span: instr.span(), - }), + "child" if bark => Ok(DataTypeInstruction::Misnamed { instr: "child", span: instr.span(), guess_name: "children", own: own_instr }), + "parent" if bark => Ok(DataTypeInstruction::Misplaced { instr: "parent", span: instr.span(), own: own_instr }), + "as_type" if bark => Ok(DataTypeInstruction::Misplaced { instr: "as_type", span: instr.span(), own: own_instr }), + "literal" if bark => Ok(DataTypeInstruction::Misplaced { instr: "literal", span: instr.span(), own: own_instr }), + "pattern" if bark => Ok(DataTypeInstruction::Misplaced { instr: "pattern", span: instr.span(), own: own_instr }), + "repeat" if bark => Ok(DataTypeInstruction::Misplaced { instr: "repeat", span: instr.span(), own: own_instr }), + "skip_repeat" if bark => Ok(DataTypeInstruction::Misplaced { instr: "skip_repeat", span: instr.span(), own: own_instr }), + "stop_repeat" if bark => Ok(DataTypeInstruction::Misplaced { instr: "stop_repeat", span: instr.span(), own: own_instr }), + "type_hint" if bark => Ok(DataTypeInstruction::Misplaced { instr: "type_hint", span: instr.span(), own: own_instr }), + _ if own_instr => Ok(DataTypeInstruction::UnrecognizedWithError { instr: instr_str.clone(), span: instr.span() }), _ => Ok(DataTypeInstruction::Unrecognized), } } -fn parse_member_instruction( - instr: &Ident, - input: TokenStream, - own_instr: bool, - bark: bool, -) -> Result { +fn parse_member_instruction(instr: &Ident, input: TokenStream, own_instr: bool, bark: bool) -> Result { let instr_str = &instr.to_string(); match instr_str.as_ref() { - "owned_into" - | "ref_into" - | "into" - | "from_owned" - | "from_ref" - | "from" - | "map_owned" - | "map_ref" - | "map" - | "owned_into_existing" - | "ref_into_existing" - | "into_existing" => Ok(MemberInstruction::Map(MemberAttr { + "owned_into" | "ref_into" | "into" | "from_owned" | "from_ref" | "from" | "map_owned" | "map_ref" | "map" | "owned_into_existing" | "ref_into_existing" | "into_existing" => Ok(MemberInstruction::Map(MemberAttr { attr: syn::parse2(input)?, fallible: false, original_instr: instr_str.clone(), @@ -1514,22 +1127,19 @@ fn parse_member_instruction( appl_ref_into_existing(instr_str), ], })), - "owned_try_into" | "ref_try_into" | "try_into" | "try_from_owned" | "try_from_ref" - | "try_from" | "try_map_owned" | "try_map_ref" | "try_map" => { - Ok(MemberInstruction::Map(MemberAttr { - attr: syn::parse2(input)?, - fallible: true, - original_instr: instr_str.clone(), - applicable_to: [ - appl_owned_into(instr_str), - appl_ref_into(instr_str), - appl_from_owned(instr_str), - appl_from_ref(instr_str), - appl_owned_into_existing(instr_str), - appl_ref_into_existing(instr_str), - ], - })) - } + "owned_try_into" | "ref_try_into" | "try_into" | "try_from_owned" | "try_from_ref" | "try_from" | "try_map_owned" | "try_map_ref" | "try_map" => Ok(MemberInstruction::Map(MemberAttr { + attr: syn::parse2(input)?, + fallible: true, + original_instr: instr_str.clone(), + applicable_to: [ + appl_owned_into(instr_str), + appl_ref_into(instr_str), + appl_from_owned(instr_str), + appl_from_ref(instr_str), + appl_owned_into_existing(instr_str), + appl_ref_into_existing(instr_str), + ], + })), "ghost" | "ghost_ref" | "ghost_owned" => Ok(MemberInstruction::Ghost(GhostAttr { attr: syn::parse2(input)?, applicable_to: [ @@ -1561,26 +1171,10 @@ fn parse_member_instruction( "skip_repeat" => Ok(MemberInstruction::SkipRepeat), "stop_repeat" => Ok(MemberInstruction::StopRepeat), "type_hint" => Ok(MemberInstruction::VariantTypeHint(syn::parse2(input)?)), - "children" if bark => Ok(MemberInstruction::Misnamed { - instr: "children", - span: instr.span(), - guess_name: "child", - own: own_instr, - }), - "where_clause" if bark => Ok(MemberInstruction::Misplaced { - instr: "where_clause", - span: instr.span(), - own: own_instr, - }), - "allow_unknown" if bark => Ok(MemberInstruction::Misplaced { - instr: "allow_unknown", - span: instr.span(), - own: own_instr, - }), - _ if own_instr => Ok(MemberInstruction::UnrecognizedWithError { - instr: instr_str.clone(), - span: instr.span(), - }), + "children" if bark => Ok(MemberInstruction::Misnamed { instr: "children", span: instr.span(), guess_name: "child", own: own_instr }), + "where_clause" if bark => Ok(MemberInstruction::Misplaced { instr: "where_clause", span: instr.span(), own: own_instr }), + "allow_unknown" if bark => Ok(MemberInstruction::Misplaced { instr: "allow_unknown", span: instr.span(), own: own_instr }), + _ if own_instr => Ok(MemberInstruction::UnrecognizedWithError { instr: instr_str.clone(), span: instr.span() }), _ => Ok(MemberInstruction::Unrecognized), } } @@ -1668,12 +1262,7 @@ fn try_parse_children(input: ParseStream) -> Result bool { - matches!( - instr, - "owned_into" - | "into" - | "map_owned" - | "map" - | "owned_try_into" - | "try_into" - | "try_map_owned" - | "try_map" - ) + matches!(instr, "owned_into" | "into" | "map_owned" | "map" | "owned_try_into" | "try_into" | "try_map_owned" | "try_map") } fn appl_ref_into(instr: &str) -> bool { - matches!( - instr, - "ref_into" - | "into" - | "map_ref" - | "map" - | "ref_try_into" - | "try_into" - | "try_map_ref" - | "try_map" - ) + matches!(instr, "ref_into" | "into" | "map_ref" | "map" | "ref_try_into" | "try_into" | "try_map_ref" | "try_map") } fn appl_from_owned(instr: &str) -> bool { - matches!( - instr, - "from_owned" - | "from" - | "map_owned" - | "map" - | "try_from_owned" - | "try_from" - | "try_map_owned" - | "try_map" - ) + matches!(instr, "from_owned" | "from" | "map_owned" | "map" | "try_from_owned" | "try_from" | "try_map_owned" | "try_map") } fn appl_from_ref(instr: &str) -> bool { - matches!( - instr, - "from_ref" - | "from" - | "map_ref" - | "map" - | "try_from_ref" - | "try_from" - | "try_map_ref" - | "try_map" - ) + matches!(instr, "from_ref" | "from" | "map_ref" | "map" | "try_from_ref" | "try_from" | "try_map_ref" | "try_map") } fn appl_owned_into_existing(instr: &str) -> bool { - matches!( - instr, - "owned_into_existing" | "into_existing" | "owned_try_into_existing" | "try_into_existing" - ) + matches!(instr, "owned_into_existing" | "into_existing" | "owned_try_into_existing" | "try_into_existing") } fn appl_ref_into_existing(instr: &str) -> bool { - matches!( - instr, - "ref_into_existing" | "into_existing" | "ref_try_into_existing" | "try_into_existing" - ) + matches!(instr, "ref_into_existing" | "into_existing" | "ref_try_into_existing" | "try_into_existing") } fn appl_ghosts_owned(instr: &str) -> bool { @@ -1813,11 +1356,7 @@ fn build_child_path_str(child_path: &Punctuated) -> Vec Result { @@ -29,10 +29,7 @@ pub fn derive(node: &DeriveInput) -> Result { validate(&input)?; Ok(data_type_impl(input)) } - _ => Err(Error::new_spanned( - node, - "#[derive(o2o)] only supports structs and enums.", - )), + _ => Err(Error::new_spanned(node, "#[derive(o2o)] only supports structs and enums.")), } } @@ -88,273 +85,197 @@ fn data_type_impl(input: DataType) -> TokenStream { DataType::Enum(_) => ImplType::Enum, }; - let from_owned_impls = attrs - .iter_for_kind_core(&Kind::FromOwned, false) - .map(|struct_attr| { - let ctx = ImplContext { - struct_attr, - kind: Kind::FromOwned, - dst_ty: &ty, - src_ty: &struct_attr.ty.path, - has_post_init: false, - impl_type, - fallible: false, - }; + let from_owned_impls = attrs.iter_for_kind_core(&Kind::FromOwned, false).map(|struct_attr| { + let ctx = ImplContext { + struct_attr, + kind: Kind::FromOwned, + dst_ty: &ty, + src_ty: &struct_attr.ty.path, + has_post_init: false, + impl_type, + fallible: false, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - quote_from_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx)) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + quote_from_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx)) + }); - let try_from_owned_impls = - attrs - .iter_for_kind_core(&Kind::FromOwned, true) - .map(|struct_attr| { - let ctx = ImplContext { - struct_attr, - kind: Kind::FromOwned, - dst_ty: &ty, - src_ty: &struct_attr.ty.path, - has_post_init: false, - impl_type, - fallible: true, - }; + let try_from_owned_impls = attrs.iter_for_kind_core(&Kind::FromOwned, true).map(|struct_attr| { + let ctx = ImplContext { + struct_attr, + kind: Kind::FromOwned, + dst_ty: &ty, + src_ty: &struct_attr.ty.path, + has_post_init: false, + impl_type, + fallible: true, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - quote_try_from_trait(&input, &ctx, pre_init, main_code_block_ok(&input, &ctx)) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + quote_try_from_trait(&input, &ctx, pre_init, main_code_block_ok(&input, &ctx)) + }); - let from_ref_impls = attrs - .iter_for_kind_core(&Kind::FromRef, false) - .map(|struct_attr| { - let ctx = ImplContext { - struct_attr, - kind: Kind::FromRef, - dst_ty: &ty, - src_ty: &struct_attr.ty.path, - has_post_init: false, - impl_type, - fallible: false, - }; + let from_ref_impls = attrs.iter_for_kind_core(&Kind::FromRef, false).map(|struct_attr| { + let ctx = ImplContext { + struct_attr, + kind: Kind::FromRef, + dst_ty: &ty, + src_ty: &struct_attr.ty.path, + has_post_init: false, + impl_type, + fallible: false, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - quote_from_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx)) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + quote_from_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx)) + }); - let try_from_ref_impls = attrs - .iter_for_kind_core(&Kind::FromRef, true) - .map(|struct_attr| { - let ctx = ImplContext { - struct_attr, - kind: Kind::FromRef, - dst_ty: &ty, - src_ty: &struct_attr.ty.path, - has_post_init: false, - impl_type, - fallible: true, - }; + let try_from_ref_impls = attrs.iter_for_kind_core(&Kind::FromRef, true).map(|struct_attr| { + let ctx = ImplContext { + struct_attr, + kind: Kind::FromRef, + dst_ty: &ty, + src_ty: &struct_attr.ty.path, + has_post_init: false, + impl_type, + fallible: true, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - quote_try_from_trait(&input, &ctx, pre_init, main_code_block_ok(&input, &ctx)) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + quote_try_from_trait(&input, &ctx, pre_init, main_code_block_ok(&input, &ctx)) + }); - let owned_into_impls = attrs - .iter_for_kind_core(&Kind::OwnedInto, false) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::OwnedInto, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: false, - }; + let owned_into_impls = attrs.iter_for_kind_core(&Kind::OwnedInto, false).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::OwnedInto, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: false, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_into_trait( - &input, - &ctx, - pre_init, - main_code_block(&input, &ctx), - post_init, - ) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_into_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx), post_init) + }); - let owned_try_into_impls = - attrs - .iter_for_kind_core(&Kind::OwnedInto, true) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::OwnedInto, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: true, - }; + let owned_try_into_impls = attrs.iter_for_kind_core(&Kind::OwnedInto, true).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::OwnedInto, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: true, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_try_into_trait( - &input, - &ctx, - pre_init, - main_code_block_ok(&input, &ctx), - post_init, - ) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_try_into_trait(&input, &ctx, pre_init, main_code_block_ok(&input, &ctx), post_init) + }); - let ref_into_impls = attrs - .iter_for_kind_core(&Kind::RefInto, false) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::RefInto, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: false, - }; + let ref_into_impls = attrs.iter_for_kind_core(&Kind::RefInto, false).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::RefInto, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: false, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_into_trait( - &input, - &ctx, - pre_init, - main_code_block(&input, &ctx), - post_init, - ) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_into_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx), post_init) + }); - let ref_try_into_impls = attrs - .iter_for_kind_core(&Kind::RefInto, true) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::RefInto, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: true, - }; + let ref_try_into_impls = attrs.iter_for_kind_core(&Kind::RefInto, true).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::RefInto, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: true, + }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_try_into_trait( - &input, - &ctx, - pre_init, - main_code_block_ok(&input, &ctx), - post_init, - ) - }); + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_try_into_trait(&input, &ctx, pre_init, main_code_block_ok(&input, &ctx), post_init) + }); - let owned_into_existing_impls = attrs - .iter_for_kind_core(&Kind::OwnedIntoExisting, false) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::OwnedIntoExisting, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: false, - }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_into_existing_trait( - &input, - &ctx, - pre_init, - main_code_block(&input, &ctx), - post_init, - ) - }); + let owned_into_existing_impls = attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, false).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::OwnedIntoExisting, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: false, + }; + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_into_existing_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx), post_init) + }); - let owned_try_into_existing_impls = attrs - .iter_for_kind_core(&Kind::OwnedIntoExisting, true) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::OwnedIntoExisting, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: true, - }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_try_into_existing_trait( - &input, - &ctx, - pre_init, - main_code_block(&input, &ctx), - post_init, - ) - }); + let owned_try_into_existing_impls = attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, true).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::OwnedIntoExisting, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: true, + }; + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_try_into_existing_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx), post_init) + }); - let ref_into_existing_impls = - attrs - .iter_for_kind_core(&Kind::RefIntoExisting, false) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::RefIntoExisting, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: false, - }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_into_existing_trait( - &input, - &ctx, - pre_init, - main_code_block(&input, &ctx), - post_init, - ) - }); + let ref_into_existing_impls = attrs.iter_for_kind_core(&Kind::RefIntoExisting, false).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::RefIntoExisting, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: false, + }; + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_into_existing_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx), post_init) + }); - let ref_try_into_existing_impls = - attrs - .iter_for_kind_core(&Kind::RefIntoExisting, true) - .map(|struct_attr| { - let mut ctx = ImplContext { - struct_attr, - kind: Kind::RefIntoExisting, - dst_ty: &struct_attr.ty.path, - src_ty: &ty, - has_post_init: false, - impl_type, - fallible: true, - }; - let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); - let post_init = struct_post_init(&input, &ctx); - ctx.has_post_init = post_init.is_some(); - quote_try_into_existing_trait( - &input, - &ctx, - pre_init, - main_code_block(&input, &ctx), - post_init, - ) - }); + let ref_try_into_existing_impls = attrs.iter_for_kind_core(&Kind::RefIntoExisting, true).map(|struct_attr| { + let mut ctx = ImplContext { + struct_attr, + kind: Kind::RefIntoExisting, + dst_ty: &struct_attr.ty.path, + src_ty: &ty, + has_post_init: false, + impl_type, + fallible: true, + }; + let pre_init = struct_pre_init(&ctx, &struct_attr.init_data); + let post_init = struct_post_init(&input, &ctx); + ctx.has_post_init = post_init.is_some(); + quote_try_into_existing_trait(&input, &ctx, pre_init, main_code_block(&input, &ctx), post_init) + }); let result = quote! { #(#from_owned_impls)* @@ -448,9 +369,7 @@ fn enum_main_code_block(input: &Enum, ctx: &ImplContext) -> TokenStream { } fn struct_init_block<'a>(input: &'a Struct, ctx: &ImplContext) -> TokenStream { - if (!ctx.kind.is_from() && ctx.struct_attr.type_hint == TypeHint::Unit) - || (ctx.kind.is_from() && input.unit) - { + if (!ctx.kind.is_from() && ctx.struct_attr.type_hint == TypeHint::Unit) || (ctx.kind.is_from() && input.unit) { return TokenStream::new(); } @@ -474,41 +393,24 @@ fn struct_init_block<'a>(input: &'a Struct, ctx: &ImplContext) -> TokenStream { .fields .iter() .map(|x| { - let path = x - .attrs - .child(&ctx.struct_attr.ty) - .map(|x| x.get_child_path_str(None)) - .unwrap_or(""); + let path = x.attrs.child(&ctx.struct_attr.ty).map(|x| x.get_child_path_str(None)).unwrap_or(""); unique_paths.insert(path); make_tuple(path, FieldData::Field(x)) }) .collect::>(), ); - fields.extend( - input - .attrs - .ghosts_attrs - .iter() - .flat_map(|x| &x.attr.ghost_data) - .filter(|x| unique_paths.insert(x.get_child_path_str(None))) - .map(|x| { - let path: &str = x.get_child_path_str(None); - make_tuple(path, FieldData::GhostData(x)) - }), - ); + fields.extend(input.attrs.ghosts_attrs.iter().flat_map(|x| &x.attr.ghost_data).filter(|x| unique_paths.insert(x.get_child_path_str(None))).map(|x| { + let path: &str = x.get_child_path_str(None); + make_tuple(path, FieldData::GhostData(x)) + })); fields.sort_by(|(ga, a, _), (gb, b, _)| ga.cmp(gb).then(a.cmp(b))); struct_init_block_inner(&mut fields.iter().peekable(), input, ctx, None) } -fn struct_init_block_inner( - members: &mut Peekable>, - input: &Struct, - ctx: &ImplContext, - field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)>, -) -> TokenStream { +fn struct_init_block_inner(members: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)>) -> TokenStream { let type_hint = match field_ctx { Some(field_ctx) => match field_ctx.1 { Some(child_data) => child_data.type_hint, @@ -530,10 +432,7 @@ fn struct_init_block_inner( match field_data { FieldData::Field(f) => { let attrs = &f.attrs; - if !ctx.kind.is_from() - && (attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_some() - || attrs.has_parent_attr(&ctx.struct_attr.ty)) - { + if !ctx.kind.is_from() && (attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_some() || attrs.has_parent_attr(&ctx.struct_attr.ty)) { members.next(); continue; } @@ -548,15 +447,7 @@ fn struct_init_block_inner( } let fragment = match attrs.child(&ctx.struct_attr.ty) { - Some(child_attr) => render_child_fragment( - &child_attr.child_path, - members, - input, - ctx, - field_ctx, - type_hint, - || render_struct_line(f, ctx, type_hint, idx), - ), + Some(child_attr) => render_child_fragment(&child_attr.child_path, members, input, ctx, field_ctx, type_hint, || render_struct_line(f, ctx, type_hint, idx)), None => { members.next(); render_struct_line(f, ctx, type_hint, idx) @@ -567,15 +458,7 @@ fn struct_init_block_inner( } FieldData::GhostData(ghost_data) => { let child_path = &ghost_data.child_path.as_ref().unwrap(); - let fragment = render_child_fragment( - child_path, - members, - input, - ctx, - field_ctx, - type_hint, - TokenStream::new, - ); + let fragment = render_child_fragment(child_path, members, input, ctx, field_ctx, type_hint, TokenStream::new); fragments.push(fragment); idx += 1; } @@ -584,20 +467,15 @@ fn struct_init_block_inner( if !ctx.kind.is_from() { if let Some(ghost_attr) = input.attrs.ghosts_attr(&ctx.struct_attr.ty, &ctx.kind) { - ghost_attr - .ghost_data - .iter() - .for_each(|x| match (&x.child_path, field_ctx) { - (Some(_), Some(field_ctx)) => { - if x.get_child_path_str(None) - == field_ctx.0.get_child_path_str(Some(field_ctx.2)) - { - fragments.push(render_ghost_line(x, ctx)) - } + ghost_attr.ghost_data.iter().for_each(|x| match (&x.child_path, field_ctx) { + (Some(_), Some(field_ctx)) => { + if x.get_child_path_str(None) == field_ctx.0.get_child_path_str(Some(field_ctx.2)) { + fragments.push(render_ghost_line(x, ctx)) } - (None, None) => fragments.push(render_ghost_line(x, ctx)), - _ => (), - }); + } + (None, None) => fragments.push(render_ghost_line(x, ctx)), + _ => (), + }); } } @@ -624,31 +502,14 @@ fn struct_init_block_inner( fn enum_init_block(input: &Enum, ctx: &ImplContext) -> TokenStream { let mut fields: Vec = vec![]; - fields.extend( - input - .variants - .iter() - .map(VariantData::Variant) - .collect::>(), - ); + fields.extend(input.variants.iter().map(VariantData::Variant).collect::>()); - fields.extend( - input - .attrs - .ghosts_attrs - .iter() - .flat_map(|x| &x.attr.ghost_data) - .map(VariantData::GhostData), - ); + fields.extend(input.attrs.ghosts_attrs.iter().flat_map(|x| &x.attr.ghost_data).map(VariantData::GhostData)); enum_init_block_inner(&mut fields.iter().peekable(), input, ctx) } -fn enum_init_block_inner( - members: &mut Peekable>, - input: &Enum, - ctx: &ImplContext, -) -> TokenStream { +fn enum_init_block_inner(members: &mut Peekable>, input: &Enum, ctx: &ImplContext) -> TokenStream { let mut fragments: Vec = vec![]; while let Some(member_data) = members.peek() { @@ -682,19 +543,8 @@ fn enum_init_block_inner( } if let Some(default_case) = &ctx.struct_attr.default_case { - if ctx.kind.is_from() - && (input.variants.iter().any(|v| { - v.attrs.lit(&ctx.struct_attr.ty).is_some() - || v.attrs.pat(&ctx.struct_attr.ty).is_some() - }) || input - .attrs - .ghosts_attr(&ctx.struct_attr.ty, &ctx.kind) - .is_some()) - || !ctx.kind.is_from() - && input - .variants - .iter() - .any(|v| v.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_some()) + if ctx.kind.is_from() && (input.variants.iter().any(|v| v.attrs.lit(&ctx.struct_attr.ty).is_some() || v.attrs.pat(&ctx.struct_attr.ty).is_some()) || input.attrs.ghosts_attr(&ctx.struct_attr.ty, &ctx.kind).is_some()) + || !ctx.kind.is_from() && input.variants.iter().any(|v| v.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_some()) { let g = quote_action(default_case, None, ctx); fragments.push(quote!(_ #g)) @@ -706,23 +556,13 @@ fn enum_init_block_inner( fn variant_destruct_block(input: &Struct, ctx: &ImplContext) -> TokenStream { let (mut idents, type_hint) = match (input.named_fields, ctx.kind, ctx.struct_attr.type_hint) { - ( - true, - Kind::OwnedInto | Kind::RefInto | Kind::OwnedIntoExisting | Kind::RefIntoExisting, - _, - ) - | (true, _, TypeHint::Struct | TypeHint::Unspecified) - | (false, Kind::FromOwned | Kind::FromRef, TypeHint::Struct) => ( + (true, Kind::OwnedInto | Kind::RefInto | Kind::OwnedIntoExisting | Kind::RefIntoExisting, _) | (true, _, TypeHint::Struct | TypeHint::Unspecified) | (false, Kind::FromOwned | Kind::FromRef, TypeHint::Struct) => ( input .fields .iter() - .filter(|x| { - !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none() - }) + .filter(|x| !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none()) .map(|x| { - let attr = - x.attrs - .applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); + let attr = x.attrs.applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); if !ctx.kind.is_from() || attr.is_none() { let ident = &x.member; @@ -742,9 +582,7 @@ fn variant_destruct_block(input: &Struct, ctx: &ImplContext) -> TokenStream { input .fields .iter() - .filter(|x| { - !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none() - }) + .filter(|x| !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none()) .map(|x| { let ident = format_ident!("f{}", x.idx); quote!(#ident ,) @@ -755,23 +593,14 @@ fn variant_destruct_block(input: &Struct, ctx: &ImplContext) -> TokenStream { }; if ctx.kind.is_from() { - idents.extend( - input - .attrs - .ghosts_attrs - .iter() - .flat_map(|x| &x.attr.ghost_data) - .map(|x| { - let ghost_ident = x.ghost_ident.get_ident(); - let ident = match ghost_ident { - Member::Named(ident) => ident.to_token_stream(), - Member::Unnamed(index) => { - format_ident!("f{}", index.index).to_token_stream() - } - }; - quote!(#ident ,) - }), - ); + idents.extend(input.attrs.ghosts_attrs.iter().flat_map(|x| &x.attr.ghost_data).map(|x| { + let ghost_ident = x.ghost_ident.get_ident(); + let ident = match ghost_ident { + Named(ident) => ident.to_token_stream(), + Unnamed(index) => format_ident!("f{}", index.index).to_token_stream(), + }; + quote!(#ident ,) + })); } match type_hint { @@ -782,24 +611,12 @@ fn variant_destruct_block(input: &Struct, ctx: &ImplContext) -> TokenStream { } } -fn render_child_fragment TokenStream>( - child_path: &ChildPath, - fields: &mut Peekable>, - input: &Struct, - ctx: &ImplContext, - field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)>, - type_hint: TypeHint, - render_line: F, -) -> TokenStream { +fn render_child_fragment TokenStream>(child_path: &ChildPath, fields: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)>, type_hint: TypeHint, render_line: F) -> TokenStream { if let Some(field_ctx) = field_ctx { if field_ctx.2 < child_path.child_path_str.len() - 1 { match ctx.kind { - Kind::OwnedInto | Kind::RefInto => { - render_child(fields, input, ctx, (child_path, field_ctx.2 + 1), type_hint) - } - Kind::OwnedIntoExisting | Kind::RefIntoExisting => { - render_existing_child(fields, input, ctx, (child_path, field_ctx.2 + 1)) - } + Kind::OwnedInto | Kind::RefInto => render_child(fields, input, ctx, (child_path, field_ctx.2 + 1), type_hint), + Kind::OwnedIntoExisting | Kind::RefIntoExisting => render_existing_child(fields, input, ctx, (child_path, field_ctx.2 + 1)), Kind::FromOwned | Kind::FromRef => { fields.next(); render_line() @@ -811,12 +628,8 @@ fn render_child_fragment TokenStream>( } } else { match ctx.kind { - Kind::OwnedInto | Kind::RefInto => { - render_child(fields, input, ctx, (child_path, 0), type_hint) - } - Kind::OwnedIntoExisting | Kind::RefIntoExisting => { - render_existing_child(fields, input, ctx, (child_path, 0)) - } + Kind::OwnedInto | Kind::RefInto => render_child(fields, input, ctx, (child_path, 0), type_hint), + Kind::OwnedIntoExisting | Kind::RefIntoExisting => render_existing_child(fields, input, ctx, (child_path, 0)), Kind::FromOwned | Kind::FromRef => { fields.next(); render_line() @@ -825,10 +638,7 @@ fn render_child_fragment TokenStream>( } } -fn struct_pre_init( - ctx: &ImplContext, - init_data: &Option>, -) -> Option { +fn struct_pre_init(ctx: &ImplContext, init_data: &Option>) -> Option { if let Some(init_data) = init_data { let g = init_data.iter().map(|x| { let a = &x.ident; @@ -875,32 +685,14 @@ fn render_parent(f: &Field, ctx: &ImplContext) -> TokenStream { } } -fn render_child( - fields: &mut Peekable>, - input: &Struct, - ctx: &ImplContext, - field_ctx: (&ChildPath, usize), - hint: TypeHint, -) -> TokenStream { +fn render_child(fields: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: (&ChildPath, usize), hint: TypeHint) -> TokenStream { let child_path = field_ctx.0; let path = child_path.get_child_path_str(Some(field_ctx.1)); let child_name = child_path.child_path[field_ctx.1].to_token_stream(); - let mut children = input - .attrs - .children_attr(&ctx.struct_attr.ty) - .unwrap() - .children - .iter(); - let child_data = children - .find(|child_data| child_data.check_match(path)) - .unwrap(); + let mut children = input.attrs.children_attr(&ctx.struct_attr.ty).unwrap().children.iter(); + let child_data = children.find(|child_data| child_data.check_match(path)).unwrap(); let ty = &child_data.ty; - let init = struct_init_block_inner( - fields, - input, - ctx, - Some((field_ctx.0, Some(child_data), field_ctx.1)), - ); + let init = struct_init_block_inner(fields, input, ctx, Some((field_ctx.0, Some(child_data), field_ctx.1))); match (input.named_fields, hint) { (true, TypeHint::Struct | TypeHint::Unspecified) => quote!(#child_name: #ty #init,), (true, TypeHint::Tuple) => quote!(#ty #init,), @@ -910,32 +702,16 @@ fn render_child( } } -fn render_existing_child( - fields: &mut Peekable>, - input: &Struct, - ctx: &ImplContext, - field_ctx: (&ChildPath, usize), -) -> TokenStream { +fn render_existing_child(fields: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: (&ChildPath, usize)) -> TokenStream { let child_attr = field_ctx.0; let path = child_attr.get_child_path_str(Some(field_ctx.1)); let children_attr = input.attrs.children_attr(&ctx.struct_attr.ty); - let child_data = children_attr.and_then(|x| { - x.children - .iter() - .find(|child_data| child_data.check_match(path)) - }); - struct_init_block_inner( - fields, - input, - ctx, - Some((field_ctx.0, child_data, field_ctx.1)), - ) + let child_data = children_attr.and_then(|x| x.children.iter().find(|child_data| child_data.check_match(path))); + struct_init_block_inner(fields, input, ctx, Some((field_ctx.0, child_data, field_ctx.1))) } fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) -> TokenStream { - let attr = f - .attrs - .applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); + let attr = f.attrs.applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); let get_field_path = |x: &Member| match f.attrs.child(&ctx.struct_attr.ty) { Some(child_attr) => { let ch = child_attr.child_path.child_path.to_token_stream(); @@ -958,48 +734,25 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) }; match (&f.member, attr, &ctx.kind, hint) { - ( - syn::Member::Named(ident), - None, - Kind::OwnedInto | Kind::RefInto, - TypeHint::Struct | TypeHint::Unspecified, - ) => { + (Named(ident), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Struct | TypeHint::Unspecified) => { if ctx.has_post_init { quote!(obj.#ident = #obj #ident;) } else { quote!(#ident: #obj #ident,) } } - ( - syn::Member::Named(ident), - None, - Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Struct | TypeHint::Unspecified, - ) => { + (Named(ident), None, Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Struct | TypeHint::Unspecified) => { let field_path = get_field_path(&f.member); quote!(other.#field_path = #obj #ident;) } - (syn::Member::Named(ident), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple) => { + (Named(ident), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple) => { quote!(#obj #ident,) } - ( - syn::Member::Named(ident), - None, - Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Tuple, - ) => { - let index = Member::Unnamed(Index { - index: f.idx as u32, - span: Span::call_site(), - }); + (Named(ident), None, Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple) => { + let index = Unnamed(Index { index: f.idx as u32, span: Span::call_site() }); quote!(other.#index = #obj #ident;) } - ( - syn::Member::Named(ident), - None, - Kind::FromOwned | Kind::FromRef, - TypeHint::Struct | TypeHint::Unspecified | TypeHint::Unit, - ) => { + (Named(ident), None, Kind::FromOwned | Kind::FromRef, TypeHint::Struct | TypeHint::Unspecified | TypeHint::Unit) => { if f.attrs.has_parent_attr(&ctx.struct_attr.ty) { match (ctx.kind.is_ref(), ctx.fallible) { (true, true) => quote!(#ident: value.try_into()?,), @@ -1012,57 +765,25 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) quote!(#ident: #obj #field_path,) } } - (syn::Member::Named(ident), None, Kind::FromOwned | Kind::FromRef, TypeHint::Tuple) => { - let index = Member::Unnamed(Index { - index: f.idx as u32, - span: Span::call_site(), - }); - let field_path = if ctx.impl_type.is_variant() { - get_field_path(&Member::Named(format_ident!("f{}", index))) - } else { - get_field_path(&index) - }; + (Named(ident), None, Kind::FromOwned | Kind::FromRef, TypeHint::Tuple) => { + let index = Unnamed(Index { index: f.idx as u32, span: Span::call_site() }); + let field_path = if ctx.impl_type.is_variant() { get_field_path(&Named(format_ident!("f{}", index))) } else { get_field_path(&index) }; quote!(#ident: #obj #field_path,) } - ( - syn::Member::Unnamed(index), - None, - Kind::OwnedInto | Kind::RefInto, - TypeHint::Tuple | TypeHint::Unspecified, - ) => { + (Unnamed(index), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple | TypeHint::Unspecified) => { if ctx.has_post_init { - let index2 = Member::Unnamed(Index { - index: idx as u32, - span: Span::call_site(), - }); + let index2 = Unnamed(Index { index: idx as u32, span: Span::call_site() }); quote!(obj.#index2 = #obj #index;) } else { - let index = if ctx.impl_type.is_variant() { - format_ident!("f{}", index.index).to_token_stream() - } else { - index.to_token_stream() - }; + let index = if ctx.impl_type.is_variant() { format_ident!("f{}", index.index).to_token_stream() } else { index.to_token_stream() }; quote!(#obj #index,) } } - ( - syn::Member::Unnamed(index), - None, - Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Tuple | TypeHint::Unspecified, - ) => { - let index2 = Member::Unnamed(Index { - index: f.idx as u32, - span: Span::call_site(), - }); + (Unnamed(index), None, Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple | TypeHint::Unspecified) => { + let index2 = Unnamed(Index { index: f.idx as u32, span: Span::call_site() }); quote!(other.#index2 = #obj #index;) } - ( - syn::Member::Unnamed(index), - None, - Kind::FromOwned | Kind::FromRef, - TypeHint::Tuple | TypeHint::Unspecified | TypeHint::Unit, - ) => { + (Unnamed(index), None, Kind::FromOwned | Kind::FromRef, TypeHint::Tuple | TypeHint::Unspecified | TypeHint::Unit) => { if f.attrs.has_parent_attr(&ctx.struct_attr.ty) { match (ctx.kind.is_ref(), ctx.fallible) { (true, true) => quote!(value.try_into()?,), @@ -1071,15 +792,11 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) (false, false) => quote!((&value).into(),), } } else { - let field_path = if ctx.impl_type.is_variant() { - get_field_path(&Member::Named(format_ident!("f{}", index.index))) - } else { - get_field_path(&f.member) - }; + let field_path = if ctx.impl_type.is_variant() { get_field_path(&Named(format_ident!("f{}", index.index))) } else { get_field_path(&f.member) }; quote!(#obj #field_path,) } } - (syn::Member::Unnamed(_), None, _, TypeHint::Struct) => { + (Unnamed(_), None, _, TypeHint::Struct) => { if f.attrs.has_parent_attr(&ctx.struct_attr.ty) { match (ctx.kind.is_ref(), ctx.fallible) { (true, true) => quote!(value.try_into()?,), @@ -1091,118 +808,51 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) unreachable!("6") } } - ( - syn::Member::Named(ident), - Some(attr), - Kind::OwnedInto | Kind::RefInto, - TypeHint::Struct | TypeHint::Unspecified, - ) => { + (Named(ident), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Struct | TypeHint::Unspecified) => { let field_name = attr.get_field_name_or(&f.member); - let right_side = - attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); + let right_side = attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); if ctx.has_post_init { quote!(obj.#field_name = #right_side;) } else { quote!(#field_name: #right_side,) } } - ( - syn::Member::Named(ident), - Some(attr), - Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Struct | TypeHint::Unspecified, - ) => { + (Named(ident), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Struct | TypeHint::Unspecified) => { let field_path = get_field_path(attr.get_field_name_or(&f.member)); - let right_side = - attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); + let right_side = attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); quote!(other.#field_path = #right_side;) } - ( - syn::Member::Named(ident), - Some(attr), - Kind::OwnedInto | Kind::RefInto, - TypeHint::Tuple, - ) => { - let right_side = - attr.get_action_or(Some(get_field_path(&f.member)), ctx, || quote!(#obj #ident)); + (Named(ident), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple) => { + let right_side = attr.get_action_or(Some(get_field_path(&f.member)), ctx, || quote!(#obj #ident)); quote!(#right_side,) } - ( - syn::Member::Named(ident), - Some(attr), - Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Tuple, - ) => { - let field_path = get_field_path(&Member::Unnamed(Index { - index: idx as u32, - span: Span::call_site(), - })); - let right_side = - attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); + (Named(ident), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple) => { + let field_path = get_field_path(&Unnamed(Index { index: idx as u32, span: Span::call_site() })); + let right_side = attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); quote!(other.#field_path = #right_side;) } - ( - syn::Member::Named(ident), - Some(attr), - Kind::FromOwned | Kind::FromRef, - TypeHint::Struct | TypeHint::Unspecified | TypeHint::Unit, - ) => { + (Named(ident), Some(attr), Kind::FromOwned | Kind::FromRef, TypeHint::Struct | TypeHint::Unspecified | TypeHint::Unit) => { let right_side = attr.get_stuff(&obj, get_field_path, ctx, || &f.member); quote!(#ident: #right_side,) } - ( - syn::Member::Named(ident), - Some(attr), - Kind::FromOwned | Kind::FromRef, - TypeHint::Tuple, - ) => { - let or = Member::Named(format_ident!("f{}", f.idx)); - let right_side = attr.get_stuff(&obj, get_field_path, ctx, || { - if ctx.impl_type.is_variant() { - &or - } else { - &f.member - } - }); + (Named(ident), Some(attr), Kind::FromOwned | Kind::FromRef, TypeHint::Tuple) => { + let or = Named(format_ident!("f{}", f.idx)); + let right_side = attr.get_stuff(&obj, get_field_path, ctx, || if ctx.impl_type.is_variant() { &or } else { &f.member }); quote!(#ident: #right_side,) } - ( - syn::Member::Unnamed(index), - Some(attr), - Kind::OwnedInto | Kind::RefInto, - TypeHint::Tuple | TypeHint::Unspecified, - ) => { - let index = if ctx.impl_type.is_variant() { - Some(format_ident!("f{}", index.index).to_token_stream()) - } else { - Some(index.to_token_stream()) - }; + (Unnamed(index), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple | TypeHint::Unspecified) => { + let index = if ctx.impl_type.is_variant() { Some(format_ident!("f{}", index.index).to_token_stream()) } else { Some(index.to_token_stream()) }; let right_side = attr.get_action_or(index.clone(), ctx, || quote!(#obj #index)); quote!(#right_side,) } - ( - syn::Member::Unnamed(index), - Some(attr), - Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Tuple | TypeHint::Unspecified, - ) => { + (Unnamed(index), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple | TypeHint::Unspecified) => { let field_path = get_field_path(attr.get_field_name_or(&f.member)); - let right_side = - attr.get_action_or(Some(index.to_token_stream()), ctx, || quote!(#obj #index)); + let right_side = attr.get_action_or(Some(index.to_token_stream()), ctx, || quote!(#obj #index)); quote!(other.#field_path = #right_side;) } - ( - syn::Member::Unnamed(index), - Some(attr), - Kind::OwnedInto | Kind::RefInto, - TypeHint::Struct, - ) => { + (Unnamed(index), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Struct) => { let field_name = attr.get_ident(); - let or = if ctx.impl_type.is_variant() { - format_ident!("f{}", index.index).to_token_stream() - } else { - index.to_token_stream() - }; + let or = if ctx.impl_type.is_variant() { format_ident!("f{}", index.index).to_token_stream() } else { index.to_token_stream() }; let right_side = attr.get_action_or(Some(or.clone()), ctx, || quote!(#obj #or)); if ctx.has_post_init { quote!(obj.#field_name = #right_side;) @@ -1210,41 +860,22 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) quote!(#field_name: #right_side,) } } - ( - syn::Member::Unnamed(index), - Some(attr), - Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Struct, - ) => { + (Unnamed(index), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Struct) => { let field_path = get_field_path(attr.get_ident()); - let right_side = - attr.get_action_or(Some(index.to_token_stream()), ctx, || quote!(#obj #index)); + let right_side = attr.get_action_or(Some(index.to_token_stream()), ctx, || quote!(#obj #index)); quote!(other.#field_path = #right_side;) } - (syn::Member::Unnamed(index), Some(attr), Kind::FromOwned | Kind::FromRef, _) => { - let or = Member::Named(format_ident!("f{}", index.index)); - let right_side = attr.get_stuff(&obj, get_field_path, ctx, || { - if ctx.impl_type.is_variant() { - &or - } else { - &f.member - } - }); + (Unnamed(index), Some(attr), Kind::FromOwned | Kind::FromRef, _) => { + let or = Named(format_ident!("f{}", index.index)); + let right_side = attr.get_stuff(&obj, get_field_path, ctx, || if ctx.impl_type.is_variant() { &or } else { &f.member }); quote!(#right_side,) } - ( - _, - _, - Kind::OwnedInto | Kind::RefInto | Kind::OwnedIntoExisting | Kind::RefIntoExisting, - TypeHint::Unit, - ) => TokenStream::new(), + (_, _, Kind::OwnedInto | Kind::RefInto | Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Unit) => TokenStream::new(), } } fn render_enum_line(v: &Variant, ctx: &ImplContext) -> TokenStream { - let attr = v - .attrs - .applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); + let attr = v.attrs.applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); let lit = v.attrs.lit(&ctx.struct_attr.ty); let pat = v.attrs.pat(&ctx.struct_attr.ty); let var = v.attrs.type_hint(&ctx.struct_attr.ty); @@ -1255,10 +886,7 @@ fn render_enum_line(v: &Variant, ctx: &ImplContext) -> TokenStream { let ident = &v.ident; let variant_struct: Struct<'_> = Struct { - attrs: DataTypeAttrs { - ghosts_attrs: v.attrs.ghosts_attrs.clone(), - ..Default::default() - }, + attrs: DataTypeAttrs { ghosts_attrs: v.attrs.ghosts_attrs.clone(), ..Default::default() }, ident, generics: &Default::default(), fields: v.fields.clone(), @@ -1270,11 +898,7 @@ fn render_enum_line(v: &Variant, ctx: &ImplContext) -> TokenStream { let type_hint = var.map_or(TypeHint::Unspecified, |x| x.type_hint); struct_attr.type_hint = type_hint; - let new_ctx = ImplContext { - struct_attr: &struct_attr, - impl_type: ImplType::Variant, - ..*ctx - }; + let new_ctx = ImplContext { struct_attr: &struct_attr, impl_type: ImplType::Variant, ..*ctx }; let empty_fields = variant_struct.fields.is_empty(); let destr = if empty_fields && (!new_ctx.kind.is_from() || type_hint.maybe(TypeHint::Unit)) { @@ -1286,9 +910,8 @@ fn render_enum_line(v: &Variant, ctx: &ImplContext) -> TokenStream { } else { variant_destruct_block(&variant_struct, &new_ctx) }; - let init = if attr.as_ref().is_some_and(|x| x.has_action()) - || empty_fields && type_hint.maybe(TypeHint::Unit) - { + + let init = if attr.as_ref().is_some_and(|x| x.has_action()) || empty_fields && type_hint.maybe(TypeHint::Unit) { TokenStream::new() } else { struct_init_block(&variant_struct, &new_ctx) @@ -1299,14 +922,13 @@ fn render_enum_line(v: &Variant, ctx: &ImplContext) -> TokenStream { quote!(#src::#ident #destr => #dst::#ident #init,) } (_, Some(attr), None, None, Kind::FromOwned | Kind::FromRef) => { - let member = Member::Named(ident.clone()); - let right_side = - attr.get_action_or(Some(quote!(#ident)), ctx, || quote!(#dst::#ident #init)); + let member = Named(ident.clone()); + let right_side = attr.get_action_or(Some(quote!(#ident)), ctx, || quote!(#dst::#ident #init)); let ident2 = attr.get_field_name_or(&member); quote!(#src::#ident2 #destr => #right_side,) } (_, Some(attr), None, None, Kind::OwnedInto | Kind::RefInto) => { - let member = Member::Named(ident.clone()); + let member = Named(ident.clone()); let right_side = attr.get_stuff("e!(#dst::), |x| quote!(#x #init), ctx, || &member); quote!(#src::#ident #destr => #right_side,) } @@ -1341,14 +963,10 @@ fn render_ghost_line(ghost_data: &GhostData, ctx: &ImplContext) -> TokenStream { let right_side = quote_action(&ghost_data.action, None, ctx); let ghost_ident = &ghost_data.ghost_ident.get_ident(); match (ghost_ident, &ctx.kind) { - (Member::Named(ident), Kind::OwnedInto | Kind::RefInto) => quote!(#ident: #right_side,), - (Member::Unnamed(_), Kind::OwnedInto | Kind::RefInto) => quote!(#right_side,), - (Member::Named(ident), Kind::OwnedIntoExisting | Kind::RefIntoExisting) => { - quote!(other.#ch #ident = #right_side;) - } - (Member::Unnamed(index), Kind::OwnedIntoExisting | Kind::RefIntoExisting) => { - quote!(other.#ch #index = #right_side;) - } + (Named(ident), Kind::OwnedInto | Kind::RefInto) => quote!(#ident: #right_side,), + (Unnamed(_), Kind::OwnedInto | Kind::RefInto) => quote!(#right_side,), + (Named(ident), Kind::OwnedIntoExisting | Kind::RefIntoExisting) => quote!(other.#ch #ident = #right_side;), + (Unnamed(index), Kind::OwnedIntoExisting | Kind::RefIntoExisting) => quote!(other.#ch #index = #right_side;), (_, _) => unreachable!("7"), } } @@ -1359,8 +977,8 @@ fn render_enum_ghost_line(ghost_data: &GhostData, ctx: &ImplContext) -> TokenStr match &ghost_data.ghost_ident { GhostIdent::Member(ghost_ident) => match (ghost_ident, ctx.kind.is_from()) { - (Member::Unnamed(_), _) => unreachable!("17"), - (Member::Named(ident), true) => quote!(#src::#ident => #right_side,), + (Unnamed(_), _) => unreachable!("17"), + (Named(ident), true) => quote!(#src::#ident => #right_side,), (_, false) => TokenStream::new(), }, GhostIdent::Destruction(destr) => { @@ -1373,11 +991,7 @@ fn render_enum_ghost_line(ghost_data: &GhostData, ctx: &ImplContext) -> TokenStr } } -fn replace_tilde_or_at_in_expr( - input: &TokenStream, - at_tokens: Option<&TokenStream>, - tilde_tokens: Option<&TokenStream>, -) -> TokenStream { +fn replace_tilde_or_at_in_expr(input: &TokenStream, at_tokens: Option<&TokenStream>, tilde_tokens: Option<&TokenStream>) -> TokenStream { let mut tokens = Vec::new(); input.clone().into_iter().for_each(|x| { @@ -1411,11 +1025,7 @@ fn replace_tilde_or_at_in_expr( TokenStream::from_iter(tokens) } -fn quote_action( - action: &TokenStream, - tilde_postfix: Option, - ctx: &ImplContext, -) -> TokenStream { +fn quote_action(action: &TokenStream, tilde_postfix: Option, ctx: &ImplContext) -> TokenStream { let dst = ctx.dst_ty; let ident = match ctx.kind { Kind::FromOwned | Kind::FromRef => quote!(value), @@ -1478,19 +1088,9 @@ fn get_quote_trait_params<'a>(input: &DataType, ctx: &'a ImplContext) -> QuoteTr // If there is at least one lifetime in generics, we add a new lifetime `'o2o` and add a bound `'o2o: 'a + 'b`. let (gens_impl, where_clause, r) = if ctx.kind.is_ref() { // If lifetime is empty, we assume that lifetime generics come from the other structure (src <-> dst). - let lifetimes: Vec<_> = if lifetimes.is_empty() { - generics - .lifetimes() - .map(|params| params.lifetime.clone()) - .collect() - } else { - lifetimes - }; + let lifetimes: Vec<_> = if lifetimes.is_empty() { generics.lifetimes().map(|params| params.lifetime.clone()).collect() } else { lifetimes }; - let mut where_clause = input - .get_attrs() - .where_attr(&ctx.struct_attr.ty) - .map(|x| x.where_clause.clone()); + let mut where_clause = input.get_attrs().where_attr(&ctx.struct_attr.ty).map(|x| x.where_clause.clone()); let r = if !lifetimes.is_empty() { generics_impl.params.push(parse_quote!('o2o)); @@ -1502,11 +1102,7 @@ fn get_quote_trait_params<'a>(input: &DataType, ctx: &'a ImplContext) -> QuoteTr Some(quote!(&)) }; - ( - generics_impl.to_token_stream(), - where_clause.map(|where_clause| quote!(where #where_clause)), - r, - ) + (generics_impl.to_token_stream(), where_clause.map(|where_clause| quote!(where #where_clause)), r) } else { ( input.get_generics().to_token_stream(), @@ -1531,23 +1127,8 @@ fn get_quote_trait_params<'a>(input: &DataType, ctx: &'a ImplContext) -> QuoteTr } } -fn quote_from_trait( - input: &DataType, - ctx: &ImplContext, - pre_init: Option, - init: TokenStream, -) -> TokenStream { - let QuoteTraitParams { - attr, - impl_attr, - inner_attr, - dst, - src, - gens, - gens_impl, - where_clause, - r, - } = get_quote_trait_params(input, ctx); +fn quote_from_trait(input: &DataType, ctx: &ImplContext, pre_init: Option, init: TokenStream) -> TokenStream { + let QuoteTraitParams { attr, impl_attr, inner_attr, dst, src, gens, gens_impl, where_clause, r } = get_quote_trait_params(input, ctx); quote! { #impl_attr impl #gens_impl ::core::convert::From<#r #src> for #dst #gens #where_clause { @@ -1561,23 +1142,8 @@ fn quote_from_trait( } } -fn quote_try_from_trait( - input: &DataType, - ctx: &ImplContext, - pre_init: Option, - init: TokenStream, -) -> TokenStream { - let QuoteTraitParams { - attr, - impl_attr, - inner_attr, - dst, - src, - gens, - gens_impl, - where_clause, - r, - } = get_quote_trait_params(input, ctx); +fn quote_try_from_trait(input: &DataType, ctx: &ImplContext, pre_init: Option, init: TokenStream) -> TokenStream { + let QuoteTraitParams { attr, impl_attr, inner_attr, dst, src, gens, gens_impl, where_clause, r } = get_quote_trait_params(input, ctx); let err_ty = &ctx.struct_attr.err_ty.as_ref().unwrap().path; quote! { #impl_attr @@ -1593,24 +1159,8 @@ fn quote_try_from_trait( } } -fn quote_into_trait( - input: &DataType, - ctx: &ImplContext, - pre_init: Option, - init: TokenStream, - post_init: Option, -) -> TokenStream { - let QuoteTraitParams { - attr, - impl_attr, - inner_attr, - dst, - src, - gens, - gens_impl, - where_clause, - r, - } = get_quote_trait_params(input, ctx); +fn quote_into_trait(input: &DataType, ctx: &ImplContext, pre_init: Option, init: TokenStream, post_init: Option) -> TokenStream { + let QuoteTraitParams { attr, impl_attr, inner_attr, dst, src, gens, gens_impl, where_clause, r } = get_quote_trait_params(input, ctx); let body = match post_init { Some(post_init) => quote! { @@ -1637,24 +1187,8 @@ fn quote_into_trait( } } -fn quote_try_into_trait( - input: &DataType, - ctx: &ImplContext, - pre_init: Option, - init: TokenStream, - post_init: Option, -) -> TokenStream { - let QuoteTraitParams { - attr, - impl_attr, - inner_attr, - dst, - src, - gens, - gens_impl, - where_clause, - r, - } = get_quote_trait_params(input, ctx); +fn quote_try_into_trait(input: &DataType, ctx: &ImplContext, pre_init: Option, init: TokenStream, post_init: Option) -> TokenStream { + let QuoteTraitParams { attr, impl_attr, inner_attr, dst, src, gens, gens_impl, where_clause, r } = get_quote_trait_params(input, ctx); let err_ty = &ctx.struct_attr.err_ty.as_ref().unwrap().path; let body = match post_init { @@ -1683,24 +1217,8 @@ fn quote_try_into_trait( } } -fn quote_into_existing_trait( - input: &DataType, - ctx: &ImplContext, - pre_init: Option, - init: TokenStream, - post_init: Option, -) -> TokenStream { - let QuoteTraitParams { - attr, - impl_attr, - inner_attr, - dst, - src, - gens, - gens_impl, - where_clause, - r, - } = get_quote_trait_params(input, ctx); +fn quote_into_existing_trait(input: &DataType, ctx: &ImplContext, pre_init: Option, init: TokenStream, post_init: Option) -> TokenStream { + let QuoteTraitParams { attr, impl_attr, inner_attr, dst, src, gens, gens_impl, where_clause, r } = get_quote_trait_params(input, ctx); quote! { #impl_attr impl #gens_impl o2o::traits::IntoExisting<#dst> for #r #src #gens #where_clause { @@ -1715,24 +1233,8 @@ fn quote_into_existing_trait( } } -fn quote_try_into_existing_trait( - input: &DataType, - ctx: &ImplContext, - pre_init: Option, - init: TokenStream, - post_init: Option, -) -> TokenStream { - let QuoteTraitParams { - attr, - impl_attr, - inner_attr, - dst, - src, - gens, - gens_impl, - where_clause, - r, - } = get_quote_trait_params(input, ctx); +fn quote_try_into_existing_trait(input: &DataType, ctx: &ImplContext, pre_init: Option, init: TokenStream, post_init: Option) -> TokenStream { + let QuoteTraitParams { attr, impl_attr, inner_attr, dst, src, gens, gens_impl, where_clause, r } = get_quote_trait_params(input, ctx); let err_ty = &ctx.struct_attr.err_ty.as_ref().unwrap().path; quote! { #impl_attr @@ -1778,12 +1280,7 @@ impl<'a> ApplicableAttr<'a> { } } - fn get_action_or TokenStream>( - &self, - field_path: Option, - ctx: &ImplContext, - or: F, - ) -> TokenStream { + fn get_action_or TokenStream>(&self, field_path: Option, ctx: &ImplContext, or: F) -> TokenStream { match self { ApplicableAttr::Field(field_attr) => match &field_attr.action { Some(val) => quote_action(val, field_path, ctx), @@ -1793,19 +1290,13 @@ impl<'a> ApplicableAttr<'a> { } } - fn get_stuff TokenStream, F2: Fn() -> &'a Member>( - &self, - obj: &TokenStream, - field_path: F1, - ctx: &ImplContext, - or: F2, - ) -> TokenStream { + fn get_stuff TokenStream, F2: Fn() -> &'a Member>(&self, obj: &TokenStream, field_path: F1, ctx: &ImplContext, or: F2) -> TokenStream { match self { ApplicableAttr::Field(field_attr) => match (&field_attr.member, &field_attr.action) { (Some(ident), Some(action)) => { - if let Member::Unnamed(index) = ident { + if let Unnamed(index) = ident { if ctx.impl_type.is_variant() { - let ident = Member::Named(format_ident!("f{}", index.index)); + let ident = Named(format_ident!("f{}", index.index)); quote_action(action, Some(field_path(&ident)), ctx) } else { quote_action(action, Some(field_path(ident)), ctx) @@ -1821,9 +1312,7 @@ impl<'a> ApplicableAttr<'a> { (None, Some(action)) => quote_action(action, Some(field_path(or())), ctx), _ => unreachable!("12"), }, - ApplicableAttr::Ghost(ghost_attr) => { - quote_action(ghost_attr.action.as_ref().unwrap(), None, ctx) - } + ApplicableAttr::Ghost(ghost_attr) => quote_action(ghost_attr.action.as_ref().unwrap(), None, ctx), } } } diff --git a/o2o-impl/src/tests.rs b/o2o-impl/src/tests.rs index c7812f2..59284b3 100644 --- a/o2o-impl/src/tests.rs +++ b/o2o-impl/src/tests.rs @@ -510,13 +510,7 @@ fn more_than_one_default_instruction(code_fragment: TokenStream, err: &str) { let output = derive(&input); let message = get_error(output, true); - assert_eq!( - message, - format!( - "There can be at most one default #[{}(...)] instruction.", - err - ) - ); + assert_eq!(message, format!("There can be at most one default #[{}(...)] instruction.", err)); } // endregion: more_than_one_default_instruction @@ -560,13 +554,7 @@ fn more_than_one_default_member_instruction(code_fragment: TokenStream, err: &st let output = derive(&input); let message = get_error(output, true); - assert_eq!( - message, - format!( - "There can be at most one default #[{}(...)] instruction for a given member.", - err - ) - ); + assert_eq!(message, format!("There can be at most one default #[{}(...)] instruction for a given member.", err)); } // endregion: more_than_one_default_member_instruction @@ -602,13 +590,7 @@ fn dedicated_instruction_defined_twice(code_fragment: TokenStream, err_instr: &s let output = derive(&input); let message = get_error(output, true); - assert_eq!( - message, - format!( - "Dedicated #[{}(...)] instruction for type {} is already defined.", - err_instr, err_ty - ) - ); + assert_eq!(message, format!("Dedicated #[{}(...)] instruction for type {} is already defined.", err_instr, err_ty)); } // endregion: dedicated_instruction_defined_twice @@ -647,22 +629,12 @@ fn dedicated_instruction_defined_twice(code_fragment: TokenStream, err_instr: &s Var } }, "type_hint", "EnumDto"; "enum_type_hint_instr")] -fn dedicated_member_instruction_defined_twice( - code_fragment: TokenStream, - err_instr: &str, - err_ty: &str, -) { +fn dedicated_member_instruction_defined_twice(code_fragment: TokenStream, err_instr: &str, err_ty: &str) { let input: DeriveInput = syn::parse2(code_fragment).unwrap(); let output = derive(&input); let message = get_error(output, true); - assert_eq!( - message, - format!( - "Dedicated #[{}(...)] instruction for type {} is already defined.", - err_instr, err_ty - ) - ); + assert_eq!(message, format!("Dedicated #[{}(...)] instruction for type {} is already defined.", err_instr, err_ty)); } // endregion: dedicated_member_instruction_defined_twice @@ -825,11 +797,7 @@ fn dedicated_field_instruction_mismatch(code_fragment: TokenStream, errs: Vec<&s assert_eq!(errs.len(), errors.len()); for err_ty in errs { - assert!(errors.iter().any(|x| x.to_string() - == format!( - "Type '{}' doesn't match any type specified in trait instructions.", - err_ty - ))) + assert!(errors.iter().any(|x| x.to_string() == format!("Type '{}' doesn't match any type specified in trait instructions.", err_ty))) } } else { assert!(output.is_ok()) @@ -961,16 +929,10 @@ fn missing_children_instruction(code_fragment: TokenStream, errs: Vec<(&str, boo for (ty, should_contain) in errs { match should_contain { true => { - assert!(errors - .iter() - .any(|x| x.to_string() - == format!("Missing #[children(...)] instruction for {}", ty))) + assert!(errors.iter().any(|x| x.to_string() == format!("Missing #[children(...)] instruction for {}", ty))) } false => { - assert!(!errors - .iter() - .any(|x| x.to_string() - == format!("Missing #[children(...)] instruction for {}", ty))) + assert!(!errors.iter().any(|x| x.to_string() == format!("Missing #[children(...)] instruction for {}", ty))) } } } @@ -1050,11 +1012,7 @@ fn member_instr_on_wrong_member(code_fragment: TokenStream, errs: Vec<&str>) { assert_eq!(errs.len(), errors.len()); for err in errs { - assert!(errors.iter().any(|x| x.to_string() - == format!( - "Instruction #[{}(...)] is not supported for this member.", - err - ))) + assert!(errors.iter().any(|x| x.to_string() == format!("Instruction #[{}(...)] is not supported for this member.", err))) } } else { assert!(output.is_ok()) @@ -1127,16 +1085,8 @@ fn incomplete_children_instruction(code_fragment: TokenStream, errs: Vec<(&str, for (field, ty, should_contain) in errs { match should_contain { - true => assert!(errors.iter().any(|x| x.to_string() - == format!( - "Missing '{}: [Type Path]' instruction for type {}", - field, ty - ))), - false => assert!(!errors.iter().any(|x| x.to_string() - == format!( - "Missing '{}: [Type Path]' instruction for type {}", - field, ty - ))), + true => assert!(errors.iter().any(|x| x.to_string() == format!("Missing '{}: [Type Path]' instruction for type {}", field, ty))), + false => assert!(!errors.iter().any(|x| x.to_string() == format!("Missing '{}: [Type Path]' instruction for type {}", field, ty))), } } } @@ -1299,7 +1249,9 @@ fn incomplete_field_attr_instruction(code_fragment: TokenStream, errs: Vec<(&str assert_eq!(errs.len(), errors.len()); for (field, ty, or_action) in errs { - assert!(errors.iter().any(|x| x.to_string() == format!("Member 0 should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", if or_action {" or an action"} else {""}, field, ty))) + assert!(errors + .iter() + .any(|x| x.to_string() == format!("Member 0 should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", if or_action { " or an action" } else { "" }, field, ty))) } } else { assert!(output.is_ok()) @@ -1478,11 +1430,7 @@ fn incomplete_field_attr_instruction(code_fragment: TokenStream, errs: Vec<(&str (1, "Var3", "ref_try_into_existing", "TestDto", false), (0, "Var4", "ref_try_into_existing", "TestDto", false), ]; "24")] -fn incomplete_variant_field_attr_instruction( - code_fragment: TokenStream, - err_ty: TokenStream, - errs: Vec<(u32, &str, &str, &str, bool)>, -) { +fn incomplete_variant_field_attr_instruction(code_fragment: TokenStream, err_ty: TokenStream, errs: Vec<(u32, &str, &str, &str, bool)>) { let code_fragment = quote! { #[#code_fragment(TestDto #err_ty)] enum Test2Dto { @@ -1502,7 +1450,9 @@ fn incomplete_variant_field_attr_instruction( assert_eq!(errs.len(), errors.len()); for (idx, variant, field, ty, or_action) in errs { - assert!(errors.iter().any(|x| x.to_string() == format!("Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", idx, variant, if or_action {" or an action"} else {""}, field, ty))) + assert!(errors + .iter() + .any(|x| x.to_string() == format!("Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", idx, variant, if or_action { " or an action" } else { "" }, field, ty))) } } else { assert!(output.is_ok()) @@ -1590,7 +1540,9 @@ fn incomplete_field_attr_instruction_2(code_fragment: TokenStream, errs: Vec<(&s assert_eq!(errs.len(), errors.len()); for (field, ty, or_action) in errs { - assert!(errors.iter().any(|x| x.to_string() == format!("Member trait instruction #[{}(...)] for member 0 should specify corresponding field name of the {}{}", field, ty, if or_action {" or an action"} else {""}))) + assert!(errors + .iter() + .any(|x| x.to_string() == format!("Member trait instruction #[{}(...)] for member 0 should specify corresponding field name of the {}{}", field, ty, if or_action { " or an action" } else { "" }))) } } else { assert!(output.is_ok()) @@ -1649,10 +1601,7 @@ fn fallible_map_instruction_no_error_type(instr: TokenStream, postfix: Option, expect_root_error: bool) -> Str if expect_root_error { let error = err_iter.next(); - assert_eq!( - error.expect("Root error expected").to_string(), - "Cannot expand o2o macro" - ); + assert_eq!(error.expect("Root error expected").to_string(), "Cannot expand o2o macro"); } let error = err_iter.next(); diff --git a/o2o-impl/src/validate.rs b/o2o-impl/src/validate.rs index f6b13eb..750ee50 100644 --- a/o2o-impl/src/validate.rs +++ b/o2o-impl/src/validate.rs @@ -1,10 +1,6 @@ use crate::{ ast::{DataType, DataTypeMember, Struct, Variant}, - attr::{ - ChildAttr, ChildrenAttr, DataTypeAttrs, DataTypeInstruction, FallibleKind, GhostsAttr, - Kind, MemberAttrs, MemberInstruction, TraitAttr, TraitAttrCore, TypeHint, TypePath, - WhereAttr, - }, + attr::{ChildAttr, ChildrenAttr, DataTypeAttrs, DataTypeInstruction, FallibleKind, GhostsAttr, Kind, MemberAttrs, MemberInstruction, TraitAttr, TraitAttrCore, TypeHint, TypePath, WhereAttr}, }; use proc_macro2::Span; use quote::ToTokens; @@ -16,118 +12,33 @@ pub(crate) fn validate(input: &DataType) -> Result<()> { let mut errors: HashMap = HashMap::new(); if attrs.attrs.is_empty() { - errors.insert( - "At least one trait instruction is expected.".into(), - Span::call_site(), - ); + errors.insert("At least one trait instruction is expected.".into(), Span::call_site()); } validate_error_instrs(input, attrs, &mut errors); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::FromOwned, false), - false, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::FromRef, false), - false, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::OwnedInto, false), - false, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::RefInto, false), - false, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, false), - false, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::RefIntoExisting, false), - false, - &mut errors, - ); - - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::FromOwned, true), - true, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::FromRef, true), - true, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::OwnedInto, true), - true, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::RefInto, true), - true, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, true), - true, - &mut errors, - ); - validate_struct_attrs( - attrs.iter_for_kind_core(&Kind::RefIntoExisting, true), - true, - &mut errors, - ); - - let type_paths = attrs - .attrs - .iter() - .map(|x| &x.core.ty) - .collect::>(); - - validate_ghost_attrs( - &Kind::FromOwned, - &attrs.ghosts_attrs, - &type_paths, - &mut errors, - ); - validate_ghost_attrs( - &Kind::FromRef, - &attrs.ghosts_attrs, - &type_paths, - &mut errors, - ); - validate_ghost_attrs( - &Kind::OwnedInto, - &attrs.ghosts_attrs, - &type_paths, - &mut errors, - ); - validate_ghost_attrs( - &Kind::RefInto, - &attrs.ghosts_attrs, - &type_paths, - &mut errors, - ); - validate_ghost_attrs( - &Kind::OwnedIntoExisting, - &attrs.ghosts_attrs, - &type_paths, - &mut errors, - ); - validate_ghost_attrs( - &Kind::RefIntoExisting, - &attrs.ghosts_attrs, - &type_paths, - &mut errors, - ); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::FromOwned, false), false, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::FromRef, false), false, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::OwnedInto, false), false, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::RefInto, false), false, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, false), false, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::RefIntoExisting, false), false, &mut errors); + + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::FromOwned, true), true, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::FromRef, true), true, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::OwnedInto, true), true, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::RefInto, true), true, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, true), true, &mut errors); + validate_struct_attrs(attrs.iter_for_kind_core(&Kind::RefIntoExisting, true), true, &mut errors); + + let type_paths = attrs.attrs.iter().map(|x| &x.core.ty).collect::>(); + + validate_ghost_attrs(&Kind::FromOwned, &attrs.ghosts_attrs, &type_paths, &mut errors); + validate_ghost_attrs(&Kind::FromRef, &attrs.ghosts_attrs, &type_paths, &mut errors); + validate_ghost_attrs(&Kind::OwnedInto, &attrs.ghosts_attrs, &type_paths, &mut errors); + validate_ghost_attrs(&Kind::RefInto, &attrs.ghosts_attrs, &type_paths, &mut errors); + validate_ghost_attrs(&Kind::OwnedIntoExisting, &attrs.ghosts_attrs, &type_paths, &mut errors); + validate_ghost_attrs(&Kind::RefIntoExisting, &attrs.ghosts_attrs, &type_paths, &mut errors); validate_children_attrs(&attrs.children_attrs, &type_paths, &mut errors); validate_where_attrs(&attrs.where_attrs, &type_paths, &mut errors); @@ -136,121 +47,26 @@ pub(crate) fn validate(input: &DataType) -> Result<()> { let member_span = member.get_span(); let member_attrs = member.get_attrs(); - validate_dedicated_member_attrs( - &member_attrs.attrs, - |x| x.attr.container_ty.as_ref(), - None, - member_span, - &type_paths, - &mut errors, - ); - validate_dedicated_member_attrs( - &member_attrs.ghost_attrs, - |x| x.attr.container_ty.as_ref(), - None, - member_span, - &type_paths, - &mut errors, - ); + validate_dedicated_member_attrs(&member_attrs.attrs, |x| x.attr.container_ty.as_ref(), None, member_span, &type_paths, &mut errors); + validate_dedicated_member_attrs(&member_attrs.ghost_attrs, |x| x.attr.container_ty.as_ref(), None, member_span, &type_paths, &mut errors); match member { DataTypeMember::Field(f) => { - bark_at_member_attr( - &member_attrs.lit_attrs, - "literal", - |_| f.member.span(), - &mut errors, - ); - bark_at_member_attr( - &member_attrs.pat_attrs, - "pattern", - |_| f.member.span(), - &mut errors, - ); - bark_at_member_attr( - &member_attrs.type_hint_attrs, - "type_hint", - |_| f.member.span(), - &mut errors, - ); - bark_at_member_attr( - &member_attrs - .ghosts_attrs - .iter() - .filter(|x| { - x.applicable_to[&Kind::OwnedInto] && x.applicable_to[&Kind::RefInto] - }) - .collect(), - "ghosts", - |_| f.member.span(), - &mut errors, - ); - bark_at_member_attr( - &member_attrs - .ghosts_attrs - .iter() - .filter(|x| { - x.applicable_to[&Kind::OwnedInto] && !x.applicable_to[&Kind::RefInto] - }) - .collect(), - "ghosts_owned", - |_| f.member.span(), - &mut errors, - ); - bark_at_member_attr( - &member_attrs - .ghosts_attrs - .iter() - .filter(|x| { - !x.applicable_to[&Kind::OwnedInto] && x.applicable_to[&Kind::RefInto] - }) - .collect(), - "ghosts_ref", - |_| f.member.span(), - &mut errors, - ); - - validate_dedicated_member_attrs( - &member_attrs.parent_attrs, - |x| x.container_ty.as_ref(), - Some("parent"), - member_span, - &type_paths, - &mut errors, - ); + bark_at_member_attr(&member_attrs.lit_attrs, "literal", |_| f.member.span(), &mut errors); + bark_at_member_attr(&member_attrs.pat_attrs, "pattern", |_| f.member.span(), &mut errors); + bark_at_member_attr(&member_attrs.type_hint_attrs, "type_hint", |_| f.member.span(), &mut errors); + bark_at_member_attr(&member_attrs.ghosts_attrs.iter().filter(|x| x.applicable_to[&Kind::OwnedInto] && x.applicable_to[&Kind::RefInto]).collect(), "ghosts", |_| f.member.span(), &mut errors); + bark_at_member_attr(&member_attrs.ghosts_attrs.iter().filter(|x| x.applicable_to[&Kind::OwnedInto] && !x.applicable_to[&Kind::RefInto]).collect(), "ghosts_owned", |_| f.member.span(), &mut errors); + bark_at_member_attr(&member_attrs.ghosts_attrs.iter().filter(|x| !x.applicable_to[&Kind::OwnedInto] && x.applicable_to[&Kind::RefInto]).collect(), "ghosts_ref", |_| f.member.span(), &mut errors); + + validate_dedicated_member_attrs(&member_attrs.parent_attrs, |x| x.container_ty.as_ref(), Some("parent"), member_span, &type_paths, &mut errors); } DataTypeMember::Variant(v) => { - bark_at_member_attr( - &member_attrs.parent_attrs, - "parent", - |_| v.ident.span(), - &mut errors, - ); - - validate_dedicated_member_attrs( - &member_attrs.lit_attrs, - |x| x.container_ty.as_ref(), - Some("literal"), - member_span, - &type_paths, - &mut errors, - ); - validate_dedicated_member_attrs( - &member_attrs.pat_attrs, - |x| x.container_ty.as_ref(), - Some("pattern"), - member_span, - &type_paths, - &mut errors, - ); - validate_dedicated_member_attrs( - &member_attrs.type_hint_attrs, - |x| x.container_ty.as_ref(), - Some("type_hint"), - member_span, - &type_paths, - &mut errors, - ); + bark_at_member_attr(&member_attrs.parent_attrs, "parent", |_| v.ident.span(), &mut errors); + + validate_dedicated_member_attrs(&member_attrs.lit_attrs, |x| x.container_ty.as_ref(), Some("literal"), member_span, &type_paths, &mut errors); + validate_dedicated_member_attrs(&member_attrs.pat_attrs, |x| x.container_ty.as_ref(), Some("pattern"), member_span, &type_paths, &mut errors); + validate_dedicated_member_attrs(&member_attrs.type_hint_attrs, |x| x.container_ty.as_ref(), Some("type_hint"), member_span, &type_paths, &mut errors); } } @@ -273,19 +89,13 @@ pub(crate) fn validate(input: &DataType) -> Result<()> { } else { let mut root_err = syn::Error::new(Span::call_site(), "Cannot expand o2o macro"); - errors - .iter() - .for_each(|(err, sp)| root_err.combine(syn::Error::new(*sp, err))); + errors.iter().for_each(|(err, sp)| root_err.combine(syn::Error::new(*sp, err))); Err(root_err) } } -fn validate_error_instrs( - input: &DataType, - attrs: &DataTypeAttrs, - errors: &mut HashMap, -) { +fn validate_error_instrs(input: &DataType, attrs: &DataTypeAttrs, errors: &mut HashMap) { let postfix = |own: bool| { if !own { " To turn this message off, use #[o2o(allow_unknown)]" @@ -296,72 +106,24 @@ fn validate_error_instrs( for err in &attrs.error_instrs { match (input, err) { - ( - DataType::Enum(_), - DataTypeInstruction::Misnamed { - instr: instr @ "child", - span, - guess_name: _, - own, - }, - ) - | ( - DataType::Enum(_), - DataTypeInstruction::Misplaced { - instr: instr @ ("parent" | "as_type"), - span, - own, - }, - ) => { - errors.insert( - format!( - "Member instruction '{}' is not applicable to enums.{}", - instr, - postfix(*own) - ), - *span, - ); + (DataType::Enum(_), DataTypeInstruction::Misnamed { instr: instr @ "child", span, guess_name: _, own }) | (DataType::Enum(_), DataTypeInstruction::Misplaced { instr: instr @ ("parent" | "as_type"), span, own }) => { + errors.insert(format!("Member instruction '{}' is not applicable to enums.{}", instr, postfix(*own)), *span); } - ( - _, - DataTypeInstruction::Misnamed { - instr: _, - span, - guess_name, - own, - }, - ) => { - errors.insert( - format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), - *span, - ); + (_, DataTypeInstruction::Misnamed { instr: _, span, guess_name, own }) => { + errors.insert(format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), *span); } (_, DataTypeInstruction::Misplaced { instr, span, own }) => { - errors.insert( - format!( - "Member instruction '{}' should be used on a member.{}", - instr, - postfix(*own) - ), - *span, - ); + errors.insert(format!("Member instruction '{}' should be used on a member.{}", instr, postfix(*own)), *span); } (_, DataTypeInstruction::UnrecognizedWithError { instr, span }) => { - errors.insert( - format!("Struct instruction '{}' is not supported.", instr), - *span, - ); + errors.insert(format!("Struct instruction '{}' is not supported.", instr), *span); } _ => unreachable!("13"), } } } -fn validate_member_error_instrs( - input: &DataType, - attrs: &MemberAttrs, - errors: &mut HashMap, -) { +fn validate_member_error_instrs(input: &DataType, attrs: &MemberAttrs, errors: &mut HashMap) { let postfix = |own: bool| { if !own { " To turn this message off, use #[o2o(allow_unknown)]" @@ -372,64 +134,24 @@ fn validate_member_error_instrs( for err in &attrs.error_instrs { match (input, err) { - ( - DataType::Enum(_), - MemberInstruction::Misnamed { - instr: instr @ "children", - span, - guess_name: _, - own, - }, - ) => { - errors.insert( - format!( - "Struct instruction '{}' is not applicable to enums.{}", - instr, - postfix(*own) - ), - *span, - ); + (DataType::Enum(_), MemberInstruction::Misnamed { instr: instr @ "children", span, guess_name: _, own }) => { + errors.insert(format!("Struct instruction '{}' is not applicable to enums.{}", instr, postfix(*own)), *span); } - ( - _, - MemberInstruction::Misnamed { - instr: _, - span, - guess_name, - own, - }, - ) => { - errors.insert( - format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), - *span, - ); + (_, MemberInstruction::Misnamed { instr: _, span, guess_name, own }) => { + errors.insert(format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), *span); } (_, MemberInstruction::Misplaced { instr, span, own }) => { - errors.insert( - format!( - "Struct instruction '{}' should be used on a struct.{}", - instr, - postfix(*own) - ), - *span, - ); + errors.insert(format!("Struct instruction '{}' should be used on a struct.{}", instr, postfix(*own)), *span); } (_, MemberInstruction::UnrecognizedWithError { instr, span }) => { - errors.insert( - format!("Member instruction '{}' is not supported.", instr), - *span, - ); + errors.insert(format!("Member instruction '{}' is not supported.", instr), *span); } _ => unreachable!("14"), } } } -fn validate_struct_attrs<'a, I: Iterator>( - attrs: I, - fallible: bool, - errors: &mut HashMap, -) { +fn validate_struct_attrs<'a, I: Iterator>(attrs: I, fallible: bool, errors: &mut HashMap) { let mut unique_ident = HashSet::new(); for attr in attrs { if !unique_ident.insert(&attr.ty) { @@ -437,82 +159,36 @@ fn validate_struct_attrs<'a, I: Iterator>( } if fallible && attr.err_ty.is_none() { - errors.insert( - "Error type should be specified for fallible instruction.".into(), - attr.ty.span, - ); + errors.insert("Error type should be specified for fallible instruction.".into(), attr.ty.span); } if !fallible && attr.err_ty.is_some() { - errors.insert( - "Error type should not be specified for infallible instruction.".into(), - attr.err_ty.as_ref().unwrap().span, - ); + errors.insert("Error type should not be specified for infallible instruction.".into(), attr.err_ty.as_ref().unwrap().span); } } } -fn validate_ghost_attrs( - kind: &Kind, - ghost_attrs: &[GhostsAttr], - type_paths: &HashSet<&TypePath>, - errors: &mut HashMap, -) { - if ghost_attrs - .iter() - .filter(|x| x.applicable_to[kind] && x.attr.container_ty.is_none()) - .count() - > 1 - { - errors.insert( - "There can be at most one default #[ghosts(...)] instruction.".into(), - Span::call_site(), - ); +fn validate_ghost_attrs(kind: &Kind, ghost_attrs: &[GhostsAttr], type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { + if ghost_attrs.iter().filter(|x| x.applicable_to[kind] && x.attr.container_ty.is_none()).count() > 1 { + errors.insert("There can be at most one default #[ghosts(...)] instruction.".into(), Span::call_site()); } let mut unique_dedicated_attr_type_path = HashSet::new(); - for ghost_attr in ghost_attrs - .iter() - .filter(|x| x.applicable_to[kind] && x.attr.container_ty.is_some()) - { + for ghost_attr in ghost_attrs.iter().filter(|x| x.applicable_to[kind] && x.attr.container_ty.is_some()) { let tp = ghost_attr.attr.container_ty.as_ref().unwrap(); if !type_paths.contains(tp) { - errors.insert( - format!( - "Type '{}' doesn't match any type specified in trait instructions.", - tp.path_str - ), - tp.span, - ); + errors.insert(format!("Type '{}' doesn't match any type specified in trait instructions.", tp.path_str), tp.span); } if !unique_dedicated_attr_type_path.insert(tp) { - errors.insert( - format!( - "Dedicated #[ghosts(...)] instruction for type {} is already defined.", - tp.path_str - ), - tp.span, - ); + errors.insert(format!("Dedicated #[ghosts(...)] instruction for type {} is already defined.", tp.path_str), tp.span); } } } -fn validate_children_attrs( - children_attrs: &[ChildrenAttr], - type_paths: &HashSet<&TypePath>, - errors: &mut HashMap, -) { - if children_attrs - .iter() - .filter(|x| x.container_ty.is_none()) - .count() - > 1 - { - errors.insert( - "There can be at most one default #[children(...)] instruction.".into(), - Span::call_site(), - ); +fn validate_children_attrs(children_attrs: &[ChildrenAttr], type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { + if children_attrs.iter().filter(|x| x.container_ty.is_none()).count() > 1 { + errors.insert("There can be at most one default #[children(...)] instruction.".into(), Span::call_site()); } let mut unique_dedicated_attr_type_path = HashSet::new(); @@ -520,22 +196,10 @@ fn validate_children_attrs( for children_attr in children_attrs.iter() { if let Some(tp) = &children_attr.container_ty { if !type_paths.contains(tp) { - errors.insert( - format!( - "Type '{}' doesn't match any type specified in trait instructions.", - tp.path_str - ), - tp.span, - ); + errors.insert(format!("Type '{}' doesn't match any type specified in trait instructions.", tp.path_str), tp.span); } if !unique_dedicated_attr_type_path.insert(tp) { - errors.insert( - format!( - "Dedicated #[children(...)] instruction for type {} is already defined.", - tp.path_str - ), - tp.span, - ); + errors.insert(format!("Dedicated #[children(...)] instruction for type {} is already defined.", tp.path_str), tp.span); } } @@ -543,30 +207,15 @@ fn validate_children_attrs( for child_data in &children_attr.children { if !unique_field.insert(child_data) { - errors.insert( - "Ident here must be unique.".into(), - child_data.field_path.span(), - ); + errors.insert("Ident here must be unique.".into(), child_data.field_path.span()); } } } } -fn validate_where_attrs( - where_attrs: &[WhereAttr], - type_paths: &HashSet<&TypePath>, - errors: &mut HashMap, -) { - if where_attrs - .iter() - .filter(|x| x.container_ty.is_none()) - .count() - > 1 - { - errors.insert( - "There can be at most one default #[where_clause(...)] instruction.".into(), - Span::call_site(), - ); +fn validate_where_attrs(where_attrs: &[WhereAttr], type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { + if where_attrs.iter().filter(|x| x.container_ty.is_none()).count() > 1 { + errors.insert("There can be at most one default #[where_clause(...)] instruction.".into(), Span::call_site()); } let mut unique_dedicated_attr_type_path = HashSet::new(); @@ -574,13 +223,7 @@ fn validate_where_attrs( for where_attr in where_attrs.iter() { if let Some(tp) = &where_attr.container_ty { if !type_paths.contains(tp) { - errors.insert( - format!( - "Type '{}' doesn't match any type specified in trait instructions.", - tp.path_str - ), - tp.span, - ); + errors.insert(format!("Type '{}' doesn't match any type specified in trait instructions.", tp.path_str), tp.span); } if !unique_dedicated_attr_type_path.insert(tp) { errors.insert(format!("Dedicated #[where_clause(...)] instruction for type {} is already defined.", tp.path_str), tp.span); @@ -589,45 +232,16 @@ fn validate_where_attrs( } } -fn bark_at_member_attr Span>( - attrs: &Vec, - instr_name: &'static str, - extract_span: U, - errors: &mut HashMap, -) { +fn bark_at_member_attr Span>(attrs: &Vec, instr_name: &'static str, extract_span: U, errors: &mut HashMap) { for attr in attrs { - errors.insert( - format!( - "Instruction #[{}(...)] is not supported for this member.", - instr_name - ), - extract_span(attr), - ); + errors.insert(format!("Instruction #[{}(...)] is not supported for this member.", instr_name), extract_span(attr)); } } -fn validate_dedicated_member_attrs Option<&TypePath>>( - attrs: &Vec, - extract_type_path: U, - instr_name: Option<&'static str>, - member_span: Span, - type_paths: &HashSet<&TypePath>, - errors: &mut HashMap, -) { +fn validate_dedicated_member_attrs Option<&TypePath>>(attrs: &Vec, extract_type_path: U, instr_name: Option<&'static str>, member_span: Span, type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { if let Some(inst_name) = instr_name { - if attrs - .iter() - .filter(|x| extract_type_path(x).is_none()) - .count() - > 1 - { - errors.insert( - format!( - "There can be at most one default #[{}(...)] instruction for a given member.", - inst_name - ), - member_span, - ); + if attrs.iter().filter(|x| extract_type_path(x).is_none()).count() > 1 { + errors.insert(format!("There can be at most one default #[{}(...)] instruction for a given member.", inst_name), member_span); } } @@ -636,35 +250,18 @@ fn validate_dedicated_member_attrs Option<&TypePath>>( for attr in attrs { if let Some(tp) = extract_type_path(attr) { if !type_paths.contains(tp) { - errors.insert( - format!( - "Type '{}' doesn't match any type specified in trait instructions.", - tp.path_str - ), - tp.span, - ); + errors.insert(format!("Type '{}' doesn't match any type specified in trait instructions.", tp.path_str), tp.span); } if let Some(inst_name) = instr_name { if !unique_dedicated_attr_type_path.insert(tp) { - errors.insert( - format!( - "Dedicated #[{}(...)] instruction for type {} is already defined.", - inst_name, tp.path_str - ), - tp.span, - ); + errors.insert(format!("Dedicated #[{}(...)] instruction for type {} is already defined.", inst_name, tp.path_str), tp.span); } } } } } -fn validate_fields( - input: &Struct, - data_type_attrs: &DataTypeAttrs, - type_paths: &HashSet<&TypePath>, - errors: &mut HashMap, -) { +fn validate_fields(input: &Struct, data_type_attrs: &DataTypeAttrs, type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { let into_type_paths = data_type_attrs .iter_for_kind_core(&Kind::OwnedInto, false) .chain(data_type_attrs.iter_for_kind_core(&Kind::RefInto, false)) @@ -704,11 +301,7 @@ fn validate_fields( if let Some(repeat_attr) = &field.attrs.repeat { if repeat_attr.permeate { - errors.insert( - "Permeating repeat instruction is only applicable to enum variant fields." - .into(), - field.member.span(), - ); + errors.insert("Permeating repeat instruction is only applicable to enum variant fields.".into(), field.member.span()); } } } @@ -717,13 +310,7 @@ fn validate_fields( match &child_attr.container_ty { Some(tp) => { if !type_paths.contains(tp) { - errors.insert( - format!( - "Type '{}' doesn't match any type specified in trait instructions.", - tp.path_str - ), - tp.span, - ); + errors.insert(format!("Type '{}' doesn't match any type specified in trait instructions.", tp.path_str), tp.span); } if into_type_paths.contains(tp) { check_child_errors(child_attr, data_type_attrs, tp, errors) @@ -741,88 +328,45 @@ fn validate_fields( let data_type_attrs: Vec<(&TraitAttrCore, Kind)> = data_type_attrs .iter_for_kind_core(&Kind::OwnedInto, false) .map(|x| (x, Kind::OwnedInto)) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::RefInto, false) - .map(|x| (x, Kind::RefInto)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::OwnedIntoExisting, false) - .map(|x| (x, Kind::OwnedIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::RefIntoExisting, false) - .map(|x| (x, Kind::RefIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::FromOwned, false) - .map(|x| (x, Kind::FromOwned)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::FromRef, false) - .map(|x| (x, Kind::FromRef)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::OwnedInto, true) - .map(|x| (x, Kind::OwnedInto)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::RefInto, true) - .map(|x| (x, Kind::RefInto)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::OwnedIntoExisting, true) - .map(|x| (x, Kind::OwnedIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::RefIntoExisting, true) - .map(|x| (x, Kind::RefIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::FromOwned, true) - .map(|x| (x, Kind::FromOwned)), - ) - .chain( - data_type_attrs - .iter_for_kind_core(&Kind::FromRef, true) - .map(|x| (x, Kind::FromRef)), - ) + .chain(data_type_attrs.iter_for_kind_core(&Kind::RefInto, false).map(|x| (x, Kind::RefInto))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, false).map(|x| (x, Kind::OwnedIntoExisting))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::RefIntoExisting, false).map(|x| (x, Kind::RefIntoExisting))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::FromOwned, false).map(|x| (x, Kind::FromOwned))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::FromRef, false).map(|x| (x, Kind::FromRef))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::OwnedInto, true).map(|x| (x, Kind::OwnedInto))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::RefInto, true).map(|x| (x, Kind::RefInto))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, true).map(|x| (x, Kind::OwnedIntoExisting))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::RefIntoExisting, true).map(|x| (x, Kind::RefIntoExisting))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::FromOwned, true).map(|x| (x, Kind::FromOwned))) + .chain(data_type_attrs.iter_for_kind_core(&Kind::FromRef, true).map(|x| (x, Kind::FromRef))) .collect(); for (data_type_attr, kind) in data_type_attrs { - if data_type_attr.quick_return.is_none() && data_type_attr.type_hint == TypeHint::Struct - { + if data_type_attr.quick_return.is_none() && data_type_attr.type_hint == TypeHint::Struct { for field in &input.fields { - if field.attrs.ghost(&data_type_attr.ty, &kind).is_some() - || field.attrs.has_parent_attr(&data_type_attr.ty) - { + if field.attrs.ghost(&data_type_attr.ty, &kind).is_some() || field.attrs.has_parent_attr(&data_type_attr.ty) { continue; } - if let Some(field_attr) = - field - .attrs - .applicable_field_attr(&kind, false, &data_type_attr.ty) - { + if let Some(field_attr) = field.attrs.applicable_field_attr(&kind, false, &data_type_attr.ty) { if kind == Kind::FromOwned || kind == Kind::FromRef { - if field_attr.attr.member.is_none() && field_attr.attr.action.is_none() - { + if field_attr.attr.member.is_none() && field_attr.attr.action.is_none() { errors.insert(format!("Member trait instruction #[{}(...)] for member {} should specify corresponding field name of the {} or an action", field_attr.original_instr, field.member.to_token_stream(), data_type_attr.ty.path), field.member.span()); } } else if field_attr.attr.member.is_none() { errors.insert(format!("Member trait instruction #[{}(...)] for member {} should specify corresponding field name of the {}", field_attr.original_instr, field.member.to_token_stream(), data_type_attr.ty.path_str), field.member.span()); } } else { - errors.insert(format!("Member {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", field.member.to_token_stream(), if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, FallibleKind(kind, false), data_type_attr.ty.path_str), field.member.span()); + errors.insert( + format!( + "Member {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", + field.member.to_token_stream(), + if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, + FallibleKind(kind, false), + data_type_attr.ty.path_str + ), + field.member.span(), + ); } } } @@ -830,103 +374,51 @@ fn validate_fields( } } -fn validate_variant_fields( - input: &Variant, - data_type_attrs: &DataTypeAttrs, - _type_paths: &HashSet<&TypePath>, - errors: &mut HashMap, -) { +fn validate_variant_fields(input: &Variant, data_type_attrs: &DataTypeAttrs, _type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { if !input.named_fields { let data_type_attrs: Vec<(&TraitAttr, Kind)> = data_type_attrs .iter_for_kind(&Kind::OwnedInto, false) .map(|x| (x, Kind::OwnedInto)) - .chain( - data_type_attrs - .iter_for_kind(&Kind::RefInto, false) - .map(|x| (x, Kind::RefInto)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::OwnedIntoExisting, false) - .map(|x| (x, Kind::OwnedIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::RefIntoExisting, false) - .map(|x| (x, Kind::RefIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::FromOwned, false) - .map(|x| (x, Kind::FromOwned)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::FromRef, false) - .map(|x| (x, Kind::FromRef)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::OwnedInto, true) - .map(|x| (x, Kind::OwnedInto)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::RefInto, true) - .map(|x| (x, Kind::RefInto)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::OwnedIntoExisting, true) - .map(|x| (x, Kind::OwnedIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::RefIntoExisting, true) - .map(|x| (x, Kind::RefIntoExisting)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::FromOwned, true) - .map(|x| (x, Kind::FromOwned)), - ) - .chain( - data_type_attrs - .iter_for_kind(&Kind::FromRef, true) - .map(|x| (x, Kind::FromRef)), - ) + .chain(data_type_attrs.iter_for_kind(&Kind::RefInto, false).map(|x| (x, Kind::RefInto))) + .chain(data_type_attrs.iter_for_kind(&Kind::OwnedIntoExisting, false).map(|x| (x, Kind::OwnedIntoExisting))) + .chain(data_type_attrs.iter_for_kind(&Kind::RefIntoExisting, false).map(|x| (x, Kind::RefIntoExisting))) + .chain(data_type_attrs.iter_for_kind(&Kind::FromOwned, false).map(|x| (x, Kind::FromOwned))) + .chain(data_type_attrs.iter_for_kind(&Kind::FromRef, false).map(|x| (x, Kind::FromRef))) + .chain(data_type_attrs.iter_for_kind(&Kind::OwnedInto, true).map(|x| (x, Kind::OwnedInto))) + .chain(data_type_attrs.iter_for_kind(&Kind::RefInto, true).map(|x| (x, Kind::RefInto))) + .chain(data_type_attrs.iter_for_kind(&Kind::OwnedIntoExisting, true).map(|x| (x, Kind::OwnedIntoExisting))) + .chain(data_type_attrs.iter_for_kind(&Kind::RefIntoExisting, true).map(|x| (x, Kind::RefIntoExisting))) + .chain(data_type_attrs.iter_for_kind(&Kind::FromOwned, true).map(|x| (x, Kind::FromOwned))) + .chain(data_type_attrs.iter_for_kind(&Kind::FromRef, true).map(|x| (x, Kind::FromRef))) .collect(); for (data_type_attr, kind) in data_type_attrs { - if data_type_attr.core.quick_return.is_none() - && input - .attrs - .type_hint(&data_type_attr.core.ty) - .map_or(TypeHint::Unspecified, |x| x.type_hint) - == TypeHint::Struct - { + if data_type_attr.core.quick_return.is_none() && input.attrs.type_hint(&data_type_attr.core.ty).map_or(TypeHint::Unspecified, |x| x.type_hint) == TypeHint::Struct { for field in &input.fields { - if field.attrs.ghost(&data_type_attr.core.ty, &kind).is_some() - || field.attrs.has_parent_attr(&data_type_attr.core.ty) - { + if field.attrs.ghost(&data_type_attr.core.ty, &kind).is_some() || field.attrs.has_parent_attr(&data_type_attr.core.ty) { continue; } - if let Some(field_attr) = - field - .attrs - .applicable_field_attr(&kind, false, &data_type_attr.core.ty) - { + if let Some(field_attr) = field.attrs.applicable_field_attr(&kind, false, &data_type_attr.core.ty) { if kind == Kind::FromOwned || kind == Kind::FromRef { - if field_attr.attr.member.is_none() && field_attr.attr.action.is_none() - { + if field_attr.attr.member.is_none() && field_attr.attr.action.is_none() { errors.insert(format!("Member trait instruction #[{}(...)] for member {} should specify corresponding field name of the {} or an action", field_attr.original_instr, field.member.to_token_stream(), data_type_attr.core.ty.path), field.member.span()); } } else if field_attr.attr.member.is_none() { errors.insert(format!("Member trait instruction #[{}(...)] for member {} should specify corresponding field name of the {}", field_attr.original_instr, field.member.to_token_stream(), data_type_attr.core.ty.path_str), field.member.span()); } } else { - errors.insert(format!("Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", field.member.to_token_stream(), input.ident, if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, FallibleKind(kind, data_type_attr.fallible), data_type_attr.core.ty.path_str), field.member.span()); + errors.insert( + format!( + "Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", + field.member.to_token_stream(), + input.ident, + if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, + FallibleKind(kind, data_type_attr.fallible), + data_type_attr.core.ty.path_str + ), + field.member.span(), + ); } } } @@ -934,32 +426,18 @@ fn validate_variant_fields( } } -fn check_child_errors( - child_attr: &ChildAttr, - struct_attrs: &DataTypeAttrs, - tp: &TypePath, - errors: &mut HashMap, -) { +fn check_child_errors(child_attr: &ChildAttr, struct_attrs: &DataTypeAttrs, tp: &TypePath, errors: &mut HashMap) { let children_attr = struct_attrs.children_attr(tp); for (idx, _level) in child_attr.child_path.child_path.iter().enumerate() { let path = child_attr.get_child_path_str(Some(idx)); match children_attr { Some(children_attr) => { if !children_attr.children.iter().any(|x| x.check_match(path)) { - errors.insert( - format!( - "Missing '{}: [Type Path]' instruction for type {}", - path, tp.path_str - ), - tp.span, - ); + errors.insert(format!("Missing '{}: [Type Path]' instruction for type {}", path, tp.path_str), tp.span); } } None => { - errors.insert( - format!("Missing #[children(...)] instruction for {}", tp.path_str), - tp.span, - ); + errors.insert(format!("Missing #[children(...)] instruction for {}", tp.path_str), tp.span); } } } diff --git a/o2o-macros/src/lib.rs b/o2o-macros/src/lib.rs index bf75432..3269674 100644 --- a/o2o-macros/src/lib.rs +++ b/o2o-macros/src/lib.rs @@ -117,7 +117,5 @@ use syn::{parse_macro_input, DeriveInput}; // (given that all but one are essentially shortcuts and can be avoided with alternative instr syntax) pub fn derive_o2o(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); - derive(&input) - .unwrap_or_else(|err| err.to_compile_error()) - .into() + derive(&input).unwrap_or_else(|err| err.to_compile_error()).into() } diff --git a/o2o-tests/tests/10_multiple_child_attr_tests.rs b/o2o-tests/tests/10_multiple_child_attr_tests.rs index 96d6e0f..bfd2390 100644 --- a/o2o-tests/tests/10_multiple_child_attr_tests.rs +++ b/o2o-tests/tests/10_multiple_child_attr_tests.rs @@ -156,17 +156,8 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -183,17 +174,8 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.into(); @@ -252,17 +234,8 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -279,17 +252,8 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.into(); @@ -332,11 +296,7 @@ fn unnamed2named() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -350,11 +310,7 @@ fn unnamed2unnamed_reverse() { #[test] fn unnamed2named_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.into(); @@ -396,11 +352,7 @@ fn unnamed2named_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -414,11 +366,7 @@ fn unnamed2unnamed_reverse_ref() { #[test] fn unnamed2named_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.into(); diff --git a/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs b/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs index 80f4b24..e6bb785 100644 --- a/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs +++ b/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs @@ -156,17 +156,8 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -183,17 +174,8 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -252,17 +234,8 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -279,17 +252,8 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -332,11 +296,7 @@ fn unnamed2named() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -350,11 +310,7 @@ fn unnamed2unnamed_reverse() { #[test] fn unnamed2named_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.try_into().unwrap(); @@ -396,11 +352,7 @@ fn unnamed2named_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -414,11 +366,7 @@ fn unnamed2unnamed_reverse_ref() { #[test] fn unnamed2named_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.try_into().unwrap(); diff --git a/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests.rs b/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests.rs index ad52da8..28b0dfe 100644 --- a/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests.rs +++ b/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests.rs @@ -107,17 +107,8 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -155,17 +146,8 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -194,14 +176,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -229,14 +204,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); diff --git a/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests_fallible.rs b/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests_fallible.rs index 88a5c0c..89a7d96 100644 --- a/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests_fallible.rs +++ b/o2o-tests/tests/11_child_attr_mixed_struct_kinds_tests_fallible.rs @@ -107,17 +107,8 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -155,17 +146,8 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -194,14 +176,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -229,14 +204,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); diff --git a/o2o-tests/tests/12_ghost_attr_props.rs b/o2o-tests/tests/12_ghost_attr_props.rs index 56c5846..3af732b 100644 --- a/o2o-tests/tests/12_ghost_attr_props.rs +++ b/o2o-tests/tests/12_ghost_attr_props.rs @@ -69,11 +69,7 @@ struct TupleEntityDto( #[test] fn named2named_basic() { - let named2 = Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let named: Entity = named2.into(); @@ -83,11 +79,7 @@ fn named2named_basic() { #[test] fn named2named_ref_basic() { - let named2 = &Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = &Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let named: Entity = named2.into(); @@ -97,10 +89,7 @@ fn named2named_ref_basic() { #[test] fn named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.into(); @@ -113,10 +102,7 @@ fn named2named() { #[test] fn named2named_2() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.into(); @@ -161,10 +147,7 @@ fn named2named_reverse_2() { #[test] fn named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.into(); @@ -177,10 +160,7 @@ fn named2named_ref() { #[test] fn named2named_ref_2() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.into(); @@ -317,11 +297,7 @@ fn unnamed2unnamed_reverse_ref_2() { #[test] fn existing_named2named_basic() { - let named2 = Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let mut named: Entity = Default::default(); named2.into_existing(&mut named); @@ -332,11 +308,7 @@ fn existing_named2named_basic() { #[test] fn existing_named2named_ref_basic() { - let named2 = &Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = &Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let mut named: Entity = Default::default(); named2.into_existing(&mut named); @@ -347,10 +319,7 @@ fn existing_named2named_ref_basic() { #[test] fn existing_named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.into_existing(&mut model); @@ -364,10 +333,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.into_existing(&mut model); diff --git a/o2o-tests/tests/12_ghost_attr_props_fallible.rs b/o2o-tests/tests/12_ghost_attr_props_fallible.rs index 8b488b3..3da77bb 100644 --- a/o2o-tests/tests/12_ghost_attr_props_fallible.rs +++ b/o2o-tests/tests/12_ghost_attr_props_fallible.rs @@ -69,11 +69,7 @@ struct TupleEntityDto( #[test] fn named2named_basic() { - let named2 = Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let named: Entity = named2.try_into().unwrap(); @@ -83,11 +79,7 @@ fn named2named_basic() { #[test] fn named2named_ref_basic() { - let named2 = &Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = &Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let named: Entity = named2.try_into().unwrap(); @@ -97,10 +89,7 @@ fn named2named_ref_basic() { #[test] fn named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.try_into().unwrap(); @@ -113,10 +102,7 @@ fn named2named() { #[test] fn named2named_2() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.try_into().unwrap(); @@ -161,10 +147,7 @@ fn named2named_reverse_2() { #[test] fn named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.try_into().unwrap(); @@ -177,10 +160,7 @@ fn named2named_ref() { #[test] fn named2named_ref_2() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.try_into().unwrap(); @@ -317,11 +297,7 @@ fn unnamed2unnamed_reverse_ref_2() { #[test] fn existing_named2named_basic() { - let named2 = Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let mut named: Entity = Default::default(); named2.try_into_existing(&mut named).unwrap(); @@ -332,11 +308,7 @@ fn existing_named2named_basic() { #[test] fn existing_named2named_ref_basic() { - let named2 = &Entity2 { - some_int: 123, - another_int: 321, - _some_float: 456.0, - }; + let named2 = &Entity2 { some_int: 123, another_int: 321, _some_float: 456.0 }; let mut named: Entity = Default::default(); named2.try_into_existing(&mut named).unwrap(); @@ -347,10 +319,7 @@ fn existing_named2named_ref_basic() { #[test] fn existing_named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.try_into_existing(&mut model).unwrap(); @@ -364,10 +333,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.try_into_existing(&mut model).unwrap(); diff --git a/o2o-tests/tests/13_multiple_ghost_attr_props.rs b/o2o-tests/tests/13_multiple_ghost_attr_props.rs index 0696d08..31c6ceb 100644 --- a/o2o-tests/tests/13_multiple_ghost_attr_props.rs +++ b/o2o-tests/tests/13_multiple_ghost_attr_props.rs @@ -110,10 +110,7 @@ struct TupleEntityDto( #[test] fn named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.into(); @@ -126,10 +123,7 @@ fn named2named() { #[test] fn named2named_2() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.into(); @@ -174,10 +168,7 @@ fn named2named_reverse_2() { #[test] fn named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.into(); @@ -190,10 +181,7 @@ fn named2named_ref() { #[test] fn named2named_ref_2() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.into(); @@ -330,10 +318,7 @@ fn unnamed2unnamed_reverse_ref_2() { #[test] fn named2unnamed() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let dto: TupleEntityDto = named.into(); @@ -346,10 +331,7 @@ fn named2unnamed() { #[test] fn named2unnamed_2() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let model: TupleEntityModel = named.into(); @@ -394,10 +376,7 @@ fn named2unnamed_reverse_2() { #[test] fn named2unnamed_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let dto: TupleEntityDto = named.into(); @@ -410,10 +389,7 @@ fn named2unnamed_ref() { #[test] fn named2unnamed_ref_2() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let model: TupleEntityModel = named.into(); @@ -550,10 +526,7 @@ fn unnamed2named_reverse_ref_2() { #[test] fn existing_named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.into_existing(&mut model); @@ -584,10 +557,7 @@ fn existing_named2named_reverse() { #[test] fn existing_named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.into_existing(&mut model); @@ -668,10 +638,7 @@ fn existing_unnamed2unnamed_reverse_ref() { #[test] fn existing_named2unnamed() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let mut model: TupleEntityModel = Default::default(); named.into_existing(&mut model); @@ -702,10 +669,7 @@ fn existing_named2unnamed_reverse() { #[test] fn existing_named2unnamed_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let mut model: TupleEntityModel = Default::default(); named.into_existing(&mut model); diff --git a/o2o-tests/tests/13_multiple_ghost_attr_props_fallible.rs b/o2o-tests/tests/13_multiple_ghost_attr_props_fallible.rs index 14bc5c6..a8919fa 100644 --- a/o2o-tests/tests/13_multiple_ghost_attr_props_fallible.rs +++ b/o2o-tests/tests/13_multiple_ghost_attr_props_fallible.rs @@ -110,10 +110,7 @@ struct TupleEntityDto( #[test] fn named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.try_into().unwrap(); @@ -126,10 +123,7 @@ fn named2named() { #[test] fn named2named_2() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.try_into().unwrap(); @@ -174,10 +168,7 @@ fn named2named_reverse_2() { #[test] fn named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let dto: EntityDto = named.try_into().unwrap(); @@ -190,10 +181,7 @@ fn named2named_ref() { #[test] fn named2named_ref_2() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let model: EntityModel = named.try_into().unwrap(); @@ -330,10 +318,7 @@ fn unnamed2unnamed_reverse_ref_2() { #[test] fn named2unnamed() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let dto: TupleEntityDto = named.try_into().unwrap(); @@ -346,10 +331,7 @@ fn named2unnamed() { #[test] fn named2unnamed_2() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let model: TupleEntityModel = named.try_into().unwrap(); @@ -394,10 +376,7 @@ fn named2unnamed_reverse_2() { #[test] fn named2unnamed_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let dto: TupleEntityDto = named.try_into().unwrap(); @@ -410,10 +389,7 @@ fn named2unnamed_ref() { #[test] fn named2unnamed_ref_2() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let model: TupleEntityModel = named.try_into().unwrap(); @@ -550,10 +526,7 @@ fn unnamed2named_reverse_ref_2() { #[test] fn existing_named2named() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.try_into_existing(&mut model).unwrap(); @@ -584,10 +557,7 @@ fn existing_named2named_reverse() { #[test] fn existing_named2named_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let mut model: EntityModel = Default::default(); named.try_into_existing(&mut model).unwrap(); @@ -668,10 +638,7 @@ fn existing_unnamed2unnamed_reverse_ref() { #[test] fn existing_named2unnamed() { - let named = Entity { - some_int: 123, - another_int: 321, - }; + let named = Entity { some_int: 123, another_int: 321 }; let mut model: TupleEntityModel = Default::default(); named.try_into_existing(&mut model).unwrap(); @@ -702,10 +669,7 @@ fn existing_named2unnamed_reverse() { #[test] fn existing_named2unnamed_ref() { - let named = &Entity { - some_int: 123, - another_int: 321, - }; + let named = &Entity { some_int: 123, another_int: 321 }; let mut model: TupleEntityModel = Default::default(); named.try_into_existing(&mut model).unwrap(); diff --git a/o2o-tests/tests/14_parent_attr_tests.rs b/o2o-tests/tests/14_parent_attr_tests.rs index 2e9cd9d..b09e403 100644 --- a/o2o-tests/tests/14_parent_attr_tests.rs +++ b/o2o-tests/tests/14_parent_attr_tests.rs @@ -96,17 +96,8 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -144,17 +135,8 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -183,11 +165,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -215,11 +193,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -235,17 +209,8 @@ fn unnamed2unnamed_reverse_ref() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -263,17 +228,8 @@ fn existing_named2named() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -289,11 +245,7 @@ fn existing_named2named_ref() { #[test] fn existing_unnamed2unnamed() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.into_existing(&mut dto); @@ -308,11 +260,7 @@ fn existing_unnamed2unnamed() { #[test] fn existing_unnamed2unnamed_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.into_existing(&mut dto); diff --git a/o2o-tests/tests/14_parent_attr_tests_fallible.rs b/o2o-tests/tests/14_parent_attr_tests_fallible.rs index 11dfafc..cb8b93b 100644 --- a/o2o-tests/tests/14_parent_attr_tests_fallible.rs +++ b/o2o-tests/tests/14_parent_attr_tests_fallible.rs @@ -96,17 +96,8 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -144,17 +135,8 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -183,11 +165,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -215,11 +193,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -235,17 +209,8 @@ fn unnamed2unnamed_reverse_ref() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -263,17 +228,8 @@ fn existing_named2named() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -289,11 +245,7 @@ fn existing_named2named_ref() { #[test] fn existing_unnamed2unnamed() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); @@ -308,11 +260,7 @@ fn existing_unnamed2unnamed() { #[test] fn existing_unnamed2unnamed_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); diff --git a/o2o-tests/tests/15_multiple_parent_attr_tests.rs b/o2o-tests/tests/15_multiple_parent_attr_tests.rs index 426d9f6..2a174f0 100644 --- a/o2o-tests/tests/15_multiple_parent_attr_tests.rs +++ b/o2o-tests/tests/15_multiple_parent_attr_tests.rs @@ -2,13 +2,7 @@ use o2o::o2o; use o2o::traits::IntoExisting; #[derive(o2o)] -#[o2o( - map(EntityDto), - map(TupleEntityDto), - map(EntityModel), - into_existing(EntityDto), - into_existing(TupleEntityDto) -)] +#[o2o(map(EntityDto), map(TupleEntityDto), map(EntityModel), into_existing(EntityDto), into_existing(TupleEntityDto))] struct Entity { #[map(TupleEntityDto| 0)] parent_int: i32, @@ -82,11 +76,7 @@ struct EntityDto { #[map(EntityDto as {})] #[into_existing(TupleEntityDto)] #[into_existing(EntityDto)] -struct TupleEntity( - #[map(EntityDto| parent_int)] i32, - #[parent] TupleBaseEntity, - #[parent] TupleChild, -); +struct TupleEntity(#[map(EntityDto| parent_int)] i32, #[parent] TupleBaseEntity, #[parent] TupleChild); #[derive(o2o)] #[from(TupleEntityDto)] @@ -179,17 +169,8 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -206,17 +187,8 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.into(); @@ -275,17 +247,8 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -302,17 +265,8 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.into(); @@ -355,11 +309,7 @@ fn unnamed2named() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -373,11 +323,7 @@ fn unnamed2unnamed_reverse() { #[test] fn unnamed2named_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.into(); @@ -419,11 +365,7 @@ fn unnamed2named_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -437,11 +379,7 @@ fn unnamed2unnamed_reverse_ref() { #[test] fn unnamed2named_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.into(); @@ -457,17 +395,8 @@ fn unnamed2named_reverse_ref() { fn named2named_2() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let model: EntityModel = entity.into(); @@ -484,50 +413,26 @@ fn named2named_2() { fn named2named_2_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let model: EntityModel = entity.into(); assert_eq!(entity.parent_int, model.parent_int); assert_eq!(entity.base.base.base_int_2, model.base.base.base_int_2); - assert_eq!( - entity.base.base.another_base_int, - model.base.base.another_base_int - ); + assert_eq!(entity.base.base.another_base_int, model.base.base.another_base_int); assert_eq!(entity.base.base_entity_int, model.base.base_entity_int); assert_eq!(entity.child.child_int, model.child.child_int); - assert_eq!( - entity.child.another_child_int, - model.child.another_child_int - ); + assert_eq!(entity.child.another_child_int, model.child.another_child_int); } #[test] fn named2named_2_reverse() { let model = EntityModel { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let entity: Entity = model.into(); @@ -544,50 +449,26 @@ fn named2named_2_reverse() { fn named2named_2_ref_reverse() { let model = &EntityModel { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let entity: Entity = model.into(); assert_eq!(model.parent_int, entity.parent_int); assert_eq!(model.base.base.base_int_2, entity.base.base.base_int_2); - assert_eq!( - model.base.base.another_base_int, - entity.base.base.another_base_int - ); + assert_eq!(model.base.base.another_base_int, entity.base.base.another_base_int); assert_eq!(model.base.base_entity_int, entity.base.base_entity_int); assert_eq!(model.child.child_int, entity.child.child_int); - assert_eq!( - model.child.another_child_int, - entity.child.another_child_int - ); + assert_eq!(model.child.another_child_int, entity.child.another_child_int); } #[test] fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -605,17 +486,8 @@ fn existing_named2named() { fn existing_named2unnamed() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: TupleEntityDto = Default::default(); @@ -633,17 +505,8 @@ fn existing_named2unnamed() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -661,17 +524,8 @@ fn existing_named2named_ref() { fn existing_named2unnamed_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: TupleEntityDto = Default::default(); @@ -687,11 +541,7 @@ fn existing_named2unnamed_ref() { #[test] fn existing_unnamed2unnamed() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.into_existing(&mut dto); @@ -706,11 +556,7 @@ fn existing_unnamed2unnamed() { #[test] fn existing_unnamed2named() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: EntityDto = Default::default(); entity.into_existing(&mut dto); @@ -725,11 +571,7 @@ fn existing_unnamed2named() { #[test] fn existing_unnamed2unnamed_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.into_existing(&mut dto); @@ -744,11 +586,7 @@ fn existing_unnamed2unnamed_ref() { #[test] fn existing_unnamed2named_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: EntityDto = Default::default(); entity.into_existing(&mut dto); diff --git a/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs b/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs index 66346d2..a66f7bb 100644 --- a/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs +++ b/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs @@ -2,13 +2,7 @@ use o2o::o2o; use o2o::traits::TryIntoExisting; #[derive(o2o)] -#[o2o( - try_map(EntityDto, String), - try_map(TupleEntityDto, String), - try_map(EntityModel, String), - try_into_existing(EntityDto, String), - try_into_existing(TupleEntityDto, String) -)] +#[o2o(try_map(EntityDto, String), try_map(TupleEntityDto, String), try_map(EntityModel, String), try_into_existing(EntityDto, String), try_into_existing(TupleEntityDto, String))] struct Entity { #[map(TupleEntityDto| 0)] parent_int: i32, @@ -82,11 +76,7 @@ struct EntityDto { #[try_map(EntityDto as {}, String)] #[try_into_existing(TupleEntityDto, String)] #[try_into_existing(EntityDto, String)] -struct TupleEntity( - #[map(EntityDto| parent_int)] i32, - #[parent] TupleBaseEntity, - #[parent] TupleChild, -); +struct TupleEntity(#[map(EntityDto| parent_int)] i32, #[parent] TupleBaseEntity, #[parent] TupleChild); #[derive(o2o)] #[try_from(TupleEntityDto, String)] @@ -179,17 +169,8 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -206,17 +187,8 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -275,17 +247,8 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -302,17 +265,8 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -355,11 +309,7 @@ fn unnamed2named() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -373,11 +323,7 @@ fn unnamed2unnamed_reverse() { #[test] fn unnamed2named_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.try_into().unwrap(); @@ -419,11 +365,7 @@ fn unnamed2named_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -437,11 +379,7 @@ fn unnamed2unnamed_reverse_ref() { #[test] fn unnamed2named_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: EntityDto = entity.try_into().unwrap(); @@ -457,17 +395,8 @@ fn unnamed2named_reverse_ref() { fn named2named_2() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let model: EntityModel = entity.try_into().unwrap(); @@ -484,50 +413,26 @@ fn named2named_2() { fn named2named_2_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let model: EntityModel = entity.try_into().unwrap(); assert_eq!(entity.parent_int, model.parent_int); assert_eq!(entity.base.base.base_int_2, model.base.base.base_int_2); - assert_eq!( - entity.base.base.another_base_int, - model.base.base.another_base_int - ); + assert_eq!(entity.base.base.another_base_int, model.base.base.another_base_int); assert_eq!(entity.base.base_entity_int, model.base.base_entity_int); assert_eq!(entity.child.child_int, model.child.child_int); - assert_eq!( - entity.child.another_child_int, - model.child.another_child_int - ); + assert_eq!(entity.child.another_child_int, model.child.another_child_int); } #[test] fn named2named_2_reverse() { let model = EntityModel { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let entity: Entity = model.try_into().unwrap(); @@ -544,50 +449,26 @@ fn named2named_2_reverse() { fn named2named_2_ref_reverse() { let model = &EntityModel { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let entity: Entity = model.try_into().unwrap(); assert_eq!(model.parent_int, entity.parent_int); assert_eq!(model.base.base.base_int_2, entity.base.base.base_int_2); - assert_eq!( - model.base.base.another_base_int, - entity.base.base.another_base_int - ); + assert_eq!(model.base.base.another_base_int, entity.base.base.another_base_int); assert_eq!(model.base.base_entity_int, entity.base.base_entity_int); assert_eq!(model.child.child_int, entity.child.child_int); - assert_eq!( - model.child.another_child_int, - entity.child.another_child_int - ); + assert_eq!(model.child.another_child_int, entity.child.another_child_int); } #[test] fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -605,17 +486,8 @@ fn existing_named2named() { fn existing_named2unnamed() { let entity = Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: TupleEntityDto = Default::default(); @@ -633,17 +505,8 @@ fn existing_named2unnamed() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -661,17 +524,8 @@ fn existing_named2named_ref() { fn existing_named2unnamed_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - }, - base_entity_int: 654, - }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: TupleEntityDto = Default::default(); @@ -687,11 +541,7 @@ fn existing_named2unnamed_ref() { #[test] fn existing_unnamed2unnamed() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); @@ -706,11 +556,7 @@ fn existing_unnamed2unnamed() { #[test] fn existing_unnamed2named() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: EntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); @@ -725,11 +571,7 @@ fn existing_unnamed2named() { #[test] fn existing_unnamed2unnamed_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); @@ -744,11 +586,7 @@ fn existing_unnamed2unnamed_ref() { #[test] fn existing_unnamed2named_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let mut dto: EntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); diff --git a/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests.rs b/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests.rs index 9bffdae..02d1fab 100644 --- a/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests.rs +++ b/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests.rs @@ -97,17 +97,8 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -145,17 +136,8 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -184,14 +166,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -219,14 +194,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -242,17 +210,8 @@ fn unnamed2unnamed_reverse_ref() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -270,17 +229,8 @@ fn existing_named2named() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -296,14 +246,7 @@ fn existing_named2named_ref() { #[test] fn existing_unnamed2unnamed() { - let entity = TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.into_existing(&mut dto); @@ -318,14 +261,7 @@ fn existing_unnamed2unnamed() { #[test] fn existing_unnamed2unnamed_ref() { - let entity = &TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.into_existing(&mut dto); diff --git a/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests_fallible.rs b/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests_fallible.rs index 62f4393..04d44c3 100644 --- a/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests_fallible.rs +++ b/o2o-tests/tests/16_parent_attr_mixed_struct_kinds_tests_fallible.rs @@ -97,17 +97,8 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -145,17 +136,8 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -184,14 +166,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -219,14 +194,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -242,17 +210,8 @@ fn unnamed2unnamed_reverse_ref() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -270,17 +229,8 @@ fn existing_named2named() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: TupleBaseEntity( - Base { - base_int_2: 321, - another_base_int: 456, - }, - 654, - ), - child: Child { - child_int: 789, - another_child_int: 987, - }, + base: TupleBaseEntity(Base { base_int_2: 321, another_base_int: 456 }, 654), + child: Child { child_int: 789, another_child_int: 987 }, }; let mut dto: EntityDto = Default::default(); @@ -296,14 +246,7 @@ fn existing_named2named_ref() { #[test] fn existing_unnamed2unnamed() { - let entity = TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); @@ -318,14 +261,7 @@ fn existing_unnamed2unnamed() { #[test] fn existing_unnamed2unnamed_ref() { - let entity = &TupleEntity( - 123, - BaseEntity { - base: TupleBase(321, 456), - base_entity_int: 654, - }, - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, BaseEntity { base: TupleBase(321, 456), base_entity_int: 654 }, TupleChild(789, 987)); let mut dto: TupleEntityDto = Default::default(); entity.try_into_existing(&mut dto).unwrap(); diff --git a/o2o-tests/tests/17_generic_path_tests.rs b/o2o-tests/tests/17_generic_path_tests.rs index 76d4ba9..92bb2a5 100644 --- a/o2o-tests/tests/17_generic_path_tests.rs +++ b/o2o-tests/tests/17_generic_path_tests.rs @@ -55,10 +55,7 @@ struct ChildDto { fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.into(); @@ -69,10 +66,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.into(); @@ -84,13 +78,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.into(); @@ -100,10 +88,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.into(); @@ -117,76 +102,49 @@ fn named2named_different_name_and_type_reverse() { fn named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.into(); assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let model: ParentModel = dto.into(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.into(); assert_eq!(p.parent_int, dto.parent_int); assert_eq!(p.child.child_int, dto.diff_child.child_int); - assert_eq!( - p.child.another_child_int, - dto.diff_child.diff_another_child_int as i16 - ); + assert_eq!(p.child.another_child_int, dto.diff_child.diff_another_child_int as i16); let model = &ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.into(); assert_eq!(model.parent_int, dto.parent_int); assert_eq!(model.child_diff.child_int, dto.diff_child.child_int as i32); - assert_eq!( - model.child_diff.another_child_int, - dto.diff_child.diff_another_child_int as i32 - ); + assert_eq!(model.child_diff.another_child_int, dto.diff_child.diff_another_child_int as i32); } #[test] fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -198,10 +156,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -216,10 +171,7 @@ fn existing_named2named_different_name_and_type() { fn existing_named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -227,18 +179,12 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let mut model: ParentModel = Default::default(); dto.into_existing(&mut model); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } diff --git a/o2o-tests/tests/17_generic_path_tests_fallible.rs b/o2o-tests/tests/17_generic_path_tests_fallible.rs index 5433313..78969aa 100644 --- a/o2o-tests/tests/17_generic_path_tests_fallible.rs +++ b/o2o-tests/tests/17_generic_path_tests_fallible.rs @@ -55,10 +55,7 @@ struct ChildDto { fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.try_into().unwrap(); @@ -69,10 +66,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.try_into().unwrap(); @@ -84,13 +78,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -100,10 +88,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.try_into().unwrap(); @@ -117,76 +102,49 @@ fn named2named_different_name_and_type_reverse() { fn named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.try_into().unwrap(); assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let model: ParentModel = dto.try_into().unwrap(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.try_into().unwrap(); assert_eq!(p.parent_int, dto.parent_int); assert_eq!(p.child.child_int, dto.diff_child.child_int); - assert_eq!( - p.child.another_child_int, - dto.diff_child.diff_another_child_int as i16 - ); + assert_eq!(p.child.another_child_int, dto.diff_child.diff_another_child_int as i16); let model = &ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.try_into().unwrap(); assert_eq!(model.parent_int, dto.parent_int); assert_eq!(model.child_diff.child_int, dto.diff_child.child_int as i32); - assert_eq!( - model.child_diff.another_child_int, - dto.diff_child.diff_another_child_int as i32 - ); + assert_eq!(model.child_diff.another_child_int, dto.diff_child.diff_another_child_int as i32); } #[test] fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -198,10 +156,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -216,10 +171,7 @@ fn existing_named2named_different_name_and_type() { fn existing_named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -227,18 +179,12 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let mut model: ParentModel = Default::default(); dto.try_into_existing(&mut model).unwrap(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } diff --git a/o2o-tests/tests/18_where_attr_tests.rs b/o2o-tests/tests/18_where_attr_tests.rs index ff80207..647182a 100644 --- a/o2o-tests/tests/18_where_attr_tests.rs +++ b/o2o-tests/tests/18_where_attr_tests.rs @@ -59,10 +59,7 @@ where fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent, i32> = dto.into(); @@ -73,10 +70,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.into(); @@ -88,13 +82,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.into(); @@ -104,10 +92,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.into(); @@ -121,76 +106,49 @@ fn named2named_different_name_and_type_reverse() { fn named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent, i32> = dto.into(); assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int); let model: ParentModel = dto.into(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i16 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i16); } #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.into(); assert_eq!(p.parent_int, dto.parent_int); assert_eq!(p.child.child_int, dto.diff_child.child_int); - assert_eq!( - p.child.another_child_int, - dto.diff_child.diff_another_child_int - ); + assert_eq!(p.child.another_child_int, dto.diff_child.diff_another_child_int); let model = &ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.into(); assert_eq!(model.parent_int, dto.parent_int); assert_eq!(model.child_diff.child_int, dto.diff_child.child_int); - assert_eq!( - model.child_diff.another_child_int, - dto.diff_child.diff_another_child_int - ); + assert_eq!(model.child_diff.another_child_int, dto.diff_child.diff_another_child_int); } #[test] fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent, i32> = Default::default(); @@ -202,10 +160,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -220,10 +175,7 @@ fn existing_named2named_different_name_and_type() { fn existing_named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent, i32> = Default::default(); @@ -231,17 +183,11 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int); let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -249,8 +195,5 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int); } diff --git a/o2o-tests/tests/18_where_attr_tests_fallible.rs b/o2o-tests/tests/18_where_attr_tests_fallible.rs index c5e9a89..82d4068 100644 --- a/o2o-tests/tests/18_where_attr_tests_fallible.rs +++ b/o2o-tests/tests/18_where_attr_tests_fallible.rs @@ -59,10 +59,7 @@ where fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent, i32> = dto.try_into().unwrap(); @@ -73,10 +70,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.try_into().unwrap(); @@ -88,13 +82,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -104,10 +92,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.try_into().unwrap(); @@ -121,76 +106,49 @@ fn named2named_different_name_and_type_reverse() { fn named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent, i32> = dto.try_into().unwrap(); assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int); let model: ParentModel = dto.try_into().unwrap(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i16 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i16); } #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.try_into().unwrap(); assert_eq!(p.parent_int, dto.parent_int); assert_eq!(p.child.child_int, dto.diff_child.child_int); - assert_eq!( - p.child.another_child_int, - dto.diff_child.diff_another_child_int - ); + assert_eq!(p.child.another_child_int, dto.diff_child.diff_another_child_int); let model = &ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.try_into().unwrap(); assert_eq!(model.parent_int, dto.parent_int); assert_eq!(model.child_diff.child_int, dto.diff_child.child_int); - assert_eq!( - model.child_diff.another_child_int, - dto.diff_child.diff_another_child_int - ); + assert_eq!(model.child_diff.another_child_int, dto.diff_child.diff_another_child_int); } #[test] fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent, i32> = Default::default(); @@ -202,10 +160,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -220,10 +175,7 @@ fn existing_named2named_different_name_and_type() { fn existing_named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent, i32> = Default::default(); @@ -231,17 +183,11 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int); let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -249,8 +195,5 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int); } diff --git a/o2o-tests/tests/19_deep_ghost_attr_tests.rs b/o2o-tests/tests/19_deep_ghost_attr_tests.rs index 914db94..3fc8f21 100644 --- a/o2o-tests/tests/19_deep_ghost_attr_tests.rs +++ b/o2o-tests/tests/19_deep_ghost_attr_tests.rs @@ -121,11 +121,7 @@ fn named2named() { number_of_doors: 2, vehicle: Vehicle { number_of_seats: 4, - machine: Machine { - id: 123, - brand: "Trabant".into(), - year: 1960, - }, + machine: Machine { id: 123, brand: "Trabant".into(), year: 1960 }, }, }; @@ -139,12 +135,7 @@ fn named2named() { #[test] fn named2named_reverse() { - let car_dto = CarDto { - number_of_doors: 2, - number_of_seats: 4, - brand: "Trabant".into(), - year: 1960, - }; + let car_dto = CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; let car: Car = car_dto.into(); @@ -161,11 +152,7 @@ fn named2named_ref() { number_of_doors: 2, vehicle: Vehicle { number_of_seats: 4, - machine: Machine { - id: 123, - brand: "Trabant".into(), - year: 1960, - }, + machine: Machine { id: 123, brand: "Trabant".into(), year: 1960 }, }, }; @@ -179,12 +166,7 @@ fn named2named_ref() { #[test] fn named2named_reverse_ref() { - let car_dto = &CarDto { - number_of_doors: 2, - number_of_seats: 4, - brand: "Trabant".into(), - year: 1960, - }; + let car_dto = &CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; let car: Car = car_dto.into(); @@ -197,12 +179,7 @@ fn named2named_reverse_ref() { #[test] fn existing_named2named() { - let car_dto = CarDto { - number_of_doors: 2, - number_of_seats: 4, - brand: "Trabant".into(), - year: 1960, - }; + let car_dto = CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; let mut car: Car = Default::default(); car_dto.into_existing(&mut car); @@ -216,12 +193,7 @@ fn existing_named2named() { #[test] fn existing_named2named_reverse() { - let car_dto = &CarDto { - number_of_doors: 2, - number_of_seats: 4, - brand: "Trabant".into(), - year: 1960, - }; + let car_dto = &CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; let mut car: Car = Default::default(); car_dto.into_existing(&mut car); @@ -236,23 +208,12 @@ fn existing_named2named_reverse() { #[test] fn named2named_2() { let team = Team { - base: Base { - id: 123, - name: "Test".into(), - }, + base: Base { id: 123, name: "Test".into() }, division_id: 456, division: Division { - base: Base { - id: 456, - name: "TestDivision".into(), - }, + base: Base { id: 456, name: "TestDivision".into() }, league_id: 789, - league: League { - base: Base { - id: 789, - name: "TestLeague".into(), - }, - }, + league: League { base: Base { id: 789, name: "TestLeague".into() } }, }, }; @@ -271,14 +232,8 @@ fn named2named_reverse_2() { let team_dto = TeamDto { id: 123, name: "Test".into(), - division: DivisionDto { - id: 456, - name: "TestDivision".into(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".into(), - }, + division: DivisionDto { id: 456, name: "TestDivision".into() }, + league: LeagueDto { id: 789, name: "TestLeague".into() }, }; let team: Team = team_dto.into(); @@ -296,23 +251,12 @@ fn named2named_reverse_2() { #[test] fn named2named_ref_2() { let team = &Team { - base: Base { - id: 123, - name: "Test".into(), - }, + base: Base { id: 123, name: "Test".into() }, division_id: 456, division: Division { - base: Base { - id: 456, - name: "TestDivision".into(), - }, + base: Base { id: 456, name: "TestDivision".into() }, league_id: 789, - league: League { - base: Base { - id: 789, - name: "TestLeague".into(), - }, - }, + league: League { base: Base { id: 789, name: "TestLeague".into() } }, }, }; @@ -333,14 +277,8 @@ fn named2named_ref_reverse_2() { let team_dto = &TeamDto { id: 123, name: "Test".into(), - division: DivisionDto { - id: 456, - name: "TestDivision".into(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".into(), - }, + division: DivisionDto { id: 456, name: "TestDivision".into() }, + league: LeagueDto { id: 789, name: "TestLeague".into() }, }; let team: Team = team_dto.into(); @@ -360,14 +298,8 @@ fn existing_named2named_2() { let team_dto = TeamDto { id: 123, name: "Test".into(), - division: DivisionDto { - id: 456, - name: "TestDivision".into(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".into(), - }, + division: DivisionDto { id: 456, name: "TestDivision".into() }, + league: LeagueDto { id: 789, name: "TestLeague".into() }, }; let mut team: Team = Default::default(); @@ -388,14 +320,8 @@ fn existing_named2named_ref_2() { let team_dto = &TeamDto { id: 123, name: "Test".into(), - division: DivisionDto { - id: 456, - name: "TestDivision".into(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".into(), - }, + division: DivisionDto { id: 456, name: "TestDivision".into() }, + league: LeagueDto { id: 789, name: "TestLeague".into() }, }; let mut team: Team = Default::default(); diff --git a/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs b/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs index 7d9caad..0225d79 100644 --- a/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs +++ b/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs @@ -121,11 +121,7 @@ fn named2named() { number_of_doors: 2, vehicle: Vehicle { number_of_seats: 4, - machine: Machine { - id: 123, - brand: "Trabant".try_into().unwrap(), - year: 1960, - }, + machine: Machine { id: 123, brand: "Trabant".try_into().unwrap(), year: 1960 }, }, }; @@ -161,11 +157,7 @@ fn named2named_ref() { number_of_doors: 2, vehicle: Vehicle { number_of_seats: 4, - machine: Machine { - id: 123, - brand: "Trabant".try_into().unwrap(), - year: 1960, - }, + machine: Machine { id: 123, brand: "Trabant".try_into().unwrap(), year: 1960 }, }, }; @@ -236,23 +228,12 @@ fn existing_named2named_reverse() { #[test] fn named2named_2() { let team = Team { - base: Base { - id: 123, - name: "Test".try_into().unwrap(), - }, + base: Base { id: 123, name: "Test".try_into().unwrap() }, division_id: 456, division: Division { - base: Base { - id: 456, - name: "TestDivision".try_into().unwrap(), - }, + base: Base { id: 456, name: "TestDivision".try_into().unwrap() }, league_id: 789, - league: League { - base: Base { - id: 789, - name: "TestLeague".try_into().unwrap(), - }, - }, + league: League { base: Base { id: 789, name: "TestLeague".try_into().unwrap() } }, }, }; @@ -271,14 +252,8 @@ fn named2named_reverse_2() { let team_dto = TeamDto { id: 123, name: "Test".try_into().unwrap(), - division: DivisionDto { - id: 456, - name: "TestDivision".try_into().unwrap(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".try_into().unwrap(), - }, + division: DivisionDto { id: 456, name: "TestDivision".try_into().unwrap() }, + league: LeagueDto { id: 789, name: "TestLeague".try_into().unwrap() }, }; let team: Team = team_dto.try_into().unwrap(); @@ -296,23 +271,12 @@ fn named2named_reverse_2() { #[test] fn named2named_ref_2() { let team = &Team { - base: Base { - id: 123, - name: "Test".try_into().unwrap(), - }, + base: Base { id: 123, name: "Test".try_into().unwrap() }, division_id: 456, division: Division { - base: Base { - id: 456, - name: "TestDivision".try_into().unwrap(), - }, + base: Base { id: 456, name: "TestDivision".try_into().unwrap() }, league_id: 789, - league: League { - base: Base { - id: 789, - name: "TestLeague".try_into().unwrap(), - }, - }, + league: League { base: Base { id: 789, name: "TestLeague".try_into().unwrap() } }, }, }; @@ -333,14 +297,8 @@ fn named2named_ref_reverse_2() { let team_dto = &TeamDto { id: 123, name: "Test".try_into().unwrap(), - division: DivisionDto { - id: 456, - name: "TestDivision".try_into().unwrap(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".try_into().unwrap(), - }, + division: DivisionDto { id: 456, name: "TestDivision".try_into().unwrap() }, + league: LeagueDto { id: 789, name: "TestLeague".try_into().unwrap() }, }; let team: Team = team_dto.try_into().unwrap(); @@ -360,14 +318,8 @@ fn existing_named2named_2() { let team_dto = TeamDto { id: 123, name: "Test".try_into().unwrap(), - division: DivisionDto { - id: 456, - name: "TestDivision".try_into().unwrap(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".try_into().unwrap(), - }, + division: DivisionDto { id: 456, name: "TestDivision".try_into().unwrap() }, + league: LeagueDto { id: 789, name: "TestLeague".try_into().unwrap() }, }; let mut team: Team = Default::default(); @@ -388,14 +340,8 @@ fn existing_named2named_ref_2() { let team_dto = &TeamDto { id: 123, name: "Test".try_into().unwrap(), - division: DivisionDto { - id: 456, - name: "TestDivision".try_into().unwrap(), - }, - league: LeagueDto { - id: 789, - name: "TestLeague".try_into().unwrap(), - }, + division: DivisionDto { id: 456, name: "TestDivision".try_into().unwrap() }, + league: LeagueDto { id: 789, name: "TestLeague".try_into().unwrap() }, }; let mut team: Team = Default::default(); diff --git a/o2o-tests/tests/1_bare_top_level_attr_tests.rs b/o2o-tests/tests/1_bare_top_level_attr_tests.rs index 75b05a0..4d8231d 100644 --- a/o2o-tests/tests/1_bare_top_level_attr_tests.rs +++ b/o2o-tests/tests/1_bare_top_level_attr_tests.rs @@ -39,20 +39,14 @@ struct UnnamedStructDto(i32, i32); #[test] fn named2named() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let named: NamedStruct = dto.into(); assert_eq!(123, named.some_int); assert_eq!(321, named.another_int); - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let model: NamedStructModel = dto.into(); @@ -62,20 +56,14 @@ fn named2named() { #[test] fn named2named_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - }; + let named = NamedStruct { some_int: 123, another_int: 321 }; let dto: NamedStructDto = named.into(); assert_eq!(123, dto.some_int); assert_eq!(321, dto.another_int); - let model = NamedStructModel { - some_int: 123, - another_int: 321, - }; + let model = NamedStructModel { some_int: 123, another_int: 321 }; let dto: NamedStructDto = model.into(); @@ -85,10 +73,7 @@ fn named2named_reverse() { #[test] fn named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 321 }; let named: NamedStruct = dto.into(); @@ -103,20 +88,14 @@ fn named2named_ref() { #[test] fn named2named_ref_reversed() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - }; + let named = &NamedStruct { some_int: 123, another_int: 321 }; let dto: NamedStructDto = named.into(); assert_eq!(named.some_int, dto.some_int); assert_eq!(named.another_int, dto.another_int); - let model = &NamedStructModel { - some_int: 123, - another_int: 321, - }; + let model = &NamedStructModel { some_int: 123, another_int: 321 }; let dto: NamedStructDto = model.into(); @@ -192,10 +171,7 @@ fn unnamed2unnamed_ref_reversed() { #[test] fn existing_named2named() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); @@ -203,10 +179,7 @@ fn existing_named2named() { assert_eq!(123, named.some_int); assert_eq!(321, named.another_int); - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let mut model: NamedStructModel = Default::default(); dto.into_existing(&mut model); @@ -217,10 +190,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 321 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); @@ -228,10 +198,7 @@ fn existing_named2named_ref() { assert_eq!(dto.some_int, named.some_int); assert_eq!(dto.another_int, named.another_int); - let dto = &NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 321 }; let mut model: NamedStructModel = Default::default(); dto.into_existing(&mut model); diff --git a/o2o-tests/tests/1_bare_top_level_attr_tests_fallible.rs b/o2o-tests/tests/1_bare_top_level_attr_tests_fallible.rs index fcc2a4e..edc7c19 100644 --- a/o2o-tests/tests/1_bare_top_level_attr_tests_fallible.rs +++ b/o2o-tests/tests/1_bare_top_level_attr_tests_fallible.rs @@ -41,20 +41,14 @@ struct UnnamedStructDto(i32, i32); #[test] fn named2named() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let named: NamedStruct = dto.try_into().unwrap(); assert_eq!(123, named.some_int); assert_eq!(321, named.another_int); - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let model: NamedStructModel = dto.try_into().unwrap(); @@ -64,20 +58,14 @@ fn named2named() { #[test] fn named2named_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - }; + let named = NamedStruct { some_int: 123, another_int: 321 }; let dto: NamedStructDto = named.try_into().unwrap(); assert_eq!(123, dto.some_int); assert_eq!(321, dto.another_int); - let model = NamedStructModel { - some_int: 123, - another_int: 321, - }; + let model = NamedStructModel { some_int: 123, another_int: 321 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -87,10 +75,7 @@ fn named2named_reverse() { #[test] fn named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 321 }; let named: NamedStruct = dto.try_into().unwrap(); @@ -105,20 +90,14 @@ fn named2named_ref() { #[test] fn named2named_ref_reversed() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - }; + let named = &NamedStruct { some_int: 123, another_int: 321 }; let dto: NamedStructDto = named.try_into().unwrap(); assert_eq!(named.some_int, dto.some_int); assert_eq!(named.another_int, dto.another_int); - let model = &NamedStructModel { - some_int: 123, - another_int: 321, - }; + let model = &NamedStructModel { some_int: 123, another_int: 321 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -194,10 +173,7 @@ fn unnamed2unnamed_ref_reversed() { #[test] fn existing_named2named() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); @@ -205,10 +181,7 @@ fn existing_named2named() { assert_eq!(123, named.some_int); assert_eq!(321, named.another_int); - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321 }; let mut model: NamedStructModel = Default::default(); dto.try_into_existing(&mut model).unwrap(); @@ -219,10 +192,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 321 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); @@ -230,10 +200,7 @@ fn existing_named2named_ref() { assert_eq!(dto.some_int, named.some_int); assert_eq!(dto.another_int, named.another_int); - let dto = &NamedStructDto { - some_int: 123, - another_int: 321, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 321 }; let mut model: NamedStructModel = Default::default(); dto.try_into_existing(&mut model).unwrap(); diff --git a/o2o-tests/tests/20_as_type_attr_tests.rs b/o2o-tests/tests/20_as_type_attr_tests.rs index 99d62c3..15807e8 100644 --- a/o2o-tests/tests/20_as_type_attr_tests.rs +++ b/o2o-tests/tests/20_as_type_attr_tests.rs @@ -68,12 +68,7 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - another_float: 654.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = named.into(); @@ -81,12 +76,7 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.different_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { - some_int: 123, - different_int: 127, - some_float: 456.0, - another_float: 654.0, - }; + let model = NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = model.into(); @@ -122,12 +112,7 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - another_float: 654.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = named.into(); @@ -136,12 +121,7 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.some_float, dto.some_float as f32); assert_eq!(named.another_float, dto.different_float as f64); - let model = &NamedStructModel { - some_int: 123, - different_int: 127, - some_float: 456.0, - another_float: 654.0, - }; + let model = &NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = model.into(); diff --git a/o2o-tests/tests/20_as_type_attr_tests_fallible.rs b/o2o-tests/tests/20_as_type_attr_tests_fallible.rs index 6921eec..5213b0c 100644 --- a/o2o-tests/tests/20_as_type_attr_tests_fallible.rs +++ b/o2o-tests/tests/20_as_type_attr_tests_fallible.rs @@ -68,12 +68,7 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - another_float: 654.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -81,12 +76,7 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.different_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { - some_int: 123, - different_int: 127, - some_float: 456.0, - another_float: 654.0, - }; + let model = NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -122,12 +112,7 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - another_float: 654.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -136,12 +121,7 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.some_float, dto.some_float as f32); assert_eq!(named.another_float, dto.different_float as f64); - let model = &NamedStructModel { - some_int: 123, - different_int: 127, - some_float: 456.0, - another_float: 654.0, - }; + let model = &NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; let dto: NamedStructDto = model.try_into().unwrap(); diff --git a/o2o-tests/tests/22_nameless_tuple_tests.rs b/o2o-tests/tests/22_nameless_tuple_tests.rs index 97df45e..d97b96a 100644 --- a/o2o-tests/tests/22_nameless_tuple_tests.rs +++ b/o2o-tests/tests/22_nameless_tuple_tests.rs @@ -14,10 +14,7 @@ pub struct Entity { #[test] fn named2nameless() { - let entity = Entity { - int: 123, - string: "Test".into(), - }; + let entity = Entity { int: 123, string: "Test".into() }; let (int, string) = entity.into(); @@ -27,10 +24,7 @@ fn named2nameless() { #[test] fn named2nameless_ref() { - let entity = &Entity { - int: 123, - string: "Test".into(), - }; + let entity = &Entity { int: 123, string: "Test".into() }; let (int, string) = entity.into(); @@ -60,10 +54,7 @@ fn named2nameless_reverse_ref() { #[test] fn existing_named2nameless() { - let entity = Entity { - int: 123, - string: "Test".into(), - }; + let entity = Entity { int: 123, string: "Test".into() }; let mut tpl = <(i32, String)>::default(); entity.into_existing(&mut tpl); @@ -74,10 +65,7 @@ fn existing_named2nameless() { #[test] fn existing_named2nameless_ref() { - let entity = &Entity { - int: 123, - string: "Test".into(), - }; + let entity = &Entity { int: 123, string: "Test".into() }; let mut tpl = <(i32, String)>::default(); entity.into_existing(&mut tpl); diff --git a/o2o-tests/tests/22_nameless_tuple_tests_fallible.rs b/o2o-tests/tests/22_nameless_tuple_tests_fallible.rs index 5d99161..3fa77b2 100644 --- a/o2o-tests/tests/22_nameless_tuple_tests_fallible.rs +++ b/o2o-tests/tests/22_nameless_tuple_tests_fallible.rs @@ -14,10 +14,7 @@ pub struct Entity { #[test] fn named2nameless() { - let entity = Entity { - int: 123, - string: "Test".try_into().unwrap(), - }; + let entity = Entity { int: 123, string: "Test".try_into().unwrap() }; let (int, string) = entity.try_into().unwrap(); @@ -27,10 +24,7 @@ fn named2nameless() { #[test] fn named2nameless_ref() { - let entity = &Entity { - int: 123, - string: "Test".try_into().unwrap(), - }; + let entity = &Entity { int: 123, string: "Test".try_into().unwrap() }; let (int, string) = entity.try_into().unwrap(); @@ -60,10 +54,7 @@ fn named2nameless_reverse_ref() { #[test] fn existing_named2nameless() { - let entity = Entity { - int: 123, - string: "Test".try_into().unwrap(), - }; + let entity = Entity { int: 123, string: "Test".try_into().unwrap() }; let mut tpl = <(i32, String)>::default(); entity.try_into_existing(&mut tpl).unwrap(); @@ -74,10 +65,7 @@ fn existing_named2nameless() { #[test] fn existing_named2nameless_ref() { - let entity = &Entity { - int: 123, - string: "Test".try_into().unwrap(), - }; + let entity = &Entity { int: 123, string: "Test".try_into().unwrap() }; let mut tpl = <(i32, String)>::default(); entity.try_into_existing(&mut tpl).unwrap(); diff --git a/o2o-tests/tests/23_pre_init_tests.rs b/o2o-tests/tests/23_pre_init_tests.rs index dcf0ec8..f5276b3 100644 --- a/o2o-tests/tests/23_pre_init_tests.rs +++ b/o2o-tests/tests/23_pre_init_tests.rs @@ -22,11 +22,7 @@ struct PersonDto { #[test] fn named2named() { - let person = Person { - age: 42, - first_name: "Dohn".into(), - last_name: "Joe".into(), - }; + let person = Person { age: 42, first_name: "Dohn".into(), last_name: "Joe".into() }; let dto: PersonDto = person.into(); @@ -36,27 +32,17 @@ fn named2named() { #[test] fn named2named_ref() { - let person = &Person { - age: 42, - first_name: "Dohn".into(), - last_name: "Joe".into(), - }; + let person = &Person { age: 42, first_name: "Dohn".into(), last_name: "Joe".into() }; let dto: PersonDto = person.into(); assert_eq!(person.age, dto.age); - assert_eq!( - format!("{} {}", person.first_name, person.last_name), - dto.full_name - ); + assert_eq!(format!("{} {}", person.first_name, person.last_name), dto.full_name); } #[test] fn named2named_reverse() { - let dto = PersonDto { - age: 42, - full_name: "Test".into(), - }; + let dto = PersonDto { age: 42, full_name: "Test".into() }; let person: Person = dto.into(); @@ -67,10 +53,7 @@ fn named2named_reverse() { #[test] fn named2named_reverse_ref() { - let dto = &PersonDto { - age: 42, - full_name: "Test".into(), - }; + let dto = &PersonDto { age: 42, full_name: "Test".into() }; let person: Person = dto.into(); @@ -81,10 +64,7 @@ fn named2named_reverse_ref() { #[test] fn existing_named2named() { - let dto = PersonDto { - age: 42, - full_name: "Test".into(), - }; + let dto = PersonDto { age: 42, full_name: "Test".into() }; let mut person: Person = Default::default(); dto.into_existing(&mut person); @@ -96,10 +76,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let dto = &PersonDto { - age: 42, - full_name: "Test".into(), - }; + let dto = &PersonDto { age: 42, full_name: "Test".into() }; let mut person: Person = Default::default(); dto.into_existing(&mut person); diff --git a/o2o-tests/tests/23_pre_init_tests_fallible.rs b/o2o-tests/tests/23_pre_init_tests_fallible.rs index 9123b4a..6c9bb95 100644 --- a/o2o-tests/tests/23_pre_init_tests_fallible.rs +++ b/o2o-tests/tests/23_pre_init_tests_fallible.rs @@ -45,18 +45,12 @@ fn named2named_ref() { let dto: PersonDto = person.try_into().unwrap(); assert_eq!(person.age, dto.age); - assert_eq!( - format!("{} {}", person.first_name, person.last_name), - dto.full_name - ); + assert_eq!(format!("{} {}", person.first_name, person.last_name), dto.full_name); } #[test] fn named2named_reverse() { - let dto = PersonDto { - age: 42, - full_name: "Test".try_into().unwrap(), - }; + let dto = PersonDto { age: 42, full_name: "Test".try_into().unwrap() }; let person: Person = dto.try_into().unwrap(); @@ -67,10 +61,7 @@ fn named2named_reverse() { #[test] fn named2named_reverse_ref() { - let dto = &PersonDto { - age: 42, - full_name: "Test".try_into().unwrap(), - }; + let dto = &PersonDto { age: 42, full_name: "Test".try_into().unwrap() }; let person: Person = dto.try_into().unwrap(); @@ -81,10 +72,7 @@ fn named2named_reverse_ref() { #[test] fn existing_named2named() { - let dto = PersonDto { - age: 42, - full_name: "Test".try_into().unwrap(), - }; + let dto = PersonDto { age: 42, full_name: "Test".try_into().unwrap() }; let mut person: Person = Default::default(); dto.try_into_existing(&mut person).unwrap(); @@ -96,10 +84,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let dto = &PersonDto { - age: 42, - full_name: "Test".try_into().unwrap(), - }; + let dto = &PersonDto { age: 42, full_name: "Test".try_into().unwrap() }; let mut person: Person = Default::default(); dto.try_into_existing(&mut person).unwrap(); diff --git a/o2o-tests/tests/24_quick_return_tests.rs b/o2o-tests/tests/24_quick_return_tests.rs index 6c14567..a5df820 100644 --- a/o2o-tests/tests/24_quick_return_tests.rs +++ b/o2o-tests/tests/24_quick_return_tests.rs @@ -21,11 +21,7 @@ struct TotalTime { #[test] fn time2i() { - let time = Time { - hours: 2, - minutes: 10, - seconds: 15, - }; + let time = Time { hours: 2, minutes: 10, seconds: 15 }; let i: i32 = time.into(); @@ -34,11 +30,7 @@ fn time2i() { #[test] fn named2named() { - let time = Time { - hours: 2, - minutes: 10, - seconds: 15, - }; + let time = Time { hours: 2, minutes: 10, seconds: 15 }; let total: TotalTime = time.into(); @@ -47,11 +39,7 @@ fn named2named() { #[test] fn named2named_ref() { - let time = &Time { - hours: 2, - minutes: 10, - seconds: 15, - }; + let time = &Time { hours: 2, minutes: 10, seconds: 15 }; let total: TotalTime = time.into(); diff --git a/o2o-tests/tests/24_quick_return_tests_fallible.rs b/o2o-tests/tests/24_quick_return_tests_fallible.rs index 737bb07..81941f8 100644 --- a/o2o-tests/tests/24_quick_return_tests_fallible.rs +++ b/o2o-tests/tests/24_quick_return_tests_fallible.rs @@ -21,11 +21,7 @@ struct TotalTime { #[test] fn time2i() { - let time = Time { - hours: 2, - minutes: 10, - seconds: 15, - }; + let time = Time { hours: 2, minutes: 10, seconds: 15 }; let i: i32 = time.try_into().unwrap(); @@ -34,11 +30,7 @@ fn time2i() { #[test] fn named2named() { - let time = Time { - hours: 2, - minutes: 10, - seconds: 15, - }; + let time = Time { hours: 2, minutes: 10, seconds: 15 }; let total: TotalTime = time.try_into().unwrap(); @@ -47,11 +39,7 @@ fn named2named() { #[test] fn named2named_ref() { - let time = &Time { - hours: 2, - minutes: 10, - seconds: 15, - }; + let time = &Time { hours: 2, minutes: 10, seconds: 15 }; let total: TotalTime = time.try_into().unwrap(); diff --git a/o2o-tests/tests/25_update_struct_tests.rs b/o2o-tests/tests/25_update_struct_tests.rs index 87b19e7..0cc8a3e 100644 --- a/o2o-tests/tests/25_update_struct_tests.rs +++ b/o2o-tests/tests/25_update_struct_tests.rs @@ -7,10 +7,7 @@ struct Entity { impl Default for Entity { fn default() -> Self { - Self { - some_int: 0, - some_float: 321.0, - } + Self { some_int: 0, some_float: 321.0 } } } @@ -24,18 +21,12 @@ struct EntityDto { } fn get_default() -> EntityDto { - EntityDto { - some_int: 0, - some_string: "test".into(), - } + EntityDto { some_int: 0, some_string: "test".into() } } #[test] fn named2named() { - let dto = EntityDto { - some_int: 123, - some_string: "321".into(), - }; + let dto = EntityDto { some_int: 123, some_string: "321".into() }; let entity: Entity = dto.into(); @@ -45,10 +36,7 @@ fn named2named() { #[test] fn named2named_reverse() { - let entity = Entity { - some_int: 123, - some_float: 654.0, - }; + let entity = Entity { some_int: 123, some_float: 654.0 }; let dto: EntityDto = entity.into(); @@ -58,10 +46,7 @@ fn named2named_reverse() { #[test] fn named2named_ref() { - let dto = &EntityDto { - some_int: 123, - some_string: "321".into(), - }; + let dto = &EntityDto { some_int: 123, some_string: "321".into() }; let entity: Entity = dto.into(); @@ -71,10 +56,7 @@ fn named2named_ref() { #[test] fn named2named_ref_reverse() { - let entity = &Entity { - some_int: 123, - some_float: 654.0, - }; + let entity = &Entity { some_int: 123, some_float: 654.0 }; let dto: EntityDto = entity.into(); diff --git a/o2o-tests/tests/25_update_struct_tests_fallible.rs b/o2o-tests/tests/25_update_struct_tests_fallible.rs index 9c4ae04..4b48f22 100644 --- a/o2o-tests/tests/25_update_struct_tests_fallible.rs +++ b/o2o-tests/tests/25_update_struct_tests_fallible.rs @@ -7,10 +7,7 @@ struct Entity { impl Default for Entity { fn default() -> Self { - Self { - some_int: 0, - some_float: 321.0, - } + Self { some_int: 0, some_float: 321.0 } } } @@ -24,18 +21,12 @@ struct EntityDto { } fn get_default() -> EntityDto { - EntityDto { - some_int: 0, - some_string: "test".try_into().unwrap(), - } + EntityDto { some_int: 0, some_string: "test".try_into().unwrap() } } #[test] fn named2named() { - let dto = EntityDto { - some_int: 123, - some_string: "321".try_into().unwrap(), - }; + let dto = EntityDto { some_int: 123, some_string: "321".try_into().unwrap() }; let entity: Entity = dto.try_into().unwrap(); @@ -45,10 +36,7 @@ fn named2named() { #[test] fn named2named_reverse() { - let entity = Entity { - some_int: 123, - some_float: 654.0, - }; + let entity = Entity { some_int: 123, some_float: 654.0 }; let dto: EntityDto = entity.try_into().unwrap(); @@ -58,10 +46,7 @@ fn named2named_reverse() { #[test] fn named2named_ref() { - let dto = &EntityDto { - some_int: 123, - some_string: "321".try_into().unwrap(), - }; + let dto = &EntityDto { some_int: 123, some_string: "321".try_into().unwrap() }; let entity: Entity = dto.try_into().unwrap(); @@ -71,10 +56,7 @@ fn named2named_ref() { #[test] fn named2named_ref_reverse() { - let entity = &Entity { - some_int: 123, - some_float: 654.0, - }; + let entity = &Entity { some_int: 123, some_float: 654.0 }; let dto: EntityDto = entity.try_into().unwrap(); diff --git a/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests.rs b/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests.rs index 0b15f7d..fe07801 100644 --- a/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests.rs +++ b/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests.rs @@ -249,14 +249,7 @@ fn existing_named2named_ref() { #[test] fn unnamed2named() { - let dto = UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let entity: Entity = dto.into(); @@ -291,14 +284,7 @@ fn unnamed2named_reverse() { #[test] fn unnamed2named_ref() { - let dto = &UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = &UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let entity: Entity = dto.into(); @@ -333,14 +319,7 @@ fn unnamed2named_ref_reverse() { #[test] fn existing_unnamed2named() { - let dto = UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let mut entity: Entity = Default::default(); dto.into_existing(&mut entity); @@ -355,14 +334,7 @@ fn existing_unnamed2named() { #[test] fn existing_unnamed2named_ref() { - let dto = &UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = &UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let mut entity: Entity = Default::default(); dto.into_existing(&mut entity); diff --git a/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests_fallible.rs b/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests_fallible.rs index d9a7f49..1a2cda6 100644 --- a/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests_fallible.rs +++ b/o2o-tests/tests/26_at_and_tilde_inside_inline_expr_tests_fallible.rs @@ -249,14 +249,7 @@ fn existing_named2named_ref() { #[test] fn unnamed2named() { - let dto = UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let entity: Entity = dto.try_into().unwrap(); @@ -291,14 +284,7 @@ fn unnamed2named_reverse() { #[test] fn unnamed2named_ref() { - let dto = &UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = &UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let entity: Entity = dto.try_into().unwrap(); @@ -333,14 +319,7 @@ fn unnamed2named_ref_reverse() { #[test] fn existing_unnamed2named() { - let dto = UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let mut entity: Entity = Default::default(); dto.try_into_existing(&mut entity).unwrap(); @@ -355,14 +334,7 @@ fn existing_unnamed2named() { #[test] fn existing_unnamed2named_ref() { - let dto = &UnnamedEntityDto( - 123, - "456".into(), - "789".into(), - "987".into(), - "654".into(), - "321".into(), - ); + let dto = &UnnamedEntityDto(123, "456".into(), "789".into(), "987".into(), "654".into(), "321".into()); let mut entity: Entity = Default::default(); dto.try_into_existing(&mut entity).unwrap(); diff --git a/o2o-tests/tests/27_enum_bare_top_level_attr_tests.rs b/o2o-tests/tests/27_enum_bare_top_level_attr_tests.rs index c192445..5367e72 100644 --- a/o2o-tests/tests/27_enum_bare_top_level_attr_tests.rs +++ b/o2o-tests/tests/27_enum_bare_top_level_attr_tests.rs @@ -46,20 +46,8 @@ fn enum2enum() { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1(123, 321), - EnumWithData::Item1(123, 321), - ), - ( - EnumWithDataDto::Item2 { - str: "Test".into(), - i: 654, - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1(123, 321), EnumWithData::Item1(123, 321)), + (EnumWithDataDto::Item2 { str: "Test".into(), i: 654 }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().into(); assert!(en == data.1); diff --git a/o2o-tests/tests/27_enum_bare_top_level_attr_tests_fallible.rs b/o2o-tests/tests/27_enum_bare_top_level_attr_tests_fallible.rs index e8b9fb0..5af1e76 100644 --- a/o2o-tests/tests/27_enum_bare_top_level_attr_tests_fallible.rs +++ b/o2o-tests/tests/27_enum_bare_top_level_attr_tests_fallible.rs @@ -46,20 +46,8 @@ fn enum2enum() { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1(123, 321), - EnumWithData::Item1(123, 321), - ), - ( - EnumWithDataDto::Item2 { - str: "Test".into(), - i: 654, - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1(123, 321), EnumWithData::Item1(123, 321)), + (EnumWithDataDto::Item2 { str: "Test".into(), i: 654 }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().try_into().unwrap(); assert!(en == data.1); diff --git a/o2o-tests/tests/28_enum_member_level_ident_only_tests.rs b/o2o-tests/tests/28_enum_member_level_ident_only_tests.rs index 0eb4cdc..a807fd1 100644 --- a/o2o-tests/tests/28_enum_member_level_ident_only_tests.rs +++ b/o2o-tests/tests/28_enum_member_level_ident_only_tests.rs @@ -32,10 +32,7 @@ enum EnumWithDataDto { #[test] fn enum2enum() { - for data in vec![ - (EnumDto::Item1, Enum::Item1), - (EnumDto::Item2Dto, Enum::Item2), - ] { + for data in vec![(EnumDto::Item1, Enum::Item1), (EnumDto::Item2Dto, Enum::Item2)] { let dto_ref = &data.0; let en: Enum = dto_ref.into(); assert!(en == data.1); @@ -55,20 +52,8 @@ fn enum2enum() { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1Dto(123, 321), - EnumWithData::Item1(123, 321), - ), - ( - EnumWithDataDto::Item2 { - string: "Test".into(), - i: 654, - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1Dto(123, 321), EnumWithData::Item1(123, 321)), + (EnumWithDataDto::Item2 { string: "Test".into(), i: 654 }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().into(); assert!(en == data.1); diff --git a/o2o-tests/tests/28_enum_member_level_ident_only_tests_fallible.rs b/o2o-tests/tests/28_enum_member_level_ident_only_tests_fallible.rs index 43bb326..58d991f 100644 --- a/o2o-tests/tests/28_enum_member_level_ident_only_tests_fallible.rs +++ b/o2o-tests/tests/28_enum_member_level_ident_only_tests_fallible.rs @@ -32,10 +32,7 @@ enum EnumWithDataDto { #[test] fn enum2enum() { - for data in vec![ - (EnumDto::Item1, Enum::Item1), - (EnumDto::Item2Dto, Enum::Item2), - ] { + for data in vec![(EnumDto::Item1, Enum::Item1), (EnumDto::Item2Dto, Enum::Item2)] { let dto_ref = &data.0; let en: Enum = dto_ref.try_into().unwrap(); assert!(en == data.1); @@ -55,20 +52,8 @@ fn enum2enum() { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1Dto(123, 321), - EnumWithData::Item1(123, 321), - ), - ( - EnumWithDataDto::Item2 { - string: "Test".into(), - i: 654, - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1Dto(123, 321), EnumWithData::Item1(123, 321)), + (EnumWithDataDto::Item2 { string: "Test".into(), i: 654 }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().try_into().unwrap(); assert!(en == data.1); diff --git a/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests.rs b/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests.rs index ecf617c..beae9cc 100644 --- a/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests.rs +++ b/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests.rs @@ -24,20 +24,8 @@ enum EnumWithDataDto { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1(123, 222), - EnumWithData::Item1(123, 111), - ), - ( - EnumWithDataDto::Item2 { - str: "Test".into(), - i: "654".into(), - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1(123, 222), EnumWithData::Item1(123, 111)), + (EnumWithDataDto::Item2 { str: "Test".into(), i: "654".into() }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().into(); assert!(en == data.1); diff --git a/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests_fallible.rs b/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests_fallible.rs index b80c244..23ed53b 100644 --- a/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests_fallible.rs +++ b/o2o-tests/tests/29_enum_member_level_inline_expr_only_tests_fallible.rs @@ -24,20 +24,8 @@ enum EnumWithDataDto { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1(123, 222), - EnumWithData::Item1(123, 111), - ), - ( - EnumWithDataDto::Item2 { - str: "Test".into(), - i: "654".into(), - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1(123, 222), EnumWithData::Item1(123, 111)), + (EnumWithDataDto::Item2 { str: "Test".into(), i: "654".into() }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().try_into().unwrap(); assert!(en == data.1); diff --git a/o2o-tests/tests/2_field_level_ident_only_attr_tests.rs b/o2o-tests/tests/2_field_level_ident_only_attr_tests.rs index 45fae1d..db85562 100644 --- a/o2o-tests/tests/2_field_level_ident_only_attr_tests.rs +++ b/o2o-tests/tests/2_field_level_ident_only_attr_tests.rs @@ -32,11 +32,7 @@ struct NamedStructDto { #[derive(Default, o2o)] #[o2o(from(NamedStruct))] #[o2o(from(NamedStructModel))] -struct UnnamedStructDto( - #[o2o(map(some_int))] i32, - #[o2o(map(another_int))] i32, - #[o2o(map(NamedStruct| some_float), map(NamedStructModel| some_float_diff))] f32, -); +struct UnnamedStructDto(#[o2o(map(some_int))] i32, #[o2o(map(another_int))] i32, #[o2o(map(NamedStruct| some_float), map(NamedStructModel| some_float_diff))] f32); #[derive(Default, o2o)] #[map(UnnamedStructDto)] @@ -52,11 +48,7 @@ struct NamedStruct2 { #[test] fn named2named() { - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let named: NamedStruct = dto.into(); @@ -64,11 +56,7 @@ fn named2named() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let model: NamedStructModel = dto.into(); @@ -79,11 +67,7 @@ fn named2named() { #[test] fn named2named_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.into(); @@ -91,11 +75,7 @@ fn named2named_reverse() { assert_eq!(321, dto.diff_another_int); assert_eq!(456.0, dto.diff_some_float); - let model = NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let dto: NamedStructDto = model.into(); @@ -106,11 +86,7 @@ fn named2named_reverse() { #[test] fn named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let named: NamedStruct = dto.into(); @@ -127,11 +103,7 @@ fn named2named_ref() { #[test] fn named2named_ref_reversed() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.into(); @@ -139,11 +111,7 @@ fn named2named_ref_reversed() { assert_eq!(named.another_int, dto.diff_another_int); assert_eq!(named.some_float, dto.diff_some_float); - let model = &NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let dto: NamedStructDto = model.into(); @@ -154,11 +122,7 @@ fn named2named_ref_reversed() { #[test] fn named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let unnamed: UnnamedStructDto = named.into(); @@ -166,11 +130,7 @@ fn named2unnamed() { assert_eq!(321, unnamed.1); assert_eq!(456.0, unnamed.2); - let model = NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let unnamed: UnnamedStructDto = model.into(); @@ -181,11 +141,7 @@ fn named2unnamed() { #[test] fn named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let unnamed: UnnamedStructDto = named.into(); @@ -193,11 +149,7 @@ fn named2unnamed_ref() { assert_eq!(named.another_int, unnamed.1); assert_eq!(named.some_float, unnamed.2); - let model = &NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let unnamed: UnnamedStructDto = named.into(); @@ -219,11 +171,7 @@ fn unnamed2named() { #[test] fn unnamed2named_reverse() { - let named = NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.into(); @@ -245,11 +193,7 @@ fn unnamed2named_ref() { #[test] fn unnamed2named_reverse_ref() { - let named = &NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.into(); @@ -260,11 +204,7 @@ fn unnamed2named_reverse_ref() { #[test] fn existing_named2named() { - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); @@ -273,11 +213,7 @@ fn existing_named2named() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let mut model: NamedStructModel = Default::default(); dto.into_existing(&mut model); @@ -289,11 +225,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); @@ -312,11 +244,7 @@ fn existing_named2named_ref() { #[test] fn existing_named2unnamed() { - let named = NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.into_existing(&mut dto); @@ -328,11 +256,7 @@ fn existing_named2unnamed() { #[test] fn existing_named2unnamed_ref() { - let named = &NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.into_existing(&mut dto); diff --git a/o2o-tests/tests/2_field_level_ident_only_attr_tests_fallible.rs b/o2o-tests/tests/2_field_level_ident_only_attr_tests_fallible.rs index 46f0970..1ded864 100644 --- a/o2o-tests/tests/2_field_level_ident_only_attr_tests_fallible.rs +++ b/o2o-tests/tests/2_field_level_ident_only_attr_tests_fallible.rs @@ -32,11 +32,7 @@ struct NamedStructDto { #[derive(Default, o2o)] #[o2o(try_from(NamedStruct, i32))] #[o2o(try_from(NamedStructModel, i32))] -struct UnnamedStructDto( - #[o2o(try_map(some_int))] i32, - #[o2o(map(another_int))] i32, - #[o2o(map(NamedStruct| some_float), map(NamedStructModel| some_float_diff))] f32, -); +struct UnnamedStructDto(#[o2o(try_map(some_int))] i32, #[o2o(map(another_int))] i32, #[o2o(map(NamedStruct| some_float), map(NamedStructModel| some_float_diff))] f32); #[derive(Default, o2o)] #[try_map(UnnamedStructDto, anyhow::Error)] @@ -52,11 +48,7 @@ struct NamedStruct2 { #[test] fn named2named() { - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let named: NamedStruct = dto.try_into().unwrap(); @@ -64,11 +56,7 @@ fn named2named() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let model: NamedStructModel = dto.try_into().unwrap(); @@ -79,11 +67,7 @@ fn named2named() { #[test] fn named2named_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -91,11 +75,7 @@ fn named2named_reverse() { assert_eq!(321, dto.diff_another_int); assert_eq!(456.0, dto.diff_some_float); - let model = NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -106,11 +86,7 @@ fn named2named_reverse() { #[test] fn named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let named: NamedStruct = dto.try_into().unwrap(); @@ -127,11 +103,7 @@ fn named2named_ref() { #[test] fn named2named_ref_reversed() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -139,11 +111,7 @@ fn named2named_ref_reversed() { assert_eq!(named.another_int, dto.diff_another_int); assert_eq!(named.some_float, dto.diff_some_float); - let model = &NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -154,11 +122,7 @@ fn named2named_ref_reversed() { #[test] fn named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let unnamed: UnnamedStructDto = named.try_into().unwrap(); @@ -166,11 +130,7 @@ fn named2unnamed() { assert_eq!(321, unnamed.1); assert_eq!(456.0, unnamed.2); - let model = NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let unnamed: UnnamedStructDto = model.try_into().unwrap(); @@ -181,11 +141,7 @@ fn named2unnamed() { #[test] fn named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let unnamed: UnnamedStructDto = named.try_into().unwrap(); @@ -193,11 +149,7 @@ fn named2unnamed_ref() { assert_eq!(named.another_int, unnamed.1); assert_eq!(named.some_float, unnamed.2); - let model = &NamedStructModel { - some_int: 123, - another_int: 321, - some_float_diff: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 321, some_float_diff: 456.0 }; let unnamed: UnnamedStructDto = named.try_into().unwrap(); @@ -219,11 +171,7 @@ fn unnamed2named() { #[test] fn unnamed2named_reverse() { - let named = NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.try_into().unwrap(); @@ -245,11 +193,7 @@ fn unnamed2named_ref() { #[test] fn unnamed2named_reverse_ref() { - let named = &NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.try_into().unwrap(); @@ -260,11 +204,7 @@ fn unnamed2named_reverse_ref() { #[test] fn existing_named2named() { - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); @@ -273,11 +213,7 @@ fn existing_named2named() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let mut model: NamedStructModel = Default::default(); dto.try_into_existing(&mut model).unwrap(); @@ -289,11 +225,7 @@ fn existing_named2named() { #[test] fn existing_named2named_ref() { - let dto = &NamedStructDto { - some_int: 123, - diff_another_int: 321, - diff_some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, diff_another_int: 321, diff_some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); @@ -312,11 +244,7 @@ fn existing_named2named_ref() { #[test] fn existing_named2unnamed() { - let named = NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.try_into_existing(&mut dto).unwrap(); @@ -328,11 +256,7 @@ fn existing_named2unnamed() { #[test] fn existing_named2unnamed_ref() { - let named = &NamedStruct2 { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct2 { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.try_into_existing(&mut dto).unwrap(); diff --git a/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests.rs b/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests.rs index 4a30fd1..f5563de 100644 --- a/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests.rs +++ b/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests.rs @@ -24,20 +24,8 @@ enum EnumWithDataDto { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1("123".into(), 321), - EnumWithData::Item1(123, 321), - ), - ( - EnumWithDataDto::Item2 { - str: "Test".into(), - i_str: "654".into(), - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1("123".into(), 321), EnumWithData::Item1(123, 321)), + (EnumWithDataDto::Item2 { str: "Test".into(), i_str: "654".into() }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().into(); assert!(en == data.1); diff --git a/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests_fallible.rs b/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests_fallible.rs index 0219cc1..fcbb184 100644 --- a/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests_fallible.rs +++ b/o2o-tests/tests/30_enum_member_level_ident_and_inline_expr_tests_fallible.rs @@ -24,20 +24,8 @@ enum EnumWithDataDto { #[test] fn enum2enum_with_data() { for data in vec![ - ( - EnumWithDataDto::Item1("123".into(), 321), - EnumWithData::Item1(123, 321), - ), - ( - EnumWithDataDto::Item2 { - str: "Test".into(), - i_str: "654".into(), - }, - EnumWithData::Item2 { - str: "Test".into(), - i: 654, - }, - ), + (EnumWithDataDto::Item1("123".into(), 321), EnumWithData::Item1(123, 321)), + (EnumWithDataDto::Item2 { str: "Test".into(), i_str: "654".into() }, EnumWithData::Item2 { str: "Test".into(), i: 654 }), ] { let en: EnumWithData = data.0.clone().try_into().unwrap(); assert!(en == data.1); diff --git a/o2o-tests/tests/35_enum_variant_type_hint_tests.rs b/o2o-tests/tests/35_enum_variant_type_hint_tests.rs index 6eca5a4..89ea4dc 100644 --- a/o2o-tests/tests/35_enum_variant_type_hint_tests.rs +++ b/o2o-tests/tests/35_enum_variant_type_hint_tests.rs @@ -31,20 +31,8 @@ enum EnumDto { fn enum2enum() { for data in vec![ (EnumDto::Var1, Enum::Var1), - ( - EnumDto::Var2(123, "test".into()), - Enum::Var2 { - field: 123, - str_field: "test".into(), - }, - ), - ( - EnumDto::Var3 { - field: 123, - str_field: "test".into(), - }, - Enum::Var3(123, "test".into()), - ), + (EnumDto::Var2(123, "test".into()), Enum::Var2 { field: 123, str_field: "test".into() }), + (EnumDto::Var3 { field: 123, str_field: "test".into() }, Enum::Var3(123, "test".into())), ] { let dto_ref = &data.0; let en: Enum = dto_ref.into(); diff --git a/o2o-tests/tests/35_enum_variant_type_hint_tests_fallible.rs b/o2o-tests/tests/35_enum_variant_type_hint_tests_fallible.rs index b523492..2053491 100644 --- a/o2o-tests/tests/35_enum_variant_type_hint_tests_fallible.rs +++ b/o2o-tests/tests/35_enum_variant_type_hint_tests_fallible.rs @@ -31,20 +31,8 @@ enum EnumDto { fn enum2enum() { for data in vec![ (EnumDto::Var1, Enum::Var1), - ( - EnumDto::Var2(123, "test".into()), - Enum::Var2 { - field: 123, - str_field: "test".into(), - }, - ), - ( - EnumDto::Var3 { - field: 123, - str_field: "test".into(), - }, - Enum::Var3(123, "test".into()), - ), + (EnumDto::Var2(123, "test".into()), Enum::Var2 { field: 123, str_field: "test".into() }), + (EnumDto::Var3 { field: 123, str_field: "test".into() }, Enum::Var3(123, "test".into())), ] { let dto_ref = &data.0; let en: Enum = dto_ref.try_into().unwrap(); diff --git a/o2o-tests/tests/36_enum_variant_ghost_attr_tests.rs b/o2o-tests/tests/36_enum_variant_ghost_attr_tests.rs index dc256ee..a90fe38 100644 --- a/o2o-tests/tests/36_enum_variant_ghost_attr_tests.rs +++ b/o2o-tests/tests/36_enum_variant_ghost_attr_tests.rs @@ -10,11 +10,7 @@ enum Enum { #[map_ref(~.clone())] str_field: String, }, - Var3( - #[map_ref(*~)] i32, - #[ghost({123.0})] f32, - #[map_ref(~.clone())] String, - ), + Var3(#[map_ref(*~)] i32, #[ghost({123.0})] f32, #[map_ref(~.clone())] String), } #[derive(Clone, PartialEq)] @@ -28,21 +24,8 @@ enum EnumDto { fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), - ( - Enum::Var2 { - field: 123, - _f: 321.0, - str_field: "test".into(), - }, - EnumDto::Var2 { - field: 123, - str_field: "test".into(), - }, - ), - ( - Enum::Var3(123, 123.0, "test".into()), - EnumDto::Var3(123, "test".into()), - ), + (Enum::Var2 { field: 123, _f: 321.0, str_field: "test".into() }, EnumDto::Var2 { field: 123, str_field: "test".into() }), + (Enum::Var3(123, 123.0, "test".into()), EnumDto::Var3(123, "test".into())), ] { let dto_ref = &data.1; let en: Enum = dto_ref.into(); diff --git a/o2o-tests/tests/36_enum_variant_ghost_attr_tests_fallible.rs b/o2o-tests/tests/36_enum_variant_ghost_attr_tests_fallible.rs index fa9ea77..30be3f3 100644 --- a/o2o-tests/tests/36_enum_variant_ghost_attr_tests_fallible.rs +++ b/o2o-tests/tests/36_enum_variant_ghost_attr_tests_fallible.rs @@ -10,11 +10,7 @@ enum Enum { #[map_ref(~.clone())] str_field: String, }, - Var3( - #[map_ref(*~)] i32, - #[ghost({123.0})] f32, - #[map_ref(~.clone())] String, - ), + Var3(#[map_ref(*~)] i32, #[ghost({123.0})] f32, #[map_ref(~.clone())] String), } #[derive(Clone, PartialEq)] @@ -28,21 +24,8 @@ enum EnumDto { fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), - ( - Enum::Var2 { - field: 123, - _f: 321.0, - str_field: "test".into(), - }, - EnumDto::Var2 { - field: 123, - str_field: "test".into(), - }, - ), - ( - Enum::Var3(123, 123.0, "test".into()), - EnumDto::Var3(123, "test".into()), - ), + (Enum::Var2 { field: 123, _f: 321.0, str_field: "test".into() }, EnumDto::Var2 { field: 123, str_field: "test".into() }), + (Enum::Var3(123, 123.0, "test".into()), EnumDto::Var3(123, "test".into())), ] { let dto_ref = &data.1; let en: Enum = dto_ref.try_into().unwrap(); diff --git a/o2o-tests/tests/37_enum_variant_ghosts_attr_tests.rs b/o2o-tests/tests/37_enum_variant_ghosts_attr_tests.rs index 317ea0e..0fa579b 100644 --- a/o2o-tests/tests/37_enum_variant_ghosts_attr_tests.rs +++ b/o2o-tests/tests/37_enum_variant_ghosts_attr_tests.rs @@ -26,32 +26,15 @@ enum Enum { enum EnumDto { Var1, Var2(i32, String, f64), - Var3 { - field: i32, - str_field: String, - _other: f64, - }, + Var3 { field: i32, str_field: String, _other: f64 }, } #[test] fn enum2enum() { for data in vec![ (EnumDto::Var1, Enum::Var1), - ( - EnumDto::Var2(123, "test".into(), 654.0), - Enum::Var2 { - field: 123, - str_field: "test".into(), - }, - ), - ( - EnumDto::Var3 { - field: 123, - str_field: "test".into(), - _other: 321.0, - }, - Enum::Var3(123, "test".into()), - ), + (EnumDto::Var2(123, "test".into(), 654.0), Enum::Var2 { field: 123, str_field: "test".into() }), + (EnumDto::Var3 { field: 123, str_field: "test".into(), _other: 321.0 }, Enum::Var3(123, "test".into())), ] { let dto_ref = &data.0; let en: Enum = dto_ref.into(); diff --git a/o2o-tests/tests/37_enum_variant_ghosts_attr_tests_fallible.rs b/o2o-tests/tests/37_enum_variant_ghosts_attr_tests_fallible.rs index dab2855..2eca311 100644 --- a/o2o-tests/tests/37_enum_variant_ghosts_attr_tests_fallible.rs +++ b/o2o-tests/tests/37_enum_variant_ghosts_attr_tests_fallible.rs @@ -26,32 +26,15 @@ enum Enum { enum EnumDto { Var1, Var2(i32, String, f64), - Var3 { - field: i32, - str_field: String, - _other: f64, - }, + Var3 { field: i32, str_field: String, _other: f64 }, } #[test] fn enum2enum() { for data in vec![ (EnumDto::Var1, Enum::Var1), - ( - EnumDto::Var2(123, "test".into(), 654.0), - Enum::Var2 { - field: 123, - str_field: "test".into(), - }, - ), - ( - EnumDto::Var3 { - field: 123, - str_field: "test".into(), - _other: 321.0, - }, - Enum::Var3(123, "test".into()), - ), + (EnumDto::Var2(123, "test".into(), 654.0), Enum::Var2 { field: 123, str_field: "test".into() }), + (EnumDto::Var3 { field: 123, str_field: "test".into(), _other: 321.0 }, Enum::Var3(123, "test".into())), ] { let dto_ref = &data.0; let en: Enum = dto_ref.try_into().unwrap(); diff --git a/o2o-tests/tests/39_enum_variant_unit_type_hint.rs b/o2o-tests/tests/39_enum_variant_unit_type_hint.rs index 71e9822..06ed3eb 100644 --- a/o2o-tests/tests/39_enum_variant_unit_type_hint.rs +++ b/o2o-tests/tests/39_enum_variant_unit_type_hint.rs @@ -25,13 +25,7 @@ fn struct2unit() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let dto_ref = &data.1; let en: Enum = dto_ref.into(); @@ -73,13 +67,7 @@ fn unit2struct() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let dto_ref = &data.1; let en: Enum = dto_ref.into(); @@ -122,13 +110,7 @@ fn struct2unit_no_ghost() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let en_ref = &data.0; let dto: EnumDto = en_ref.into(); @@ -161,13 +143,7 @@ fn unit2struct_no_ghost() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let en_ref = &data.0; let dto: EnumDto = en_ref.into(); diff --git a/o2o-tests/tests/39_enum_variant_unit_type_hint_fallible.rs b/o2o-tests/tests/39_enum_variant_unit_type_hint_fallible.rs index 34e97a2..ce016ce 100644 --- a/o2o-tests/tests/39_enum_variant_unit_type_hint_fallible.rs +++ b/o2o-tests/tests/39_enum_variant_unit_type_hint_fallible.rs @@ -25,13 +25,7 @@ fn struct2unit() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let dto_ref = &data.1; let en: Enum = dto_ref.try_into().unwrap(); @@ -73,13 +67,7 @@ fn unit2struct() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let dto_ref = &data.1; let en: Enum = dto_ref.try_into().unwrap(); @@ -122,13 +110,7 @@ fn struct2unit_no_ghost() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let en_ref = &data.0; let dto: EnumDto = en_ref.try_into().unwrap(); @@ -161,13 +143,7 @@ fn unit2struct_no_ghost() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var2(123, "test".into()), EnumDto::Var2), - ( - Enum::Var3 { - _field: 123, - _str_field: "test".into(), - }, - EnumDto::Var3, - ), + (Enum::Var3 { _field: 123, _str_field: "test".into() }, EnumDto::Var3), ] { let en_ref = &data.0; let dto: EnumDto = en_ref.try_into().unwrap(); diff --git a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs index b446680..959c2c9 100644 --- a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs +++ b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs @@ -25,12 +25,7 @@ struct NamedStructModel { } #[derive(o2o)] -#[o2o( - map(NamedStruct), - map(NamedStructModel), - into_existing(NamedStruct), - into_existing(NamedStructModel) -)] +#[o2o(map(NamedStruct), map(NamedStructModel), into_existing(NamedStruct), into_existing(NamedStructModel))] struct NamedStructDto { some_int: i32, #[o2o( @@ -121,11 +116,7 @@ fn unnamed2named() { #[test] fn named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.into(); @@ -147,11 +138,7 @@ fn unnamed2named_ref() { #[test] fn named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.into(); @@ -162,13 +149,7 @@ fn named2unnamed_ref() { #[test] fn named2named_uneven() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto2 = p.into(); @@ -179,13 +160,7 @@ fn named2named_uneven() { #[test] fn named2named_uneven_ref() { - let parent = &Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let parent = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto2 = parent.into(); @@ -196,11 +171,7 @@ fn named2named_uneven_ref() { #[test] fn named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let named: NamedStruct = dto.into(); @@ -208,11 +179,7 @@ fn named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let model: NamedStructModel = dto.into(); @@ -223,11 +190,7 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.into(); @@ -235,11 +198,7 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.another_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.into(); @@ -250,11 +209,7 @@ fn named2named_different_types_reverse() { #[test] fn named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let named: NamedStruct = dto.into(); @@ -271,11 +226,7 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.into(); @@ -283,11 +234,7 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.another_int, dto.another_int as i32); assert_eq!(named.some_float, dto.some_float as f32); - let model = &NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.into(); @@ -298,13 +245,7 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.into(); @@ -317,10 +258,7 @@ fn named2named_child() { fn named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.into(); @@ -335,14 +273,8 @@ fn named2named_children() { let dto = PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -361,14 +293,8 @@ fn named2named_children_reverse() { let p = Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -387,14 +313,8 @@ fn named2named_children_ref() { let dto = &PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -413,14 +333,8 @@ fn named2named_children_ref_reversed() { let p = &Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -436,11 +350,7 @@ fn named2named_children_ref_reversed() { #[test] fn existing_named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.into_existing(&mut dto); @@ -452,11 +362,7 @@ fn existing_named2unnamed() { #[test] fn existing_named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.into_existing(&mut dto); @@ -468,11 +374,7 @@ fn existing_named2unnamed_ref() { #[test] fn existing_named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); @@ -481,11 +383,7 @@ fn existing_named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: NamedStructModel = Default::default(); dto.into_existing(&mut model); @@ -497,11 +395,7 @@ fn existing_named2named_different_types() { #[test] fn existing_named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); diff --git a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs index 9e5296e..1127bac 100644 --- a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs +++ b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs @@ -25,12 +25,7 @@ struct NamedStructModel { } #[derive(o2o)] -#[o2o( - try_map(NamedStruct, anyhow::Error), - try_map(NamedStructModel, anyhow::Error), - try_into_existing(NamedStruct, anyhow::Error), - try_into_existing(NamedStructModel, anyhow::Error) -)] +#[o2o(try_map(NamedStruct, anyhow::Error), try_map(NamedStructModel, anyhow::Error), try_into_existing(NamedStruct, anyhow::Error), try_into_existing(NamedStructModel, anyhow::Error))] struct NamedStructDto { some_int: i32, #[o2o( @@ -121,11 +116,7 @@ fn unnamed2named() { #[test] fn named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.try_into().unwrap(); @@ -147,11 +138,7 @@ fn unnamed2named_ref() { #[test] fn named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: UnnamedStructDto = named.try_into().unwrap(); @@ -162,13 +149,7 @@ fn named2unnamed_ref() { #[test] fn named2named_uneven() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto2 = p.try_into().unwrap(); @@ -179,13 +160,7 @@ fn named2named_uneven() { #[test] fn named2named_uneven_ref() { - let parent = &Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let parent = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto2 = parent.try_into().unwrap(); @@ -196,11 +171,7 @@ fn named2named_uneven_ref() { #[test] fn named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let named: NamedStruct = dto.try_into().unwrap(); @@ -208,11 +179,7 @@ fn named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let model: NamedStructModel = dto.try_into().unwrap(); @@ -223,11 +190,7 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -235,11 +198,7 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.another_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -250,11 +209,7 @@ fn named2named_different_types_reverse() { #[test] fn named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let named: NamedStruct = dto.try_into().unwrap(); @@ -271,11 +226,7 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -283,11 +234,7 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.another_int, dto.another_int as i32); assert_eq!(named.some_float, dto.some_float as f32); - let model = &NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -298,13 +245,7 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -317,10 +258,7 @@ fn named2named_child() { fn named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.try_into().unwrap(); @@ -335,14 +273,8 @@ fn named2named_children() { let dto = PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -361,14 +293,8 @@ fn named2named_children_reverse() { let p = Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -387,14 +313,8 @@ fn named2named_children_ref() { let dto = &PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -413,14 +333,8 @@ fn named2named_children_ref_reversed() { let p = &Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -436,11 +350,7 @@ fn named2named_children_ref_reversed() { #[test] fn existing_named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.try_into_existing(&mut dto).unwrap(); @@ -452,11 +362,7 @@ fn existing_named2unnamed() { #[test] fn existing_named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.try_into_existing(&mut dto).unwrap(); @@ -468,11 +374,7 @@ fn existing_named2unnamed_ref() { #[test] fn existing_named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); @@ -481,11 +383,7 @@ fn existing_named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: NamedStructModel = Default::default(); dto.try_into_existing(&mut model).unwrap(); @@ -497,11 +395,7 @@ fn existing_named2named_different_types() { #[test] fn existing_named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); diff --git a/o2o-tests/tests/40_permeating_repeat_tests.rs b/o2o-tests/tests/40_permeating_repeat_tests.rs index 561bf85..fab7383 100644 --- a/o2o-tests/tests/40_permeating_repeat_tests.rs +++ b/o2o-tests/tests/40_permeating_repeat_tests.rs @@ -35,16 +35,7 @@ fn reqular_repeat() { } let data = vec![ - ( - Enum::Var1 { - field: 111, - field_2: 111, - }, - EnumDto::Var1 { - field: 222, - field_2: 222, - }, - ), + (Enum::Var1 { field: 111, field_2: 111 }, EnumDto::Var1 { field: 222, field_2: 222 }), (Enum::Var2 { field_3: 222 }, EnumDto::Var2 { field_3: 222 }), (Enum::Var3 { field_4: 333 }, EnumDto::Var3 { field_4: 333 }), (Enum::Var4 { field_5: 444 }, EnumDto::Var4 { field_5: 444 }), @@ -97,16 +88,7 @@ fn permeating_repeat() { } let data = vec![ - ( - Enum::Var1 { - field: 111, - field_2: 111, - }, - EnumDto::Var1 { - field: 222, - field_2: 222, - }, - ), + (Enum::Var1 { field: 111, field_2: 111 }, EnumDto::Var1 { field: 222, field_2: 222 }), (Enum::Var2 { field_3: 222 }, EnumDto::Var2 { field_3: 444 }), (Enum::Var3 { field_4: 333 }, EnumDto::Var3 { field_4: 666 }), (Enum::Var4 { field_5: 444 }, EnumDto::Var4 { field_5: 888 }), diff --git a/o2o-tests/tests/40_permeating_repeat_tests_fallible.rs b/o2o-tests/tests/40_permeating_repeat_tests_fallible.rs index a53d707..28e1cbe 100644 --- a/o2o-tests/tests/40_permeating_repeat_tests_fallible.rs +++ b/o2o-tests/tests/40_permeating_repeat_tests_fallible.rs @@ -35,16 +35,7 @@ fn reqular_repeat() { } let data = vec![ - ( - Enum::Var1 { - field: 111, - field_2: 111, - }, - EnumDto::Var1 { - field: 222, - field_2: 222, - }, - ), + (Enum::Var1 { field: 111, field_2: 111 }, EnumDto::Var1 { field: 222, field_2: 222 }), (Enum::Var2 { field_3: 222 }, EnumDto::Var2 { field_3: 222 }), (Enum::Var3 { field_4: 333 }, EnumDto::Var3 { field_4: 333 }), (Enum::Var4 { field_5: 444 }, EnumDto::Var4 { field_5: 444 }), @@ -97,16 +88,7 @@ fn permeating_repeat() { } let data = vec![ - ( - Enum::Var1 { - field: 111, - field_2: 111, - }, - EnumDto::Var1 { - field: 222, - field_2: 222, - }, - ), + (Enum::Var1 { field: 111, field_2: 111 }, EnumDto::Var1 { field: 222, field_2: 222 }), (Enum::Var2 { field_3: 222 }, EnumDto::Var2 { field_3: 444 }), (Enum::Var3 { field_4: 333 }, EnumDto::Var3 { field_4: 666 }), (Enum::Var4 { field_5: 444 }, EnumDto::Var4 { field_5: 888 }), diff --git a/o2o-tests/tests/41_enum_ghost_tests_1.rs b/o2o-tests/tests/41_enum_ghost_tests_1.rs index 4a05ba3..dcf865f 100644 --- a/o2o-tests/tests/41_enum_ghost_tests_1.rs +++ b/o2o-tests/tests/41_enum_ghost_tests_1.rs @@ -68,10 +68,7 @@ fn enum2enum_panic() { #[test] #[should_panic(expected = "impl var4")] fn enum2enum_panic_2() { - let dto = EnumDto::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto::Var4 { _str: "test".into(), _i: 123 }; let _: Enum = dto.into(); } @@ -84,10 +81,7 @@ fn enum2enum_panic_3() { #[test] fn enum2enum_reverse() { - for data in vec![ - (Enum2::Var1, EnumDto2::Var1), - (Enum2::Var22, EnumDto2::Var2), - ] { + for data in vec![(Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2)] { let dto_ref = &data.1; let en: Enum2 = dto_ref.into(); assert!(en == data.0); @@ -114,10 +108,7 @@ fn enum2enum_panic_reverse() { #[test] #[should_panic(expected = "impl var4")] fn enum2enum_panic_reverse_2() { - let dto = EnumDto2::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto2::Var4 { _str: "test".into(), _i: 123 }; let _: Enum2 = dto.into(); } diff --git a/o2o-tests/tests/41_enum_ghost_tests_1_fallible.rs b/o2o-tests/tests/41_enum_ghost_tests_1_fallible.rs index c736e98..509b716 100644 --- a/o2o-tests/tests/41_enum_ghost_tests_1_fallible.rs +++ b/o2o-tests/tests/41_enum_ghost_tests_1_fallible.rs @@ -67,10 +67,7 @@ fn enum2enum_panic() { #[test] fn enum2enum_panic_2() { - let dto = EnumDto::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto::Var4 { _str: "test".into(), _i: 123 }; let res: Result = dto.try_into(); assert!(res.is_err_and(|x| x == "impl var4")) } @@ -84,10 +81,7 @@ fn enum2enum_panic_3() { #[test] fn enum2enum_reverse() { - for data in vec![ - (Enum2::Var1, EnumDto2::Var1), - (Enum2::Var22, EnumDto2::Var2), - ] { + for data in vec![(Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2)] { let dto_ref = &data.1; let en: Enum2 = dto_ref.try_into().unwrap(); assert!(en == data.0); @@ -113,10 +107,7 @@ fn enum2enum_panic_reverse() { #[test] fn enum2enum_panic_reverse_2() { - let dto = EnumDto2::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto2::Var4 { _str: "test".into(), _i: 123 }; let res: Result = dto.try_into(); assert!(res.is_err_and(|x| x == "impl var4")) } diff --git a/o2o-tests/tests/41_enum_ghost_tests_2.rs b/o2o-tests/tests/41_enum_ghost_tests_2.rs index 46355b0..5879f74 100644 --- a/o2o-tests/tests/41_enum_ghost_tests_2.rs +++ b/o2o-tests/tests/41_enum_ghost_tests_2.rs @@ -42,13 +42,7 @@ fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var22, EnumDto::Var2), - ( - Enum::Error("test".into()), - EnumDto::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum::Error("test".into()), EnumDto::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum = dto_ref.into(); @@ -71,13 +65,7 @@ fn enum2enum_reverse() { for data in vec![ (Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2), - ( - Enum2::Error("test".into()), - EnumDto2::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum2::Error("test".into()), EnumDto2::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum2 = dto_ref.into(); diff --git a/o2o-tests/tests/41_enum_ghost_tests_2_fallible.rs b/o2o-tests/tests/41_enum_ghost_tests_2_fallible.rs index 0344f33..dd68f6d 100644 --- a/o2o-tests/tests/41_enum_ghost_tests_2_fallible.rs +++ b/o2o-tests/tests/41_enum_ghost_tests_2_fallible.rs @@ -42,13 +42,7 @@ fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var22, EnumDto::Var2), - ( - Enum::Error("test".into()), - EnumDto::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum::Error("test".into()), EnumDto::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum = dto_ref.try_into().unwrap(); @@ -71,13 +65,7 @@ fn enum2enum_reverse() { for data in vec![ (Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2), - ( - Enum2::Error("test".into()), - EnumDto2::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum2::Error("test".into()), EnumDto2::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum2 = dto_ref.try_into().unwrap(); diff --git a/o2o-tests/tests/42_enum_variant_inline_expr_tests.rs b/o2o-tests/tests/42_enum_variant_inline_expr_tests.rs index 8705367..5ea74d2 100644 --- a/o2o-tests/tests/42_enum_variant_inline_expr_tests.rs +++ b/o2o-tests/tests/42_enum_variant_inline_expr_tests.rs @@ -46,13 +46,7 @@ fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var22, EnumDto::Var2), - ( - Enum::Error("test".into()), - EnumDto::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum::Error("test".into()), EnumDto::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum = dto_ref.into(); @@ -75,13 +69,7 @@ fn enum2enum_reverse() { for data in vec![ (Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2), - ( - Enum2::Error("test".into()), - EnumDto2::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum2::Error("test".into()), EnumDto2::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum2 = dto_ref.into(); diff --git a/o2o-tests/tests/42_enum_variant_inline_expr_tests_2.rs b/o2o-tests/tests/42_enum_variant_inline_expr_tests_2.rs index f0969e6..b1b49ef 100644 --- a/o2o-tests/tests/42_enum_variant_inline_expr_tests_2.rs +++ b/o2o-tests/tests/42_enum_variant_inline_expr_tests_2.rs @@ -46,13 +46,7 @@ fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var22, EnumDto::Var2), - ( - Enum::Error("test".into()), - EnumDto::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum::Error("test".into()), EnumDto::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum = dto_ref.into(); @@ -75,13 +69,7 @@ fn enum2enum_reverse() { for data in vec![ (Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2), - ( - Enum2::Error("test".into()), - EnumDto2::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum2::Error("test".into()), EnumDto2::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum2 = dto_ref.into(); diff --git a/o2o-tests/tests/42_enum_variant_inline_expr_tests_2_fallible.rs b/o2o-tests/tests/42_enum_variant_inline_expr_tests_2_fallible.rs index 3dcf44c..c82fd3b 100644 --- a/o2o-tests/tests/42_enum_variant_inline_expr_tests_2_fallible.rs +++ b/o2o-tests/tests/42_enum_variant_inline_expr_tests_2_fallible.rs @@ -46,13 +46,7 @@ fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var22, EnumDto::Var2), - ( - Enum::Error("test".into()), - EnumDto::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum::Error("test".into()), EnumDto::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum = dto_ref.try_into().unwrap(); @@ -75,13 +69,7 @@ fn enum2enum_reverse() { for data in vec![ (Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2), - ( - Enum2::Error("test".into()), - EnumDto2::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum2::Error("test".into()), EnumDto2::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum2 = dto_ref.try_into().unwrap(); diff --git a/o2o-tests/tests/42_enum_variant_inline_expr_tests_fallible.rs b/o2o-tests/tests/42_enum_variant_inline_expr_tests_fallible.rs index ca28035..5d3f9a1 100644 --- a/o2o-tests/tests/42_enum_variant_inline_expr_tests_fallible.rs +++ b/o2o-tests/tests/42_enum_variant_inline_expr_tests_fallible.rs @@ -46,13 +46,7 @@ fn enum2enum() { for data in vec![ (Enum::Var1, EnumDto::Var1), (Enum::Var22, EnumDto::Var2), - ( - Enum::Error("test".into()), - EnumDto::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum::Error("test".into()), EnumDto::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum = dto_ref.try_into().unwrap(); @@ -75,13 +69,7 @@ fn enum2enum_reverse() { for data in vec![ (Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2), - ( - Enum2::Error("test".into()), - EnumDto2::Var3 { - _str: "test".into(), - _i: 123, - }, - ), + (Enum2::Error("test".into()), EnumDto2::Var3 { _str: "test".into(), _i: 123 }), ] { let dto_ref = &data.1; let en: Enum2 = dto_ref.try_into().unwrap(); diff --git a/o2o-tests/tests/43_enum_default_tests.rs b/o2o-tests/tests/43_enum_default_tests.rs index a95bdc5..43d0a3c 100644 --- a/o2o-tests/tests/43_enum_default_tests.rs +++ b/o2o-tests/tests/43_enum_default_tests.rs @@ -68,10 +68,7 @@ fn enum2enum_panic() { #[test] #[should_panic(expected = "unknown")] fn enum2enum_panic_2() { - let dto = EnumDto::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto::Var4 { _str: "test".into(), _i: 123 }; let _: Enum = dto.into(); } @@ -84,10 +81,7 @@ fn enum2enum_panic_3() { #[test] fn enum2enum_reverse() { - for data in vec![ - (Enum2::Var1, EnumDto2::Var1), - (Enum2::Var22, EnumDto2::Var2), - ] { + for data in vec![(Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2)] { let dto_ref = &data.1; let en: Enum2 = dto_ref.into(); assert!(en == data.0); @@ -114,10 +108,7 @@ fn enum2enum_panic_reverse() { #[test] #[should_panic(expected = "unknown")] fn enum2enum_panic_reverse_2() { - let dto = EnumDto2::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto2::Var4 { _str: "test".into(), _i: 123 }; let _: Enum2 = dto.into(); } diff --git a/o2o-tests/tests/43_enum_default_tests_fallible.rs b/o2o-tests/tests/43_enum_default_tests_fallible.rs index 602bbe1..189b67f 100644 --- a/o2o-tests/tests/43_enum_default_tests_fallible.rs +++ b/o2o-tests/tests/43_enum_default_tests_fallible.rs @@ -67,10 +67,7 @@ fn enum2enum_panic() { #[test] fn enum2enum_panic_2() { - let dto = EnumDto::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto::Var4 { _str: "test".into(), _i: 123 }; let res: Result = dto.try_into(); assert!(res.is_err_and(|x| x == "unknown")) } @@ -84,10 +81,7 @@ fn enum2enum_panic_3() { #[test] fn enum2enum_reverse() { - for data in vec![ - (Enum2::Var1, EnumDto2::Var1), - (Enum2::Var22, EnumDto2::Var2), - ] { + for data in vec![(Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2)] { let dto_ref = &data.1; let en: Enum2 = dto_ref.try_into().unwrap(); assert!(en == data.0); @@ -113,10 +107,7 @@ fn enum2enum_panic_reverse() { #[test] fn enum2enum_panic_reverse_2() { - let dto = EnumDto2::Var4 { - _str: "test".into(), - _i: 123, - }; + let dto = EnumDto2::Var4 { _str: "test".into(), _i: 123 }; let res: Result = dto.try_into(); assert!(res.is_err_and(|x| x == "unknown")) } diff --git a/o2o-tests/tests/44_enum_ghost_default_tests.rs b/o2o-tests/tests/44_enum_ghost_default_tests.rs index e860d7f..bfb280c 100644 --- a/o2o-tests/tests/44_enum_ghost_default_tests.rs +++ b/o2o-tests/tests/44_enum_ghost_default_tests.rs @@ -68,10 +68,7 @@ fn enum2enum_panic2() { #[test] fn enum2enum_reverse() { - for data in vec![ - (Enum2::Var1, EnumDto2::Var1), - (Enum2::Var22, EnumDto2::Var2), - ] { + for data in vec![(Enum2::Var1, EnumDto2::Var1), (Enum2::Var22, EnumDto2::Var2)] { let dto_ref = &data.1; let en: Enum2 = dto_ref.try_into().unwrap(); assert!(en == data.0); diff --git a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs index d079c9e..d00a41f 100644 --- a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs +++ b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs @@ -16,12 +16,7 @@ struct NamedStructModel { } #[derive(o2o)] -#[o2o( - map(NamedStruct), - map(NamedStructModel), - into_existing(NamedStruct), - into_existing(NamedStructModel) -)] +#[o2o(map(NamedStruct), map(NamedStructModel), into_existing(NamedStruct), into_existing(NamedStructModel))] struct NamedStructDto { some_int: i32, #[o2o( @@ -91,11 +86,7 @@ struct PetDto { #[test] fn named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let named: NamedStruct = dto.into(); @@ -103,11 +94,7 @@ fn named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let model: NamedStructModel = dto.into(); @@ -118,11 +105,7 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.into(); @@ -130,11 +113,7 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.another_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.into(); @@ -145,11 +124,7 @@ fn named2named_different_types_reverse() { #[test] fn named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let named: NamedStruct = dto.into(); @@ -166,11 +141,7 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.into(); @@ -178,11 +149,7 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.another_int, dto.another_int as i32); assert_eq!(named.some_float, dto.some_float as f32); - let model = &NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.into(); @@ -193,13 +160,7 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.into(); @@ -212,10 +173,7 @@ fn named2named_child() { fn named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.into(); @@ -230,14 +188,8 @@ fn named2named_children() { let dto = PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -256,14 +208,8 @@ fn named2named_children_reverse() { let p = Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -282,14 +228,8 @@ fn named2named_children_ref() { let dto = &PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -308,14 +248,8 @@ fn named2named_children_ref_reversed() { let p = &Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -331,11 +265,7 @@ fn named2named_children_ref_reversed() { #[test] fn existing_named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); @@ -344,11 +274,7 @@ fn existing_named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: NamedStructModel = Default::default(); dto.into_existing(&mut model); @@ -360,11 +286,7 @@ fn existing_named2named_different_types() { #[test] fn existing_named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.into_existing(&mut named); diff --git a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs index bdba5df..29cb8ca 100644 --- a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs +++ b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs @@ -16,12 +16,7 @@ struct NamedStructModel { } #[derive(o2o)] -#[o2o( - try_map(NamedStruct, String), - try_map(NamedStructModel, String), - try_into_existing(NamedStruct, String), - try_into_existing(NamedStructModel, String) -)] +#[o2o(try_map(NamedStruct, String), try_map(NamedStructModel, String), try_into_existing(NamedStruct, String), try_into_existing(NamedStructModel, String))] struct NamedStructDto { some_int: i32, #[o2o( @@ -91,11 +86,7 @@ struct PetDto { #[test] fn named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let named: NamedStruct = dto.try_into().unwrap(); @@ -103,11 +94,7 @@ fn named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let model: NamedStructModel = dto.try_into().unwrap(); @@ -118,11 +105,7 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -130,11 +113,7 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.another_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -145,11 +124,7 @@ fn named2named_different_types_reverse() { #[test] fn named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let named: NamedStruct = dto.try_into().unwrap(); @@ -166,11 +141,7 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0 }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -178,11 +149,7 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.another_int, dto.another_int as i32); assert_eq!(named.some_float, dto.some_float as f32); - let model = &NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -193,13 +160,7 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -212,10 +173,7 @@ fn named2named_child() { fn named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.try_into().unwrap(); @@ -230,14 +188,8 @@ fn named2named_children() { let dto = PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -256,14 +208,8 @@ fn named2named_children_reverse() { let p = Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -282,14 +228,8 @@ fn named2named_children_ref() { let dto = &PersonDto { name: String::from("John"), pets: vec![ - PetDto { - age: 5, - nickname: String::from("Mr. Dog"), - }, - PetDto { - age: 10, - nickname: String::from("Mr. Cat"), - }, + PetDto { age: 5, nickname: String::from("Mr. Dog") }, + PetDto { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -308,14 +248,8 @@ fn named2named_children_ref_reversed() { let p = &Person { name: String::from("John"), pets: vec![ - Pet { - age: 5, - nickname: String::from("Mr. Dog"), - }, - Pet { - age: 10, - nickname: String::from("Mr. Cat"), - }, + Pet { age: 5, nickname: String::from("Mr. Dog") }, + Pet { age: 10, nickname: String::from("Mr. Cat") }, ], }; @@ -331,11 +265,7 @@ fn named2named_children_ref_reversed() { #[test] fn existing_named2named_different_types() { - let dto = NamedStructDto { - some_int: 123, - another_int: 321, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 321, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); @@ -344,11 +274,7 @@ fn existing_named2named_different_types() { assert_eq!(321, named.another_int); assert_eq!(456.0, named.some_float); - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: NamedStructModel = Default::default(); dto.try_into_existing(&mut model).unwrap(); @@ -360,11 +286,7 @@ fn existing_named2named_different_types() { #[test] fn existing_named2named_different_types_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let mut named: NamedStruct = Default::default(); dto.try_into_existing(&mut named).unwrap(); diff --git a/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs b/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs index a6d8d52..d5b8e81 100644 --- a/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs +++ b/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs @@ -32,13 +32,7 @@ struct ChildDto { #[test] fn named2named_child() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.into(); @@ -51,10 +45,7 @@ fn named2named_child() { fn named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.into(); @@ -66,13 +57,7 @@ fn named2named_child_reverse() { #[test] fn named2named_child_ref() { - let p = &Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.into(); @@ -85,30 +70,21 @@ fn named2named_child_ref() { fn named2named_child_ref_reverse() { let dto = &ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.into(); assert_eq!(dto.parent_int, parent.parent_int); assert_eq!(dto.child.child_int, parent.child.child_int); - assert_eq!( - dto.child.diff_another_child_int, - parent.child.another_child_int - ); + assert_eq!(dto.child.diff_another_child_int, parent.child.another_child_int); } #[test] fn existing_named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let mut parent: Parent = Default::default(); @@ -123,10 +99,7 @@ fn existing_named2named_child_reverse() { fn existing_named2named_child_ref_reverse() { let dto = &ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let mut parent: Parent = Default::default(); @@ -134,8 +107,5 @@ fn existing_named2named_child_ref_reverse() { assert_eq!(dto.parent_int, parent.parent_int); assert_eq!(dto.child.child_int, parent.child.child_int); - assert_eq!( - dto.child.diff_another_child_int, - parent.child.another_child_int - ); + assert_eq!(dto.child.diff_another_child_int, parent.child.another_child_int); } diff --git a/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs b/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs index 617b624..cbfc3e1 100644 --- a/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs +++ b/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs @@ -32,13 +32,7 @@ struct ChildDto { #[test] fn named2named_child() { - let p = Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -51,10 +45,7 @@ fn named2named_child() { fn named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.try_into().unwrap(); @@ -66,13 +57,7 @@ fn named2named_child_reverse() { #[test] fn named2named_child_ref() { - let p = &Parent { - parent_int: 123, - child: Child { - child_int: 321, - another_child_int: 456, - }, - }; + let p = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -85,30 +70,21 @@ fn named2named_child_ref() { fn named2named_child_ref_reverse() { let dto = &ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let parent: Parent = dto.try_into().unwrap(); assert_eq!(dto.parent_int, parent.parent_int); assert_eq!(dto.child.child_int, parent.child.child_int); - assert_eq!( - dto.child.diff_another_child_int, - parent.child.another_child_int - ); + assert_eq!(dto.child.diff_another_child_int, parent.child.another_child_int); } #[test] fn existing_named2named_child_reverse() { let dto = ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let mut parent: Parent = Default::default(); @@ -123,10 +99,7 @@ fn existing_named2named_child_reverse() { fn existing_named2named_child_ref_reverse() { let dto = &ParentDto { parent_int: 123, - child: ChildDto { - child_int: 321, - diff_another_child_int: 456, - }, + child: ChildDto { child_int: 321, diff_another_child_int: 456 }, }; let mut parent: Parent = Default::default(); @@ -134,8 +107,5 @@ fn existing_named2named_child_ref_reverse() { assert_eq!(dto.parent_int, parent.parent_int); assert_eq!(dto.child.child_int, parent.child.child_int); - assert_eq!( - dto.child.diff_another_child_int, - parent.child.another_child_int - ); + assert_eq!(dto.child.diff_another_child_int, parent.child.another_child_int); } diff --git a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs index a80adbd..016a871 100644 --- a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs +++ b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs @@ -20,12 +20,7 @@ struct Child { } #[derive(o2o)] -#[o2o( - map_owned(Parent), - map_owned(ParentModel), - owned_into_existing(Parent), - owned_into_existing(ParentModel) -)] +#[o2o(map_owned(Parent), map_owned(ParentModel), owned_into_existing(Parent), owned_into_existing(ParentModel))] struct ParentDto { #[o2o( from_owned(Parent| @.child.into()), @@ -52,10 +47,7 @@ struct ChildDto { fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.into(); @@ -66,10 +58,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.into(); @@ -81,13 +70,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.into(); @@ -97,10 +80,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.into(); @@ -114,10 +94,7 @@ fn named2named_different_name_and_type_reverse() { fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -129,10 +106,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); diff --git a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs index 6df3c10..27fd19d 100644 --- a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs +++ b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs @@ -20,12 +20,7 @@ struct Child { } #[derive(o2o)] -#[o2o( - try_map_owned(Parent, anyhow::Error), - try_map_owned(ParentModel, anyhow::Error), - owned_try_into_existing(Parent, anyhow::Error), - owned_try_into_existing(ParentModel, anyhow::Error) -)] +#[o2o(try_map_owned(Parent, anyhow::Error), try_map_owned(ParentModel, anyhow::Error), owned_try_into_existing(Parent, anyhow::Error), owned_try_into_existing(ParentModel, anyhow::Error))] struct ParentDto { #[o2o( from_owned(Parent| @.child.try_into()?), @@ -52,10 +47,7 @@ struct ChildDto { fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.try_into().unwrap(); @@ -66,10 +58,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.try_into().unwrap(); @@ -81,13 +70,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -97,10 +80,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.try_into().unwrap(); @@ -114,10 +94,7 @@ fn named2named_different_name_and_type_reverse() { fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -129,10 +106,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); diff --git a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs index 8bc909a..4faca78 100644 --- a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs +++ b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs @@ -48,10 +48,7 @@ struct ChildDto { fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.into(); @@ -62,10 +59,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.into(); @@ -77,13 +71,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.into(); @@ -93,10 +81,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.into(); @@ -110,76 +95,49 @@ fn named2named_different_name_and_type_reverse() { fn named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.into(); assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let model: ParentModel = dto.into(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.into(); assert_eq!(p.parent_int, dto.parent_int); assert_eq!(p.child.child_int, dto.diff_child.child_int as i32); - assert_eq!( - p.child.another_child_int, - dto.diff_child.diff_another_child_int as i32 - ); + assert_eq!(p.child.another_child_int, dto.diff_child.diff_another_child_int as i32); let model = &ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.into(); assert_eq!(model.parent_int, dto.parent_int); assert_eq!(model.child_diff.child_int, dto.diff_child.child_int as i32); - assert_eq!( - model.child_diff.another_child_int, - dto.diff_child.diff_another_child_int as i32 - ); + assert_eq!(model.child_diff.another_child_int, dto.diff_child.diff_another_child_int as i32); } #[test] fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -191,10 +149,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -209,10 +164,7 @@ fn existing_named2named_different_name_and_type() { fn existing_named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -220,18 +172,12 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let mut model: ParentModel = Default::default(); dto.into_existing(&mut model); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } diff --git a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs index a7ed5d1..c820992 100644 --- a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs +++ b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs @@ -48,10 +48,7 @@ struct ChildDto { fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.try_into().unwrap(); @@ -62,10 +59,7 @@ fn named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let model: ParentModel = dto.try_into().unwrap(); @@ -77,13 +71,7 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.try_into().unwrap(); @@ -93,10 +81,7 @@ fn named2named_different_name_and_type_reverse() { let model = ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.try_into().unwrap(); @@ -110,76 +95,49 @@ fn named2named_different_name_and_type_reverse() { fn named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let p: Parent = dto.try_into().unwrap(); assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let model: ParentModel = dto.try_into().unwrap(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { - parent_int: 987, - child: Child { - child_int: 456, - another_child_int: 123, - }, - }; + let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; let dto: ParentDto = p.try_into().unwrap(); assert_eq!(p.parent_int, dto.parent_int); assert_eq!(p.child.child_int, dto.diff_child.child_int as i32); - assert_eq!( - p.child.another_child_int, - dto.diff_child.diff_another_child_int as i32 - ); + assert_eq!(p.child.another_child_int, dto.diff_child.diff_another_child_int as i32); let model = &ParentModel { parent_int: 987, - child_diff: Child { - child_int: 456, - another_child_int: 123, - }, + child_diff: Child { child_int: 456, another_child_int: 123 }, }; let dto: ParentDto = model.try_into().unwrap(); assert_eq!(model.parent_int, dto.parent_int); assert_eq!(model.child_diff.child_int, dto.diff_child.child_int as i32); - assert_eq!( - model.child_diff.another_child_int, - dto.diff_child.diff_another_child_int as i32 - ); + assert_eq!(model.child_diff.another_child_int, dto.diff_child.diff_another_child_int as i32); } #[test] fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -191,10 +149,7 @@ fn existing_named2named_different_name_and_type() { let dto = ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut model: ParentModel = Default::default(); @@ -209,10 +164,7 @@ fn existing_named2named_different_name_and_type() { fn existing_named2named_different_name_and_type_ref() { let dto = &ParentDto { parent_int: 987, - diff_child: ChildDto { - child_int: 456, - diff_another_child_int: 123, - }, + diff_child: ChildDto { child_int: 456, diff_another_child_int: 123 }, }; let mut p: Parent = Default::default(); @@ -220,18 +172,12 @@ fn existing_named2named_different_name_and_type_ref() { assert_eq!(dto.parent_int, p.parent_int); assert_eq!(dto.diff_child.child_int, p.child.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - p.child.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, p.child.another_child_int as i8); let mut model: ParentModel = Default::default(); dto.try_into_existing(&mut model).unwrap(); assert_eq!(dto.parent_int, model.parent_int); assert_eq!(dto.diff_child.child_int, model.child_diff.child_int as i16); - assert_eq!( - dto.diff_child.diff_another_child_int, - model.child_diff.another_child_int as i8 - ); + assert_eq!(dto.diff_child.diff_another_child_int, model.child_diff.another_child_int as i8); } diff --git a/o2o-tests/tests/8_top_level_struct_kind_hint.rs b/o2o-tests/tests/8_top_level_struct_kind_hint.rs index 23b316b..6ffed32 100644 --- a/o2o-tests/tests/8_top_level_struct_kind_hint.rs +++ b/o2o-tests/tests/8_top_level_struct_kind_hint.rs @@ -59,11 +59,7 @@ struct UnnamedStruct( #[test] fn named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: UnnamedStructDto = named.into(); @@ -71,11 +67,7 @@ fn named2unnamed() { assert_eq!(127, dto.1); assert_eq!(456.0, dto.2); - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let model: UnnamedStructModel = named.into(); @@ -86,11 +78,7 @@ fn named2unnamed() { #[test] fn named2unnamed_2() { - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = dto.into(); @@ -98,11 +86,7 @@ fn named2unnamed_2() { assert_eq!(127, unnamed.1); assert_eq!(456.0, unnamed.2); - let named = NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = named.into(); @@ -151,11 +135,7 @@ fn unnamed2named_2() { #[test] fn named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: UnnamedStructDto = named.into(); @@ -163,11 +143,7 @@ fn named2unnamed_ref() { assert_eq!(named.another_int, dto.1); assert_eq!(named.some_float, dto.2); - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let model: UnnamedStructModel = named.into(); @@ -178,11 +154,7 @@ fn named2unnamed_ref() { #[test] fn named2unnamed_2_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = dto.into(); @@ -190,11 +162,7 @@ fn named2unnamed_2_ref() { assert_eq!(dto.another_int, unnamed.1); assert_eq!(dto.some_float, unnamed.2); - let model = &NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = model.into(); @@ -243,11 +211,7 @@ fn unnamed2named_2_ref() { #[test] fn existing_named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.into_existing(&mut dto); @@ -256,11 +220,7 @@ fn existing_named2unnamed() { assert_eq!(127, dto.1); assert_eq!(456.0, dto.2); - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: UnnamedStructModel = Default::default(); named.into_existing(&mut model); @@ -292,11 +252,7 @@ fn existing_unnamed2named() { #[test] fn existing_named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.into_existing(&mut dto); @@ -305,11 +261,7 @@ fn existing_named2unnamed_ref() { assert_eq!(named.another_int, dto.1); assert_eq!(named.some_float, dto.2); - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: UnnamedStructModel = Default::default(); named.into_existing(&mut model); diff --git a/o2o-tests/tests/8_top_level_struct_kind_hint_fallible.rs b/o2o-tests/tests/8_top_level_struct_kind_hint_fallible.rs index 8231abf..0cc528c 100644 --- a/o2o-tests/tests/8_top_level_struct_kind_hint_fallible.rs +++ b/o2o-tests/tests/8_top_level_struct_kind_hint_fallible.rs @@ -59,11 +59,7 @@ struct UnnamedStruct( #[test] fn named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: UnnamedStructDto = named.try_into().unwrap(); @@ -71,11 +67,7 @@ fn named2unnamed() { assert_eq!(127, dto.1); assert_eq!(456.0, dto.2); - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let model: UnnamedStructModel = named.try_into().unwrap(); @@ -86,11 +78,7 @@ fn named2unnamed() { #[test] fn named2unnamed_2() { - let dto = NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = dto.try_into().unwrap(); @@ -98,11 +86,7 @@ fn named2unnamed_2() { assert_eq!(127, unnamed.1); assert_eq!(456.0, unnamed.2); - let named = NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = named.try_into().unwrap(); @@ -151,11 +135,7 @@ fn unnamed2named_2() { #[test] fn named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let dto: UnnamedStructDto = named.try_into().unwrap(); @@ -163,11 +143,7 @@ fn named2unnamed_ref() { assert_eq!(named.another_int, dto.1); assert_eq!(named.some_float, dto.2); - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let model: UnnamedStructModel = named.try_into().unwrap(); @@ -178,11 +154,7 @@ fn named2unnamed_ref() { #[test] fn named2unnamed_2_ref() { - let dto = &NamedStructDto { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let dto = &NamedStructDto { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = dto.try_into().unwrap(); @@ -190,11 +162,7 @@ fn named2unnamed_2_ref() { assert_eq!(dto.another_int, unnamed.1); assert_eq!(dto.some_float, unnamed.2); - let model = &NamedStructModel { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let model = &NamedStructModel { some_int: 123, another_int: 127, some_float: 456.0 }; let unnamed: UnnamedStruct = model.try_into().unwrap(); @@ -243,11 +211,7 @@ fn unnamed2named_2_ref() { #[test] fn existing_named2unnamed() { - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.try_into_existing(&mut dto).unwrap(); @@ -256,11 +220,7 @@ fn existing_named2unnamed() { assert_eq!(127, dto.1); assert_eq!(456.0, dto.2); - let named = NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: UnnamedStructModel = Default::default(); named.try_into_existing(&mut model).unwrap(); @@ -292,11 +252,7 @@ fn existing_unnamed2named() { #[test] fn existing_named2unnamed_ref() { - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut dto: UnnamedStructDto = Default::default(); named.try_into_existing(&mut dto).unwrap(); @@ -305,11 +261,7 @@ fn existing_named2unnamed_ref() { assert_eq!(named.another_int, dto.1); assert_eq!(named.some_float, dto.2); - let named = &NamedStruct { - some_int: 123, - another_int: 127, - some_float: 456.0, - }; + let named = &NamedStruct { some_int: 123, another_int: 127, some_float: 456.0 }; let mut model: UnnamedStructModel = Default::default(); named.try_into_existing(&mut model).unwrap(); diff --git a/o2o-tests/tests/9_child_attr_tests.rs b/o2o-tests/tests/9_child_attr_tests.rs index bc74d61..b72cd17 100644 --- a/o2o-tests/tests/9_child_attr_tests.rs +++ b/o2o-tests/tests/9_child_attr_tests.rs @@ -67,14 +67,7 @@ struct EntityDto { #[map(TupleEntity)] #[into_existing(TupleEntity)] #[children(1: TupleBaseEntity, 1 .0: TupleBase, 2: TupleChild)] -struct TupleEntityDto( - i32, - #[o2o(child(1 .0), map(0))] i32, - #[o2o(child(1 .0), map(1))] i16, - #[o2o(child(1), map(1))] i32, - #[o2o(child(2), map(0))] i32, - #[o2o(child(2), map(1))] i16, -); +struct TupleEntityDto(i32, #[o2o(child(1 .0), map(0))] i32, #[o2o(child(1 .0), map(1))] i16, #[o2o(child(1), map(1))] i32, #[o2o(child(2), map(0))] i32, #[o2o(child(2), map(1))] i16); #[test] fn named2named() { @@ -104,17 +97,10 @@ fn named2named_reverse() { let entity = Entity { parent_int: 123, base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - some_string: "Test".into(), - }, + base: Base { base_int_2: 321, another_base_int: 456, some_string: "Test".into() }, base_entity_int: 654, }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -156,17 +142,10 @@ fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, base: BaseEntity { - base: Base { - base_int_2: 321, - another_base_int: 456, - some_string: "Test".into(), - }, + base: Base { base_int_2: 321, another_base_int: 456, some_string: "Test".into() }, base_entity_int: 654, }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.into(); @@ -196,11 +175,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); @@ -228,11 +203,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.into(); diff --git a/o2o-tests/tests/9_child_attr_tests_fallible.rs b/o2o-tests/tests/9_child_attr_tests_fallible.rs index b169c56..f8fc36f 100644 --- a/o2o-tests/tests/9_child_attr_tests_fallible.rs +++ b/o2o-tests/tests/9_child_attr_tests_fallible.rs @@ -67,14 +67,7 @@ struct EntityDto { #[try_map(TupleEntity, String)] #[try_into_existing(TupleEntity, String)] #[children(1: TupleBaseEntity, 1 .0: TupleBase, 2: TupleChild)] -struct TupleEntityDto( - i32, - #[o2o(child(1 .0), map(0))] i32, - #[o2o(child(1 .0), map(1))] i16, - #[o2o(child(1), map(1))] i32, - #[o2o(child(2), map(0))] i32, - #[o2o(child(2), map(1))] i16, -); +struct TupleEntityDto(i32, #[o2o(child(1 .0), map(0))] i32, #[o2o(child(1 .0), map(1))] i16, #[o2o(child(1), map(1))] i32, #[o2o(child(2), map(0))] i32, #[o2o(child(2), map(1))] i16); #[test] fn named2named() { @@ -111,10 +104,7 @@ fn named2named_reverse() { }, base_entity_int: 654, }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -163,10 +153,7 @@ fn named2named_reverse_ref() { }, base_entity_int: 654, }, - child: Child { - child_int: 789, - another_child_int: 987, - }, + child: Child { child_int: 789, another_child_int: 987 }, }; let dto: EntityDto = entity.try_into().unwrap(); @@ -196,11 +183,7 @@ fn unnamed2unnamed() { #[test] fn unnamed2unnamed_reverse() { - let entity = TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); @@ -228,11 +211,7 @@ fn unnamed2unnamed_ref() { #[test] fn unnamed2unnamed_reverse_ref() { - let entity = &TupleEntity( - 123, - TupleBaseEntity(TupleBase(321, 456), 654), - TupleChild(789, 987), - ); + let entity = &TupleEntity(123, TupleBaseEntity(TupleBase(321, 456), 654), TupleChild(789, 987)); let dto: TupleEntityDto = entity.try_into().unwrap(); diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..d2904cf --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,5 @@ +max_width = 300 +struct_lit_width = 75 +array_width = 100 +chain_width = 200 +fn_call_width = 250 \ No newline at end of file