File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ version = "1.0"
3636[dev-dependencies ]
3737matches = { version = " 0.1" }
3838bencher = " 0.1.4"
39+ borsh = { version = " 1.5.5" , default-features = false , features = [" derive" ] }
3940
4041[[bench ]]
4142name = " extend"
Original file line number Diff line number Diff line change @@ -1428,7 +1428,7 @@ where
14281428 }
14291429}
14301430
1431- #[ cfg( all( feature = "borsh" , not ( feature = "std" ) ) ) ]
1431+ #[ cfg( all( feature = "borsh" ) ) ]
14321432/// Requires crate feature `"borsh"`
14331433impl < const CAP : usize > borsh:: io:: Write for ArrayVec < u8 , CAP > {
14341434 fn write ( & mut self , data : & [ u8 ] ) -> borsh:: io:: Result < usize > {
Original file line number Diff line number Diff line change @@ -46,6 +46,39 @@ mod array_vec {
4646 assert_ser ( & vec, b"\x01 \0 \0 \0 \xef \xbe \xad \xde " ) ;
4747 assert_roundtrip ( & vec) ;
4848 }
49+
50+ #[ test]
51+ fn test_borsh_one_to_one ( ) {
52+ use borsh:: { BorshDeserialize , BorshSerialize } ;
53+ #[ derive( BorshSerialize , BorshDeserialize ) ]
54+ struct Something {
55+ a : String ,
56+ }
57+ let a = Something {
58+ a : "hello" . to_owned ( ) ,
59+ } ;
60+ let mut vec = ArrayVec :: < u8 , 9 > :: new ( ) ;
61+ a. serialize ( & mut vec) . unwrap ( ) ;
62+ let mut test = Vec :: new ( ) ;
63+ a. serialize ( & mut test) . unwrap ( ) ;
64+ assert_eq ! ( vec. as_slice( ) , test. as_slice( ) ) ;
65+ }
66+
67+ #[ test]
68+ fn test_borsh_more_than ( ) {
69+ use borsh:: { io:: ErrorKind , BorshDeserialize , BorshSerialize } ;
70+ #[ derive( BorshSerialize , BorshDeserialize ) ]
71+ struct Something {
72+ a : String ,
73+ }
74+ let mut b = ArrayVec :: < u8 , 5 > :: new ( ) ;
75+ let err = Something {
76+ a : "Hello, world!" . to_owned ( ) ,
77+ }
78+ . serialize ( & mut b)
79+ . unwrap_err ( ) ;
80+ assert_eq ! ( ErrorKind :: WriteZero , err. kind( ) ) ;
81+ }
4982}
5083
5184mod array_string {
You can’t perform that action at this time.
0 commit comments