diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-18 19:32:20 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-18 19:33:56 +0100 |
| commit | 7eed843944a247a99e48bdb6f9dc3aac17d983c5 (patch) | |
| tree | 4ffc89b2d33785445809440685fa3e59faed1229 /examples/10-transient-0/output/rust/src/lib.rs | |
| parent | 68b0b81149138dba9fb166c8574fc6d892215a81 (diff) | |
Support options in rust-transient-0
Diffstat (limited to 'examples/10-transient-0/output/rust/src/lib.rs')
| -rw-r--r-- | examples/10-transient-0/output/rust/src/lib.rs | 30 |
1 files changed, 29 insertions, 1 deletions
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<T: std::cmp::PartialEq + std::fmt::Debug>( value: T, encode: impl Fn(&T, &mut Cursor<Vec<u8>>) -> std::io::Result<()>, |
