From 7eed843944a247a99e48bdb6f9dc3aac17d983c5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 18 Jul 2026 19:32:20 +0100 Subject: Support options in rust-transient-0 --- examples/10-transient-0/output/rust/src/lib.rs | 30 +++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'examples/10-transient-0/output/rust/src/lib.rs') diff --git a/examples/10-transient-0/output/rust/src/lib.rs b/examples/10-transient-0/output/rust/src/lib.rs index a06f73e..3de2597 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, StructWithList, StructWithString}; + use super::data::{InnerStruct, OuterStruct, StructWithBool, StructWithInt32, StructWithInt64, StructWithList, StructWithOption, StructWithString}; #[test] fn struct_with_bool() { @@ -79,6 +79,34 @@ mod test { ); } + #[test] + fn struct_with_option_none() { + let value = StructWithOption { + a: None, + b: None, + }; + + assert_round_trip_encoding( + value, + super::data::transient_0::encode_struct_with_option, + super::data::transient_0::decode_struct_with_option, + ); + } + + #[test] + fn struct_with_option_some() { + let value = StructWithOption { + a: Some(10), + b: Some(InnerStruct { a: 42, b: 47 }), + }; + + assert_round_trip_encoding( + value, + super::data::transient_0::encode_struct_with_option, + super::data::transient_0::decode_struct_with_option, + ); + } + fn assert_round_trip_encoding( value: T, encode: impl Fn(&T, &mut Cursor>) -> std::io::Result<()>, -- cgit v1.2.3