Skip to content

Commit

Permalink
fix(types) Re-implement MemoryUsage for V128.
Browse files Browse the repository at this point in the history
`MemoryUsage` is implemented for `[T; N]` only on rustc
nightly. Wasmer uses the stable channel of rustc. Thus, we
re-implement `MemoryUsage` for `V128` by using `V128.as_slice()`.
  • Loading branch information
Hywan committed Mar 23, 2021
1 parent 83461c3 commit 134be5d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/wasmer-types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::lib::std::string::{String, ToString};
use crate::lib::std::vec::Vec;
use crate::units::Pages;
use crate::values::Value;
use loupe::MemoryUsage;
use loupe::{MemoryUsage, MemoryUsageTracker};

#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -57,7 +57,7 @@ impl fmt::Display for Type {
}
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, MemoryUsage)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
/// The WebAssembly V128 type
pub struct V128(pub(crate) [u8; 16]);
Expand Down Expand Up @@ -98,6 +98,12 @@ impl From<&[u8]> for V128 {
}
}

impl MemoryUsage for V128 {
fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize {
self.as_slice().size_of_val(tracker)
}
}

// External Types

/// A list of all possible types which can be externally referenced from a
Expand Down

0 comments on commit 134be5d

Please sign in to comment.