diff --git a/lib/xdrgen/generators/rust.rb b/lib/xdrgen/generators/rust.rb index 13120d835..8a4d36a37 100644 --- a/lib/xdrgen/generators/rust.rb +++ b/lib/xdrgen/generators/rust.rb @@ -250,13 +250,27 @@ def render_enum_of_all_types(out, types) } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { #{types.map { |t| "TypeVariant::#{t} => Ok(Self::#{t}(Box::new(serde_json::from_reader(r)?)))," }.join("\n")} } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + #{types.map { |t| "TypeVariant::#{t} => Ok(Self::#{t}(Box::new(serde::de::Deserialize::deserialize(r)?)))," }.join("\n")} + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs index c7f9cf95b..6bb6392dc 100644 --- a/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/block_comments.x/MyXDR.rs @@ -3030,13 +3030,27 @@ impl Type { } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/const.x/MyXDR.rs b/spec/output/generator_spec_rust/const.x/MyXDR.rs index 80670d3ce..966b54a40 100644 --- a/spec/output/generator_spec_rust/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/const.x/MyXDR.rs @@ -2969,14 +2969,29 @@ TypeVariant::TestArray2 => Box::new(ReadXdrIter::<_, TestArray2>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde_json::from_reader(r)?))), TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/enum.x/MyXDR.rs b/spec/output/generator_spec_rust/enum.x/MyXDR.rs index 093bb05a7..9968bbd13 100644 --- a/spec/output/generator_spec_rust/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/enum.x/MyXDR.rs @@ -3480,8 +3480,14 @@ TypeVariant::Color3 => Box::new(ReadXdrIter::<_, Color3>::new(dec, r.limits.clon } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde_json::from_reader(r)?))), TypeVariant::Color => Ok(Self::Color(Box::new(serde_json::from_reader(r)?))), @@ -3490,6 +3496,17 @@ TypeVariant::Color3 => Ok(Self::Color3(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color => Ok(Self::Color(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color2 => Ok(Self::Color2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color3 => Ok(Self::Color3(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs index e08690046..4cdff6d8b 100644 --- a/spec/output/generator_spec_rust/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/nesting.x/MyXDR.rs @@ -3305,8 +3305,14 @@ TypeVariant::MyUnionTwo => Box::new(ReadXdrIter::<_, MyUnionTwo>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde_json::from_reader(r)?))), TypeVariant::Foo => Ok(Self::Foo(Box::new(serde_json::from_reader(r)?))), @@ -3316,6 +3322,18 @@ TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde_json::from_reader( } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Foo => Ok(Self::Foo(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnionOne => Ok(Self::MyUnionOne(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/optional.x/MyXDR.rs b/spec/output/generator_spec_rust/optional.x/MyXDR.rs index 0f29a0a45..b9454b181 100644 --- a/spec/output/generator_spec_rust/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/optional.x/MyXDR.rs @@ -2999,14 +2999,29 @@ TypeVariant::HasOptions => Box::new(ReadXdrIter::<_, HasOptions>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Arr => Ok(Self::Arr(Box::new(serde_json::from_reader(r)?))), TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Arr => Ok(Self::Arr(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/struct.x/MyXDR.rs b/spec/output/generator_spec_rust/struct.x/MyXDR.rs index 1e6a82b74..696a6f49a 100644 --- a/spec/output/generator_spec_rust/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/struct.x/MyXDR.rs @@ -3007,14 +3007,29 @@ TypeVariant::MyStruct => Box::new(ReadXdrIter::<_, MyStruct>::new(dec, r.limits. } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde_json::from_reader(r)?))), TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/test.x/MyXDR.rs b/spec/output/generator_spec_rust/test.x/MyXDR.rs index 6b43a7501..5d234038f 100644 --- a/spec/output/generator_spec_rust/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/test.x/MyXDR.rs @@ -4916,8 +4916,14 @@ TypeVariant::NesterNestedUnion => Box::new(ReadXdrIter::<_, NesterNestedUnion>:: } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde_json::from_reader(r)?))), TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde_json::from_reader(r)?))), @@ -4945,6 +4951,36 @@ TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde_json } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Uint514 => Ok(Self::Uint514(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Str => Ok(Self::Str(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Str2 => Ok(Self::Str2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hash => Ok(Self::Hash(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes1 => Ok(Self::Hashes1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes2 => Ok(Self::Hashes2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes3 => Ok(Self::Hashes3(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::OptHash1 => Ok(Self::OptHash1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::OptHash2 => Ok(Self::OptHash2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int1 => Ok(Self::Int1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int2 => Ok(Self::Int2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int3 => Ok(Self::Int3(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int4 => Ok(Self::Int4(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::LotsOfMyStructs => Ok(Self::LotsOfMyStructs(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::HasStuff => Ok(Self::HasStuff(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color => Ok(Self::Color(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Nester => Ok(Self::Nester(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedEnum => Ok(Self::NesterNestedEnum(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedStruct => Ok(Self::NesterNestedStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust/union.x/MyXDR.rs b/spec/output/generator_spec_rust/union.x/MyXDR.rs index eb96312c0..ad02b2966 100644 --- a/spec/output/generator_spec_rust/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust/union.x/MyXDR.rs @@ -3391,8 +3391,14 @@ TypeVariant::IntUnion2 => Box::new(ReadXdrIter::<_, IntUnion2>::new(dec, r.limit } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::SError => Ok(Self::SError(Box::new(serde_json::from_reader(r)?))), TypeVariant::Multi => Ok(Self::Multi(Box::new(serde_json::from_reader(r)?))), @@ -3403,6 +3409,19 @@ TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde_json::from_reader(r) } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::SError => Ok(Self::SError(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Multi => Ok(Self::Multi(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::IntUnion => Ok(Self::IntUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/block_comments.x/MyXDR.rs index c7f9cf95b..6bb6392dc 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/block_comments.x/MyXDR.rs @@ -3030,13 +3030,27 @@ impl Type { } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/const.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/const.x/MyXDR.rs index 80670d3ce..966b54a40 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/const.x/MyXDR.rs @@ -2969,14 +2969,29 @@ TypeVariant::TestArray2 => Box::new(ReadXdrIter::<_, TestArray2>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde_json::from_reader(r)?))), TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/enum.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/enum.x/MyXDR.rs index 7b37f5d9c..62d418406 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/enum.x/MyXDR.rs @@ -3479,8 +3479,14 @@ TypeVariant::Color3 => Box::new(ReadXdrIter::<_, Color3>::new(dec, r.limits.clon } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde_json::from_reader(r)?))), TypeVariant::Color => Ok(Self::Color(Box::new(serde_json::from_reader(r)?))), @@ -3489,6 +3495,17 @@ TypeVariant::Color3 => Ok(Self::Color3(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color => Ok(Self::Color(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color2 => Ok(Self::Color2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color3 => Ok(Self::Color3(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/nesting.x/MyXDR.rs index a4e145120..81767aed3 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/nesting.x/MyXDR.rs @@ -3303,8 +3303,14 @@ TypeVariant::MyUnionTwo => Box::new(ReadXdrIter::<_, MyUnionTwo>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde_json::from_reader(r)?))), TypeVariant::Foo => Ok(Self::Foo(Box::new(serde_json::from_reader(r)?))), @@ -3314,6 +3320,18 @@ TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde_json::from_reader( } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Foo => Ok(Self::Foo(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnionOne => Ok(Self::MyUnionOne(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/optional.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/optional.x/MyXDR.rs index 9e34e30c8..0848b0a4a 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/optional.x/MyXDR.rs @@ -2998,14 +2998,29 @@ TypeVariant::HasOptions => Box::new(ReadXdrIter::<_, HasOptions>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Arr => Ok(Self::Arr(Box::new(serde_json::from_reader(r)?))), TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Arr => Ok(Self::Arr(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/struct.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/struct.x/MyXDR.rs index b7db61fc8..e43738634 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/struct.x/MyXDR.rs @@ -3006,14 +3006,29 @@ TypeVariant::MyStruct => Box::new(ReadXdrIter::<_, MyStruct>::new(dec, r.limits. } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde_json::from_reader(r)?))), TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/test.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/test.x/MyXDR.rs index cc984fe0f..c16a6f4f9 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/test.x/MyXDR.rs @@ -4914,8 +4914,14 @@ TypeVariant::NesterNestedUnion => Box::new(ReadXdrIter::<_, NesterNestedUnion>:: } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde_json::from_reader(r)?))), TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde_json::from_reader(r)?))), @@ -4943,6 +4949,36 @@ TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde_json } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Uint514 => Ok(Self::Uint514(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Str => Ok(Self::Str(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Str2 => Ok(Self::Str2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hash => Ok(Self::Hash(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes1 => Ok(Self::Hashes1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes2 => Ok(Self::Hashes2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes3 => Ok(Self::Hashes3(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::OptHash1 => Ok(Self::OptHash1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::OptHash2 => Ok(Self::OptHash2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int1 => Ok(Self::Int1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int2 => Ok(Self::Int2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int3 => Ok(Self::Int3(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int4 => Ok(Self::Int4(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::LotsOfMyStructs => Ok(Self::LotsOfMyStructs(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::HasStuff => Ok(Self::HasStuff(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color => Ok(Self::Color(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Nester => Ok(Self::Nester(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedEnum => Ok(Self::NesterNestedEnum(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedStruct => Ok(Self::NesterNestedStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_jsonschema_impls/union.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_jsonschema_impls/union.x/MyXDR.rs index 093cea099..d0b2a427a 100644 --- a/spec/output/generator_spec_rust_custom_jsonschema_impls/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_jsonschema_impls/union.x/MyXDR.rs @@ -3389,8 +3389,14 @@ TypeVariant::IntUnion2 => Box::new(ReadXdrIter::<_, IntUnion2>::new(dec, r.limit } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::SError => Ok(Self::SError(Box::new(serde_json::from_reader(r)?))), TypeVariant::Multi => Ok(Self::Multi(Box::new(serde_json::from_reader(r)?))), @@ -3401,6 +3407,19 @@ TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde_json::from_reader(r) } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::SError => Ok(Self::SError(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Multi => Ok(Self::Multi(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::IntUnion => Ok(Self::IntUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs index c7f9cf95b..6bb6392dc 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/block_comments.x/MyXDR.rs @@ -3030,13 +3030,27 @@ impl Type { } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs index 80670d3ce..966b54a40 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/const.x/MyXDR.rs @@ -2969,14 +2969,29 @@ TypeVariant::TestArray2 => Box::new(ReadXdrIter::<_, TestArray2>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde_json::from_reader(r)?))), TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs index d900ec353..3a63ac95d 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/enum.x/MyXDR.rs @@ -3480,8 +3480,14 @@ TypeVariant::Color3 => Box::new(ReadXdrIter::<_, Color3>::new(dec, r.limits.clon } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde_json::from_reader(r)?))), TypeVariant::Color => Ok(Self::Color(Box::new(serde_json::from_reader(r)?))), @@ -3490,6 +3496,17 @@ TypeVariant::Color3 => Ok(Self::Color3(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color => Ok(Self::Color(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color2 => Ok(Self::Color2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color3 => Ok(Self::Color3(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs index cf7a2d6a0..fd6a7b54f 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/nesting.x/MyXDR.rs @@ -3305,8 +3305,14 @@ TypeVariant::MyUnionTwo => Box::new(ReadXdrIter::<_, MyUnionTwo>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde_json::from_reader(r)?))), TypeVariant::Foo => Ok(Self::Foo(Box::new(serde_json::from_reader(r)?))), @@ -3316,6 +3322,18 @@ TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde_json::from_reader( } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Foo => Ok(Self::Foo(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnionOne => Ok(Self::MyUnionOne(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs index 4def34ed7..d4fed65d3 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/optional.x/MyXDR.rs @@ -2999,14 +2999,29 @@ TypeVariant::HasOptions => Box::new(ReadXdrIter::<_, HasOptions>::new(dec, r.lim } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Arr => Ok(Self::Arr(Box::new(serde_json::from_reader(r)?))), TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Arr => Ok(Self::Arr(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs index 6278822dd..882f72e13 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/struct.x/MyXDR.rs @@ -3007,14 +3007,29 @@ TypeVariant::MyStruct => Box::new(ReadXdrIter::<_, MyStruct>::new(dec, r.limits. } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde_json::from_reader(r)?))), TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde_json::from_reader(r)?))), } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs index bacfd42ed..52d6e3d11 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/test.x/MyXDR.rs @@ -4916,8 +4916,14 @@ TypeVariant::NesterNestedUnion => Box::new(ReadXdrIter::<_, NesterNestedUnion>:: } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde_json::from_reader(r)?))), TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde_json::from_reader(r)?))), @@ -4945,6 +4951,36 @@ TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde_json } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Uint514 => Ok(Self::Uint514(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Str => Ok(Self::Str(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Str2 => Ok(Self::Str2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hash => Ok(Self::Hash(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes1 => Ok(Self::Hashes1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes2 => Ok(Self::Hashes2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Hashes3 => Ok(Self::Hashes3(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::OptHash1 => Ok(Self::OptHash1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::OptHash2 => Ok(Self::OptHash2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int1 => Ok(Self::Int1(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int2 => Ok(Self::Int2(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int3 => Ok(Self::Int3(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Int4 => Ok(Self::Int4(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::LotsOfMyStructs => Ok(Self::LotsOfMyStructs(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::HasStuff => Ok(Self::HasStuff(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Color => Ok(Self::Color(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Nester => Ok(Self::Nester(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedEnum => Ok(Self::NesterNestedEnum(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedStruct => Ok(Self::NesterNestedStruct(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)] diff --git a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs index 3f8552c43..946a36cc9 100644 --- a/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs +++ b/spec/output/generator_spec_rust_custom_str_impls/union.x/MyXDR.rs @@ -3391,8 +3391,14 @@ TypeVariant::IntUnion2 => Box::new(ReadXdrIter::<_, IntUnion2>::new(dec, r.limit } #[cfg(all(feature = "std", feature = "serde_json"))] - #[allow(clippy::too_many_lines)] + #[deprecated(note = "use from_json")] pub fn read_json(v: TypeVariant, r: impl Read) -> Result { + Self::from_json(v, r) + } + + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn from_json(v: TypeVariant, r: impl Read) -> Result { match v { TypeVariant::SError => Ok(Self::SError(Box::new(serde_json::from_reader(r)?))), TypeVariant::Multi => Ok(Self::Multi(Box::new(serde_json::from_reader(r)?))), @@ -3403,6 +3409,19 @@ TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde_json::from_reader(r) } } + #[cfg(all(feature = "std", feature = "serde_json"))] + #[allow(clippy::too_many_lines)] + pub fn deserialize_json<'r, R: serde_json::de::Read<'r>>(v: TypeVariant, r: &mut serde_json::de::Deserializer) -> Result { + match v { + TypeVariant::SError => Ok(Self::SError(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::Multi => Ok(Self::Multi(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::IntUnion => Ok(Self::IntUnion(Box::new(serde::de::Deserialize::deserialize(r)?))), +TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde::de::Deserialize::deserialize(r)?))), + } + } + #[cfg(feature = "alloc")] #[must_use] #[allow(clippy::too_many_lines)]