| 1 | #![cfg_attr(docsrs, doc(cfg(feature = "borsh")))] |
| 2 | |
| 3 | use craterust-analyzer cargo ordermap 1.2.0 crate/::{OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#, OrderSetrust-analyzer cargo ordermap 1.2.0 set/OrderSet#}; |
| 4 | use borshrust-analyzer cargo borsh 1.6.1 crate/::iorust-analyzer cargo borsh 1.6.1 io/::{Readrust-analyzer cargo borsh 1.6.1 nostd_io/Read#, Resultrust-analyzer cargo borsh 1.6.1 nostd_io/Result#, Writerust-analyzer cargo borsh 1.6.1 nostd_io/Write#}; |
| 5 | use borshrust-analyzer cargo borsh 1.6.1 crate/::{BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#, BorshSerializerust-analyzer cargo borsh 1.6.1 ser/BorshSerialize#}; |
| 6 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#; |
| 7 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#; |
| 8 | |
| 9 | impl<K, V, S> BorshSerializerust-analyzer cargo borsh 1.6.1 ser/BorshSerialize# for OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#<K, V, S> |
| 10 | where |
| 11 | K: BorshSerializerust-analyzer cargo borsh 1.6.1 ser/BorshSerialize#, |
| 12 | V: BorshSerializerust-analyzer cargo borsh 1.6.1 ser/BorshSerialize#, |
| 13 | { |
| 14 | #[inline] |
| 15 | fn serializerust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderMap<K, V, S>`][BorshSerialize]serialize().<W: Writerust-analyzer cargo borsh 1.6.1 nostd_io/Write#>(&self, writer: &mut W) -> Resultrust-analyzer cargo borsh 1.6.1 nostd_io/Result#<()> { |
| 16 | self.innerrust-analyzer cargo ordermap 1.2.0 map/OrderMap#inner..serialize(writer) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | impl<K, V, S> BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize# for OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#<K, V, S> |
| 21 | where |
| 22 | K: BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, |
| 23 | V: BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#, |
| 24 | S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, |
| 25 | { |
| 26 | #[inline] |
| 27 | fn deserialize_readerrust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderMap<K, V, S>`][BorshDeserialize]deserialize_reader().<R: Readrust-analyzer cargo borsh 1.6.1 nostd_io/Read#>(reader: &mut R) -> Resultrust-analyzer cargo borsh 1.6.1 nostd_io/Result#<Selfrust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderMap<K, V, S>`][BorshDeserialize]> { |
| 28 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderMap<K, V, S>`][BorshDeserialize] { |
| 29 | innerrust-analyzer cargo ordermap 1.2.0 map/OrderMap#inner.: <_>::deserialize_readerrust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#deserialize_reader().(reader)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 30 | }) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl<T, S> BorshSerializerust-analyzer cargo borsh 1.6.1 ser/BorshSerialize# for OrderSetrust-analyzer cargo ordermap 1.2.0 set/OrderSet#<T, S> |
| 35 | where |
| 36 | T: BorshSerializerust-analyzer cargo borsh 1.6.1 ser/BorshSerialize#, |
| 37 | { |
| 38 | #[inline] |
| 39 | fn serializerust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderSet<T, S>`][BorshSerialize]serialize().<W: Writerust-analyzer cargo borsh 1.6.1 nostd_io/Write#>(&self, writer: &mut W) -> Resultrust-analyzer cargo borsh 1.6.1 nostd_io/Result#<()> { |
| 40 | self.innerrust-analyzer cargo ordermap 1.2.0 set/OrderSet#inner..serialize(writer) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl<T, S> BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize# for OrderSetrust-analyzer cargo ordermap 1.2.0 set/OrderSet#<T, S> |
| 45 | where |
| 46 | T: BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, |
| 47 | S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, |
| 48 | { |
| 49 | #[inline] |
| 50 | fn deserialize_readerrust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderSet<T, S>`][BorshDeserialize]deserialize_reader().<R: Readrust-analyzer cargo borsh 1.6.1 nostd_io/Read#>(reader: &mut R) -> Resultrust-analyzer cargo borsh 1.6.1 nostd_io/Result#<Selfrust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderSet<T, S>`][BorshDeserialize]> { |
| 51 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo ordermap 1.2.0 borsh/impl#[`OrderSet<T, S>`][BorshDeserialize] { |
| 52 | innerrust-analyzer cargo ordermap 1.2.0 set/OrderSet#inner.: <_>::deserialize_readerrust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#deserialize_reader().(reader)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | #[cfg(test)] |
| 58 | mod borsh_testsrust-analyzer cargo ordermap 1.2.0 borsh/borsh_tests/ { |
| 59 | use superrust-analyzer cargo ordermap 1.2.0 borsh/::*; |
| 60 | |
| 61 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 62 | fn map_borsh_roundtriprust-analyzer cargo ordermap 1.2.0 borsh/borsh_tests/map_borsh_roundtrip().() { |
| 63 | let original_map: OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#<i32, i32> = { |
| 64 | let mut map = OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#::newrust-analyzer cargo ordermap 1.2.0 map/impl#[`OrderMap<K, V>`]new().(); |
| 65 | map.insertrust-analyzer cargo ordermap 1.2.0 map/impl#[`OrderMap<K, V, S>`]insert().(1, 2); |
| 66 | map.insertrust-analyzer cargo ordermap 1.2.0 map/impl#[`OrderMap<K, V, S>`]insert().(3, 4); |
| 67 | map.insertrust-analyzer cargo ordermap 1.2.0 map/impl#[`OrderMap<K, V, S>`]insert().(5, 6); |
| 68 | map |
| 69 | }; |
| 70 | let serialized_map = borshrust-analyzer cargo borsh 1.6.1 crate/::to_vecrust-analyzer cargo borsh 1.6.1 ser/helpers/to_vec().(&original_map).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 71 | let deserialized_map: OrderMaprust-analyzer cargo ordermap 1.2.0 map/OrderMap#<i32, i32> = |
| 72 | BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#::try_from_slicerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#try_from_slice().(&serialized_map).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 73 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(original_map, deserialized_map); |
| 74 | } |
| 75 | |
| 76 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 77 | fn set_borsh_roundtriprust-analyzer cargo ordermap 1.2.0 borsh/borsh_tests/set_borsh_roundtrip().() { |
| 78 | let original_map: OrderSetrust-analyzer cargo ordermap 1.2.0 set/OrderSet#<i32> = [1, 2, 3, 4, 5, 6].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 79 | let serialized_map = borshrust-analyzer cargo borsh 1.6.1 crate/::to_vecrust-analyzer cargo borsh 1.6.1 ser/helpers/to_vec().(&original_map).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 80 | let deserialized_map: OrderSetrust-analyzer cargo ordermap 1.2.0 set/OrderSet#<i32> = |
| 81 | BorshDeserializerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#::try_from_slicerust-analyzer cargo borsh 1.6.1 de/BorshDeserialize#try_from_slice().(&serialized_map).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 82 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(original_map, deserialized_map); |
| 83 | } |
| 84 | } |