summaryrefslogtreecommitdiff
path: root/examples/10-transient-0/output/rust/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/10-transient-0/output/rust/src/lib.rs')
-rw-r--r--examples/10-transient-0/output/rust/src/lib.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/10-transient-0/output/rust/src/lib.rs b/examples/10-transient-0/output/rust/src/lib.rs
new file mode 100644
index 0000000..865555e
--- /dev/null
+++ b/examples/10-transient-0/output/rust/src/lib.rs
@@ -0,0 +1,33 @@
+pub mod data;
+
+#[cfg(test)]
+mod test {
+ use std::io::Cursor;
+ use super::data::StructWithInt32;
+ use super::data::StructWithInt64;
+
+ #[test]
+ fn struct_with_int_32() {
+ let value = StructWithInt32 { a: 10, b: 25 };
+
+ assert_round_trip_encoding(
+ value,
+ super::data::transient_0::encode_struct_with_int_32,
+ super::data::transient_0::decode_struct_with_int_32,
+ );
+ }
+
+ fn assert_round_trip_encoding<T: std::cmp::PartialEq + std::fmt::Debug>(
+ value: T,
+ encode: impl Fn(&T, &mut Cursor<Vec<u8>>),
+ decode: impl Fn(&mut Cursor<Vec<u8>>) -> T,
+ ) {
+ let mut bytes = Cursor::new(Vec::new());
+ encode(&value, &mut bytes);
+
+ bytes.set_position(0);
+ let decoded_value = decode(&mut bytes);
+
+ assert_eq!(value, decoded_value);
+ }
+}