1pub use borsh::*;
5
6pub trait BorshSerializeExt {
8 fn serialize_to_vec(&self) -> Vec<u8>;
10}
11
12impl<T: BorshSerialize> BorshSerializeExt for T {
13 fn serialize_to_vec(&self) -> Vec<u8> {
14 let Ok(vec) = borsh::to_vec(self) else {
15 unreachable!("Serializing to a Vec should be infallible");
16 };
17 vec
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[test]
26 fn test_serialize_equal() {
27 let to_seriailze =
28 "this is some cool shizzle I can guarantee that much - t. knower";
29 let serialized_this_lib = to_seriailze.serialize_to_vec();
30 let serialized_borsh_native = borsh::to_vec(&to_seriailze).unwrap();
31 assert_eq!(serialized_this_lib, serialized_borsh_native);
32 }
33}