diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-18 11:08:35 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-18 11:08:35 +0100 |
| commit | b801471a3555e81f59e60d34707cb0fd9b0864d8 (patch) | |
| tree | ab8f19016ccc1c47ae6e04b95c2eec295e254391 /examples/10-transient-0 | |
| parent | 28fee7435236bd1382a9e7281c8875564c607686 (diff) | |
Support String values in rust-transient-0
Diffstat (limited to 'examples/10-transient-0')
| -rw-r--r-- | examples/10-transient-0/output/rust/src/gen/transient_0.rs | 13 | ||||
| -rw-r--r-- | examples/10-transient-0/output/rust/src/lib.rs | 13 |
2 files changed, 23 insertions, 3 deletions
diff --git a/examples/10-transient-0/output/rust/src/gen/transient_0.rs b/examples/10-transient-0/output/rust/src/gen/transient_0.rs index 68aa0eb..24f5c9c 100644 --- a/examples/10-transient-0/output/rust/src/gen/transient_0.rs +++ b/examples/10-transient-0/output/rust/src/gen/transient_0.rs @@ -54,10 +54,19 @@ pub fn decode_int_64(reader: &mut impl std::io::Read) -> ::std::io::Result::<::c } pub fn encode_string(value: &::std::string::String, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { - todo!(); + { + crate::transient_0::encode_int_64(&((value.len()).try_into()).unwrap(), writer)?; + }; + writer.write_all(value.as_bytes())?; ::std::io::Result::Ok(()) } pub fn decode_string(reader: &mut impl std::io::Read) -> ::std::io::Result::<::std::string::String> { - std::io::Result::Ok(todo!()) + let len = crate::transient_0::decode_int_64(reader)?; + let bytes = { + let mut bytes = vec![0u8; (len.try_into()).unwrap()]; + reader.read_exact(&mut bytes)?; + bytes + }; + std::io::Result::Ok((::std::string::String::from_utf8(bytes)).unwrap()) } diff --git a/examples/10-transient-0/output/rust/src/lib.rs b/examples/10-transient-0/output/rust/src/lib.rs index 75a7b47..6ecb19e 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::{InnerStruct, OuterStruct, StructWithBool, StructWithInt32, StructWithInt64}; + use super::data::{InnerStruct, OuterStruct, StructWithBool, StructWithInt32, StructWithInt64, StructWithString}; #[test] fn struct_with_bool() { @@ -40,6 +40,17 @@ mod test { } #[test] + fn struct_with_string() { + let value = StructWithString { a: "abc".to_string(), b: "def".to_string() }; + + assert_round_trip_encoding( + value, + super::data::transient_0::encode_struct_with_string, + super::data::transient_0::decode_struct_with_string, + ); + } + + #[test] fn nested_struct() { let value = OuterStruct { inner: InnerStruct { a: 10, b: 25 }, c: 42 }; |
