mirror of https://git.sr.ht/~stygianentity/bincode
20 lines
438 B
Rust
20 lines
438 B
Rust
#[derive(bincode::Encodable, PartialEq, Debug)]
|
|
pub struct Test {
|
|
a: i32,
|
|
b: u32,
|
|
c: u8,
|
|
}
|
|
|
|
#[test]
|
|
fn test_encodable() {
|
|
let start = Test {
|
|
a: 5i32,
|
|
b: 10u32,
|
|
c: 20u8,
|
|
};
|
|
let mut slice = [0u8; 1024];
|
|
let bytes_written = bincode::encode_into_slice(start, &mut slice).unwrap();
|
|
assert_eq!(bytes_written, 9);
|
|
assert_eq!(&slice[..bytes_written], &[5, 0, 0, 0, 10, 0, 0, 0, 20]);
|
|
}
|