@@ -16,7 +16,7 @@ use crate as borsh; // For `#[derive(BorshSerialize, BorshDeserialize)]`.
16
16
use crate :: __private:: maybestd:: {
17
17
borrow,
18
18
boxed:: Box ,
19
- collections:: { btree_map:: Entry , BTreeMap , BTreeSet } ,
19
+ collections:: { btree_map:: Entry , BTreeMap , BTreeSet , LinkedList , VecDeque } ,
20
20
format,
21
21
string:: { String , ToString } ,
22
22
vec,
@@ -635,25 +635,33 @@ where
635
635
}
636
636
}
637
637
638
- impl < T > BorshSchema for Vec < T >
639
- where
640
- T : BorshSchema ,
641
- {
642
- fn add_definitions_recursively ( definitions : & mut BTreeMap < Declaration , Definition > ) {
643
- let definition = Definition :: Sequence {
644
- length_width : Definition :: DEFAULT_LENGTH_WIDTH ,
645
- length_range : Definition :: DEFAULT_LENGTH_RANGE ,
646
- elements : T :: declaration ( ) ,
647
- } ;
648
- add_definition ( Self :: declaration ( ) , definition, definitions) ;
649
- T :: add_definitions_recursively ( definitions) ;
650
- }
638
+ macro_rules! impl_for_vec_like_collection {
639
+ ( $type: ident) => {
640
+ impl <T > BorshSchema for $type<T >
641
+ where
642
+ T : BorshSchema ,
643
+ {
644
+ fn add_definitions_recursively( definitions: & mut BTreeMap <Declaration , Definition >) {
645
+ let definition = Definition :: Sequence {
646
+ length_width: Definition :: DEFAULT_LENGTH_WIDTH ,
647
+ length_range: Definition :: DEFAULT_LENGTH_RANGE ,
648
+ elements: T :: declaration( ) ,
649
+ } ;
650
+ add_definition( Self :: declaration( ) , definition, definitions) ;
651
+ T :: add_definitions_recursively( definitions) ;
652
+ }
651
653
652
- fn declaration ( ) -> Declaration {
653
- format ! ( r#"Vec<{}>"# , T :: declaration( ) )
654
- }
654
+ fn declaration( ) -> Declaration {
655
+ format!( r#"{}<{}>"# , stringify!( $type) , T :: declaration( ) )
656
+ }
657
+ }
658
+ } ;
655
659
}
656
660
661
+ impl_for_vec_like_collection ! ( Vec ) ;
662
+ impl_for_vec_like_collection ! ( VecDeque ) ;
663
+ impl_for_vec_like_collection ! ( LinkedList ) ;
664
+
657
665
impl < T > BorshSchema for [ T ]
658
666
where
659
667
T : BorshSchema ,
0 commit comments