diff options
| author | Henry <mail@henrygressmann.de> | 2026-04-06 19:29:47 +0200 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2026-04-06 19:29:47 +0200 |
| commit | 4cf65f48e9b17f9a8ca5099d720d3107cb5574b9 (patch) | |
| tree | bec7fa9b486c3de71ea01f48bcd5fc49fd9e861c /crates/types/src | |
| parent | 4b4f7ba271b53e8f3a3be771ca2502db29cbe399 (diff) | |
chore: use FromIterator for ValueCounts
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/types/src')
| -rw-r--r-- | crates/types/src/lib.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index e9d2729..29a29e5 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -214,19 +214,25 @@ pub struct ValueCounts { pub cref: u16, } -impl<'a, T: IntoIterator<Item = &'a ValType>> From<T> for ValueCounts { +impl ValueCounts { #[inline] - fn from(types: T) -> Self { - let mut counts = Self::default(); - for ty in types { + pub fn is_empty(&self) -> bool { + self.c32 == 0 && self.c64 == 0 && self.c128 == 0 && self.cref == 0 + } +} + +impl<'a> FromIterator<&'a ValType> for ValueCounts { + #[inline] + fn from_iter<I: IntoIterator<Item = &'a ValType>>(iter: I) -> Self { + iter.into_iter().fold(Self::default(), |mut counts, ty| { match ty { ValType::I32 | ValType::F32 => counts.c32 += 1, ValType::I64 | ValType::F64 => counts.c64 += 1, ValType::V128 => counts.c128 += 1, ValType::RefExtern | ValType::RefFunc => counts.cref += 1, } - } - counts + counts + }) } } |
