From d9374240857b256f66e9d3f84e1bf4747761ed1f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 24 Jul 2026 14:56:52 +0100 Subject: Replace OuterStruct with StructWithStruct --- .../10-transient-0/output/rust/src/gen/data.rs | 14 +++------- .../output/rust/src/gen/data/transient_0.rs | 30 +++++++--------------- examples/10-transient-0/output/rust/src/lib.rs | 16 ++++++------ 3 files changed, 21 insertions(+), 39 deletions(-) (limited to 'examples/10-transient-0/output/rust') diff --git a/examples/10-transient-0/output/rust/src/gen/data.rs b/examples/10-transient-0/output/rust/src/gen/data.rs index 814e4ca..ccabce6 100644 --- a/examples/10-transient-0/output/rust/src/gen/data.rs +++ b/examples/10-transient-0/output/rust/src/gen/data.rs @@ -25,27 +25,21 @@ pub struct StructWithString { } #[derive(Debug, PartialEq)] -pub struct OuterStruct { - pub inner: crate::data::InnerStruct, +pub struct StructWithStruct { + pub inner: crate::data::StructWithInt32, pub c: ::core::primitive::i32, } -#[derive(Debug, PartialEq)] -pub struct InnerStruct { - pub a: ::core::primitive::i32, - pub b: ::core::primitive::i32, -} - #[derive(Debug, PartialEq)] pub struct StructWithList { pub a: ::std::vec::Vec::<::core::primitive::i64>, - pub b: ::std::vec::Vec::, + pub b: ::std::vec::Vec::, } #[derive(Debug, PartialEq)] pub struct StructWithOption { pub a: ::std::option::Option::<::core::primitive::i64>, - pub b: ::std::option::Option::, + pub b: ::std::option::Option::, } #[derive(Debug, PartialEq)] diff --git a/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs b/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs index 2caeb3a..c1ded4c 100644 --- a/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs +++ b/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs @@ -48,28 +48,16 @@ pub fn decode_struct_with_string(reader: &mut impl std::io::Read) -> ::std::io:: std::io::Result::Ok(crate::data::StructWithString { a: a, b: b }) } -pub fn encode_outer_struct(value: &crate::data::OuterStruct, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_inner_struct(&value.inner, writer)?; +pub fn encode_struct_with_struct(value: &crate::data::StructWithStruct, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { + crate::data::transient_0::encode_struct_with_int_32(&value.inner, writer)?; crate::transient_0::encode_int_32(&value.c, writer)?; ::std::io::Result::Ok(()) } -pub fn decode_outer_struct(reader: &mut impl std::io::Read) -> ::std::io::Result:: { - let inner = crate::data::transient_0::decode_inner_struct(reader)?; +pub fn decode_struct_with_struct(reader: &mut impl std::io::Read) -> ::std::io::Result:: { + let inner = crate::data::transient_0::decode_struct_with_int_32(reader)?; let c = crate::transient_0::decode_int_32(reader)?; - std::io::Result::Ok(crate::data::OuterStruct { inner: inner, c: c }) -} - -pub fn encode_inner_struct(value: &crate::data::InnerStruct, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_32(&value.a, writer)?; - crate::transient_0::encode_int_32(&value.b, writer)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_inner_struct(reader: &mut impl std::io::Read) -> ::std::io::Result:: { - let a = crate::transient_0::decode_int_32(reader)?; - let b = crate::transient_0::decode_int_32(reader)?; - std::io::Result::Ok(crate::data::InnerStruct { a: a, b: b }) + std::io::Result::Ok(crate::data::StructWithStruct { inner: inner, c: c }) } pub fn encode_struct_with_list(value: &crate::data::StructWithList, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { @@ -82,7 +70,7 @@ pub fn encode_struct_with_list(value: &crate::data::StructWithList, writer: &mut { crate::transient_0::encode_int_64(&(((&value.b).len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer)?; for element in &value.b { - crate::data::transient_0::encode_inner_struct(element, writer)?; + crate::data::transient_0::encode_struct_with_int_32(element, writer)?; }; }; ::std::io::Result::Ok(()) @@ -101,7 +89,7 @@ pub fn decode_struct_with_list(reader: &mut impl std::io::Read) -> ::std::io::Re let len = crate::transient_0::decode_int_64(reader)?; let mut elements = ::std::vec::Vec::with_capacity((len.try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?); for _ in 0..len { - elements.push(crate::data::transient_0::decode_inner_struct(reader)?); + elements.push(crate::data::transient_0::decode_struct_with_int_32(reader)?); }; elements }; @@ -121,7 +109,7 @@ pub fn encode_struct_with_option(value: &crate::data::StructWithOption, writer: match &value.b { ::std::option::Option::Some(value) => { crate::transient_0::encode_bool(&true, writer)?; - crate::data::transient_0::encode_inner_struct(&value, writer)?; + crate::data::transient_0::encode_struct_with_int_32(&value, writer)?; }, ::std::option::Option::None => { crate::transient_0::encode_bool(&false, writer)?; @@ -142,7 +130,7 @@ pub fn decode_struct_with_option(reader: &mut impl std::io::Read) -> ::std::io:: let b = { let is_some = crate::transient_0::decode_bool(reader)?; if is_some { - ::std::option::Option::Some(crate::data::transient_0::decode_inner_struct(reader)?) + ::std::option::Option::Some(crate::data::transient_0::decode_struct_with_int_32(reader)?) } else { ::std::option::Option::None } diff --git a/examples/10-transient-0/output/rust/src/lib.rs b/examples/10-transient-0/output/rust/src/lib.rs index 3aa9751..b736203 100644 --- a/examples/10-transient-0/output/rust/src/lib.rs +++ b/examples/10-transient-0/output/rust/src/lib.rs @@ -4,7 +4,7 @@ pub mod transient_0; #[cfg(test)] mod test { use std::io::Cursor; - use super::data::{EnumWithVariants, InnerStruct, OuterStruct, StructWithBool, StructWithInt32, StructWithInt64, StructWithList, StructWithOption, StructWithString, SumWithVariants, VariantOne, VariantTwo }; + use super::data::{EnumWithVariants, StructWithBool, StructWithInt32, StructWithInt64, StructWithList, StructWithOption, StructWithString, StructWithStruct, SumWithVariants, VariantOne, VariantTwo }; #[test] fn struct_with_bool() { @@ -52,12 +52,12 @@ mod test { #[test] fn nested_struct() { - let value = OuterStruct { inner: InnerStruct { a: 10, b: 25 }, c: 42 }; + let value = StructWithStruct { inner: StructWithInt32 { a: 10, b: 25 }, c: 42 }; assert_round_trip_encoding( value, - super::data::transient_0::encode_outer_struct, - super::data::transient_0::decode_outer_struct, + super::data::transient_0::encode_struct_with_struct, + super::data::transient_0::decode_struct_with_struct, ); } @@ -66,9 +66,9 @@ mod test { let value = StructWithList { a: vec![10, 25], b: vec![ - InnerStruct { a: 42, b: 47 }, - InnerStruct { a: 52, b: 57 }, - InnerStruct { a: 62, b: 67 }, + StructWithInt32 { a: 42, b: 47 }, + StructWithInt32 { a: 52, b: 57 }, + StructWithInt32 { a: 62, b: 67 }, ], }; @@ -97,7 +97,7 @@ mod test { fn struct_with_option_some() { let value = StructWithOption { a: Some(10), - b: Some(InnerStruct { a: 42, b: 47 }), + b: Some(StructWithInt32 { a: 42, b: 47 }), }; assert_round_trip_encoding( -- cgit v1.2.3