Skip to content

Commit e411413

Browse files
cruesslerByron
authored andcommitted
feat: add Kind::all()
1 parent 092e9f2 commit e411413

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

gix-hash/src/kind.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

gix-hash/tests/hash/kind.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)