Struct parity_wasm::elements::IndexMap
source · [−]pub struct IndexMap<T> { /* private fields */ }
Expand description
A map from non-contiguous u32
keys to values of type T
, which is
serialized and deserialized ascending order of the keys. Normally used for
relative dense maps with occasional “holes”, and stored as an array.
SECURITY WARNING: This code is currently subject to a denial of service
attack if you create a map containing the key u32::MAX
, which should never
happen in normal data. It would be pretty easy to provide a safe
deserializing mechanism which addressed this problem.
Implementations
sourceimpl<T> IndexMap<T>
impl<T> IndexMap<T>
sourcepub fn with_capacity(capacity: usize) -> IndexMap<T>
pub fn with_capacity(capacity: usize) -> IndexMap<T>
Create an empty IndexMap
, preallocating enough space to store
capacity
entries without needing to reallocate the underlying memory.
sourcepub fn get(&self, idx: u32) -> Option<&T>
pub fn get(&self, idx: u32) -> Option<&T>
Return the name for the specified index, if it exists.
sourcepub fn contains_key(&self, idx: u32) -> bool
pub fn contains_key(&self, idx: u32) -> bool
Does the map contain an entry for the specified index?
sourcepub fn insert(&mut self, idx: u32, value: T) -> Option<T>
pub fn insert(&mut self, idx: u32, value: T) -> Option<T>
Insert a name into our map, returning the existing value if present.
Note: This API is designed for reasonably dense indices based on valid
data. Inserting a huge idx
will use up a lot of RAM, and this function
will not try to protect you against that.
sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Create a non-consuming iterator over this IndexMap
’s keys and values.
sourcepub fn deserialize_with<R, F>(
max_entry_space: usize,
deserialize_value: &F,
rdr: &mut R
) -> Result<IndexMap<T>, Error> where
R: Read,
F: Fn(u32, &mut R) -> Result<T, Error>,
pub fn deserialize_with<R, F>(
max_entry_space: usize,
deserialize_value: &F,
rdr: &mut R
) -> Result<IndexMap<T>, Error> where
R: Read,
F: Fn(u32, &mut R) -> Result<T, Error>,
Custom deserialization routine.
We will allocate an underlying array no larger than max_entry_space
to
hold the data, so the maximum index must be less than max_entry_space
.
This prevents mallicious *.wasm files from having a single entry with
the index u32::MAX
, which would consume far too much memory.
The deserialize_value
function will be passed the index of the value
being deserialized, and must deserialize the value.
sourceimpl<T: Deserialize> IndexMap<T> where
T: Deserialize,
Error: From<<T as Deserialize>::Error>,
impl<T: Deserialize> IndexMap<T> where
T: Deserialize,
Error: From<<T as Deserialize>::Error>,
sourcepub fn deserialize<R: Read>(
max_entry_space: usize,
rdr: &mut R
) -> Result<Self, Error>
pub fn deserialize<R: Read>(
max_entry_space: usize,
rdr: &mut R
) -> Result<Self, Error>
Deserialize a map containing simple values that support Deserialize
.
We will allocate an underlying array no larger than max_entry_space
to
hold the data, so the maximum index must be less than max_entry_space
.
Trait Implementations
sourceimpl<T> IntoIterator for IndexMap<T>
impl<T> IntoIterator for IndexMap<T>
sourceimpl<'a, T: 'static> IntoIterator for &'a IndexMap<T>
impl<'a, T: 'static> IntoIterator for &'a IndexMap<T>
impl<T: Eq> Eq for IndexMap<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for IndexMap<T> where
T: RefUnwindSafe,
impl<T> Send for IndexMap<T> where
T: Send,
impl<T> Sync for IndexMap<T> where
T: Sync,
impl<T> Unpin for IndexMap<T> where
T: Unpin,
impl<T> UnwindSafe for IndexMap<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more