Skip to content

Commit

Permalink
fmt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shourya742 committed Jan 14, 2025
1 parent 7338c02 commit ae2807d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
6 changes: 3 additions & 3 deletions utils/sv2_serde_json/examples/derive_macro_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Person {
#[derive(SerJson, DeJson, Debug)]
struct Person2 {
person: Person,
optional_struct: Option<Person>
optional_struct: Option<Person>,
}

#[derive(SerJson, DeJson, Debug)]
Expand All @@ -34,12 +34,12 @@ fn main() {
here: vec!["HEre".to_string()],
check: sv2_serde_json::value::Value::Null,
optional_check: Some(sv2_serde_json::value::Value::Null),
non_optional_check: Some("Hello".to_string())
non_optional_check: Some("Hello".to_string()),
};

let person2 = Person2 {
person: person.clone(),
optional_struct: Some(person.clone())
optional_struct: Some(person.clone()),
};

let person_json = person.to_json_value();
Expand Down
11 changes: 2 additions & 9 deletions utils/sv2_serde_json/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Object(HashMap<String, Value>),
// Null,
// None, // Represents Option::None
// Some(Box<Value>),
// Some(Box<Value>),
// }

// impl Value {
Expand Down Expand Up @@ -238,7 +238,6 @@
// }
// }


// impl TryFrom<&Value> for Value {
// type Error = ();

Expand All @@ -247,7 +246,6 @@
// }
// }


// impl TryFrom<&Value> for u64 {
// type Error = ();

Expand All @@ -264,7 +262,6 @@
// }
// }


// impl<T> From<Option<T>> for Value
// where
// T: Into<Value>,
Expand Down Expand Up @@ -341,7 +338,6 @@
// }
// }


use std::collections::HashMap;

#[derive(Debug, Copy, Clone, PartialEq)]
Expand All @@ -362,7 +358,6 @@ pub enum Value {
Some(Box<Value>),
}


impl Value {
pub fn to_json_string(&self) -> String {
match self {
Expand All @@ -385,10 +380,8 @@ impl Value {
Value::None => {
// Still dicy on this
"\n".to_string()
},
Value::Some(x) => {
x.to_json_string()
}
Value::Some(x) => x.to_json_string(),
}
}

Expand Down
14 changes: 6 additions & 8 deletions utils/sv2_serde_json_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn ser_json_derive(input: TokenStream) -> TokenStream {
Data::Enum(data) => {
let variants = data.variants.iter().map(|variant| {
let var_name = &variant.ident;

if variant.fields.is_empty() {
quote! {
#name::#var_name => {
Expand All @@ -63,7 +62,7 @@ pub fn ser_json_derive(input: TokenStream) -> TokenStream {
}
}
});

quote! {
impl #name {
pub fn to_json_value(&self) -> sv2_serde_json::value::Value {
Expand All @@ -72,14 +71,14 @@ pub fn ser_json_derive(input: TokenStream) -> TokenStream {
}
}
}

impl ToJsonValue for #name {
fn to_json_value(&self) -> sv2_serde_json::value::Value {
self.to_json_value()
}
}
}
}
}
_ => unimplemented!("SerJson is only implemented for structs and enums"),
};

Expand Down Expand Up @@ -130,7 +129,6 @@ pub fn de_json_derive(input: TokenStream) -> TokenStream {
Data::Enum(data) => {
let variants = data.variants.iter().map(|variant| {
let var_name = &variant.ident;

if variant.fields.is_empty() {
quote! {
stringify!(#var_name) => Ok(#name::#var_name),
Expand All @@ -148,7 +146,7 @@ pub fn de_json_derive(input: TokenStream) -> TokenStream {
}
}
});

quote! {
impl #name {
pub fn from_json_value(value: &sv2_serde_json::value::Value) -> Result<Self, ()> {
Expand All @@ -163,15 +161,15 @@ pub fn de_json_derive(input: TokenStream) -> TokenStream {
}
}
}

impl FromJsonValue for #name {
fn from_json_value(value: &sv2_serde_json::value::Value) -> Result<Self, ()> {
Self::from_json_value(value)
}
}
}
}

_ => unimplemented!("DeJson is only implemented for structs and enums"),
};

Expand Down

0 comments on commit ae2807d

Please sign in to comment.