Skip to content

Commit

Permalink
Fix to_bytes for numeric types (#447)
Browse files Browse the repository at this point in the history
make to_bytes use mem::size_of instead of hardcoded length value for numeric types
  • Loading branch information
Voxelot authored May 16, 2023
1 parent 2e1e4da commit ec46078
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fuel-types/src/numeric_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ macro_rules! key {

macro_rules! key_methods {
($i:ident, $t:ty) => {
const SIZE: usize = core::mem::size_of::<$t>();

impl $i {
/// Number constructor.
pub const fn new(number: $t) -> Self {
Self(number)
}

/// Convert to array of big endian bytes.
pub fn to_bytes(self) -> [u8; 4] {
pub fn to_bytes(self) -> [u8; SIZE] {
self.0.to_be_bytes()
}

Expand All @@ -57,8 +59,6 @@ macro_rules! key_methods {
}
}

const SIZE: usize = core::mem::size_of::<$t>();

#[cfg(feature = "random")]
impl rand::Fill for $i {
fn try_fill<R: rand::Rng + ?Sized>(&mut self, rng: &mut R) -> Result<(), rand::Error> {
Expand Down

0 comments on commit ec46078

Please sign in to comment.