File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -174,4 +174,21 @@ impl Kind {
174174 pub const fn empty_tree ( & self ) -> ObjectId {
175175 ObjectId :: empty_tree ( * self )
176176 }
177+
178+ /// Return a list of available hash kinds.
179+ #[ inline]
180+ pub const fn all ( ) -> & ' static [ Self ] {
181+ #[ cfg( all( feature = "sha1" , not( feature = "sha256" ) ) ) ]
182+ {
183+ & [ Self :: Sha1 ]
184+ }
185+ #[ cfg( all( not( feature = "sha1" ) , feature = "sha256" ) ) ]
186+ {
187+ & [ Self :: Sha256 ]
188+ }
189+ #[ cfg( all( feature = "sha1" , feature = "sha256" ) ) ]
190+ {
191+ & [ Self :: Sha1 , Self :: Sha256 ]
192+ }
193+ }
177194}
Original file line number Diff line number Diff line change @@ -103,3 +103,21 @@ fn longest_sha1_and_sha256() {
103103 let longest = Kind :: longest ( ) ;
104104 assert_eq ! ( longest, Kind :: Sha256 ) ;
105105}
106+
107+ #[ test]
108+ #[ cfg( all( feature = "sha1" , not( feature = "sha256" ) ) ) ]
109+ fn all ( ) {
110+ assert_eq ! ( Kind :: all( ) , & [ Kind :: Sha1 ] ) ;
111+ }
112+
113+ #[ test]
114+ #[ cfg( all( not( feature = "sha1" ) , feature = "sha256" ) ) ]
115+ fn all ( ) {
116+ assert_eq ! ( Kind :: all( ) , & [ Kind :: Sha256 ] ) ;
117+ }
118+
119+ #[ test]
120+ #[ cfg( all( feature = "sha1" , feature = "sha256" ) ) ]
121+ fn all ( ) {
122+ assert_eq ! ( Kind :: all( ) , & [ Kind :: Sha1 , Kind :: Sha256 ] ) ;
123+ }
You can’t perform that action at this time.
0 commit comments