Skip to content

Commit

Permalink
Added const len function to get the size of the key (#47)
Browse files Browse the repository at this point in the history
Added const `len` function to get the size of the key.
  • Loading branch information
xgreenx authored Sep 21, 2022
1 parent 63dbfe9 commit 96fe995
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fuel-types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ macro_rules! key_methods {
// access
&*(bytes.as_ptr() as *const Self)
}

/// The memory length of the type by the method.
pub const fn len(&self) -> usize {
Self::LEN
}
}

#[cfg(feature = "random")]
Expand Down
5 changes: 5 additions & 0 deletions fuel-types/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ macro_rules! check_consistency {
assert_eq!(a, c);
assert_eq!(a, d);
assert_eq!(&a, e);
assert_eq!(a.len(), $i::LEN);
assert_eq!(b.len(), $i::LEN);
assert_eq!(c.len(), $i::LEN);
assert_eq!(d.len(), $i::LEN);
assert_eq!(e.len(), $i::LEN);
}
};
}
Expand Down

0 comments on commit 96fe995

Please sign in to comment.