blob: 56be8caf0f0ec3c076da89658c9a64f0ed552866 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
pub mod data;
pub mod transient_0;
#[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);
}
}
|