Skip to content

Commit

Permalink
Removed some comments & cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kabergstrom committed Aug 11, 2020
1 parent 57e6866 commit fb5e01d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
22 changes: 11 additions & 11 deletions examples/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use serde_diff::{Apply, Diff, SerdeDiff};

#[derive(SerdeDiff, Serialize, Deserialize, PartialEq, Debug)]
enum TestEnum {
Structish {x : u32, y: u32},
Enumish (i32, i32, i32),
Structish { x: u32, y: u32 },
Enumish(i32, i32, i32),
Unitish,
}

Expand All @@ -19,7 +19,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut deserializer = serde_json::Deserializer::from_str(&json_data);
let mut target = TestEnum::Structish { x: 0, y: 4 };
Apply::apply(&mut deserializer, &mut target)?;

let result = TestEnum::Structish { x: 8, y: 4 };
assert_eq!(result, target);
}
Expand All @@ -31,30 +31,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let json_data = serde_json::to_string(&Diff::serializable(&old, &new))?;
let mut deserializer = serde_json::Deserializer::from_str(&json_data);
let mut target = TestEnum::Enumish ( 1, 2, 3);
let mut target = TestEnum::Enumish(1, 2, 3);
Apply::apply(&mut deserializer, &mut target)?;
/* we can't apply changes from one enum variant
/* we can't apply changes from one enum variant
to another, as there may be unfilled fields with no sane defaults,
should there be an error? probably.*/
let result = TestEnum::Enumish ( 1, 2, 3);
let result = TestEnum::Enumish(1, 2, 3);
assert_eq!(result, target);
}
{
let old = TestEnum::Enumish (1, 2, 3);
let new = TestEnum::Enumish (1, 10, 3);
let old = TestEnum::Enumish(1, 2, 3);
let new = TestEnum::Enumish(1, 10, 3);
let json_data = serde_json::to_string(&Diff::serializable(&old, &new))?;
let mut deserializer = serde_json::Deserializer::from_str(&json_data);
let mut target = TestEnum::Enumish ( 4, 3, 2);
let mut target = TestEnum::Enumish(4, 3, 2);
Apply::apply(&mut deserializer, &mut target)?;
let result = TestEnum::Enumish (4, 10, 2);
let result = TestEnum::Enumish(4, 10, 2);
assert_eq!(result, target);
}
{
let old = TestEnum::Structish { x: 5, y: 2 };
let new = TestEnum::Unitish;
let json_data = serde_json::to_string(&Diff::serializable(&old, &new))?;
let mut deserializer = serde_json::Deserializer::from_str(&json_data);
let mut target = TestEnum::Enumish ( 1, 2, 3);
let mut target = TestEnum::Enumish(1, 2, 3);
Apply::apply(&mut deserializer, &mut target)?;
let result = TestEnum::Unitish;
assert_eq!(result, target);
Expand Down
22 changes: 11 additions & 11 deletions examples/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ struct Test3Struct;

#[derive(SerdeDiff, Serialize, Deserialize, PartialEq, Debug)]
struct Test4Struct<T>
where T: SerdeDiff
where
T: SerdeDiff,
{
a: T,
}
Expand All @@ -34,18 +35,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(result, target);
}
{
let old = Test2Struct (1, 2, 3);
let new = Test2Struct (
let old = Test2Struct(1, 2, 3);
let new = Test2Struct(
5, // Differs from old.0, will be serialized
2,
3
2, 3,
);
let mut target = Test2Struct (4,5,6);
let mut target = Test2Struct(4, 5, 6);
let json_data = serde_json::to_string(&Diff::serializable(&old, &new))?;
let mut deserializer = serde_json::Deserializer::from_str(&json_data);
Apply::apply(&mut deserializer, &mut target)?;

let result = Test2Struct ( 5,5,6 );
let result = Test2Struct(5, 5, 6);
assert_eq!(result, target);
}
{
Expand All @@ -60,14 +60,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(result, target);
}
{
let old = Test4Struct { a: 5};
let new = Test4Struct { a: 7};
let mut target = Test4Struct { a: 10};
let old = Test4Struct { a: 5 };
let new = Test4Struct { a: 7 };
let mut target = Test4Struct { a: 10 };
let json_data = serde_json::to_string(&Diff::serializable(&old, &new))?;
let mut deserializer = serde_json::Deserializer::from_str(&json_data);
Apply::apply(&mut deserializer, &mut target)?;

let result = Test4Struct { a: 7};
let result = Test4Struct { a: 7 };
assert_eq!(result, target);
}
Ok(())
Expand Down
4 changes: 1 addition & 3 deletions serde-diff-derive/src/serde_diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn macro_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
} else {
// Go ahead and generate the code
match generate(&input, struct_args) {
//Ok(v) => {eprintln!("{}", v); v},
Ok(v) => v,
Err(v) => v,
}
Expand All @@ -31,7 +30,6 @@ pub fn macro_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
} else {
// Go ahead and generate the code
match generate(&input, struct_args) {
//Ok(v) => {eprintln!("{}", v); v},
Ok(v) => v,
Err(v) => v,
}
Expand Down Expand Up @@ -270,7 +268,7 @@ fn generate_arms(name: &syn::Ident, variant: Option<&syn::Ident>, fields: &syn::
while let Some(element) = ctx.next_path_element(seq)? {
match element {
#(#apply_fn_field_handlers)*
_ => ctx.skip_value(seq)?
_ => ctx.skip_value(seq)?
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ impl<'a, S: SerializeSeq> DiffContext<'a, S> {
self.element_stack
.as_mut()
.unwrap()
.push(ElementStackEntry::PathElement(DiffPathElementValue::EnumVariant(
Cow::Borrowed(variant_name),
)));
.push(ElementStackEntry::PathElement(
DiffPathElementValue::EnumVariant(Cow::Borrowed(variant_name)),
));
}

pub fn push_full_variant(&mut self) {
self.element_stack
.as_mut()
.unwrap()
.push(ElementStackEntry::PathElement(DiffPathElementValue::FullEnumVariant));
.push(ElementStackEntry::PathElement(
DiffPathElementValue::FullEnumVariant,
));
}

/// Called when we visit a field. If the structure is recursive (i.e. struct within struct,
Expand Down

0 comments on commit fb5e01d

Please sign in to comment.