diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-24 23:32:04 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-24 23:32:04 +0100 |
| commit | 021634785b7c3b82c1203f490813008a95dffa1e (patch) | |
| tree | 061bd96f4f8246b2f45e5b63d216672182e5f97c /examples/11-transient-0/output/rust | |
| parent | 681da8f2c1d85dcda5a676fccaa04415c6adbdcb (diff) | |
Store list of shared values in example
Diffstat (limited to 'examples/11-transient-0/output/rust')
| -rw-r--r-- | examples/11-transient-0/output/rust/src/gen/data.rs | 2 | ||||
| -rw-r--r-- | examples/11-transient-0/output/rust/src/gen/data/transient_0.rs | 16 | ||||
| -rw-r--r-- | examples/11-transient-0/output/rust/src/lib.rs | 6 |
3 files changed, 20 insertions, 4 deletions
diff --git a/examples/11-transient-0/output/rust/src/gen/data.rs b/examples/11-transient-0/output/rust/src/gen/data.rs index df221bb..75efcc8 100644 --- a/examples/11-transient-0/output/rust/src/gen/data.rs +++ b/examples/11-transient-0/output/rust/src/gen/data.rs @@ -91,5 +91,5 @@ pub struct StructWithSum { #[derive(Debug, PartialEq)] pub struct StructWithShared { - pub inner: ::std::sync::Arc::<crate::data::StructWithInt32>, + pub inner: ::std::vec::Vec::<::std::sync::Arc::<crate::data::StructWithInt32>>, } diff --git a/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs b/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs index 52ae7e1..b2f78c2 100644 --- a/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs +++ b/examples/11-transient-0/output/rust/src/gen/data/transient_0.rs @@ -223,11 +223,23 @@ pub fn decode_struct_with_sum(reader: &mut impl std::io::Read) -> ::std::io::Res } pub fn encode_struct_with_shared(value: &crate::data::StructWithShared, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_struct_with_int_32((&value.inner).as_ref(), writer)?; + { + crate::transient_0::encode_int_64(&(((&value.inner).len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer)?; + for element in &value.inner { + crate::data::transient_0::encode_struct_with_int_32(element.as_ref(), writer)?; + }; + }; ::std::io::Result::Ok(()) } pub fn decode_struct_with_shared(reader: &mut impl std::io::Read) -> ::std::io::Result::<crate::data::StructWithShared> { - let inner = ::std::sync::Arc::new(crate::data::transient_0::decode_struct_with_int_32(reader)?); + let inner = { + 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(::std::sync::Arc::new(crate::data::transient_0::decode_struct_with_int_32(reader)?)); + }; + elements + }; std::io::Result::Ok(crate::data::StructWithShared { inner: inner }) } diff --git a/examples/11-transient-0/output/rust/src/lib.rs b/examples/11-transient-0/output/rust/src/lib.rs index 6368af2..6675c4c 100644 --- a/examples/11-transient-0/output/rust/src/lib.rs +++ b/examples/11-transient-0/output/rust/src/lib.rs @@ -171,7 +171,11 @@ mod test { #[test] fn struct_with_shared() { - let value = StructWithShared { inner: Arc::new(StructWithInt32 { a: 10, b: 25 }) }; + let value = StructWithShared { + inner: vec![ + Arc::new(StructWithInt32 { a: 10, b: 25 }), + ], + }; assert_round_trip_encoding( value, |
