# [−] [src] Struct parity_wasm::elements::IndexMap

    pub struct IndexMap<T> { /* fields omitted */ }

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.

## Methods

### `impl<T> IndexMap<T>` [src]

#### `pub fn with_capacity(capacity: usize) -> IndexMap<T>` [src]

Create an empty `IndexMap`, preallocating enough space to store `capacity` entries without needing to reallocate the underlying memory.

#### `pub fn clear(&mut self)` [src]

Clear the map.

#### `pub fn get(&self, idx: u32) -> Option<&T>` [src]

Return the name for the specified index, if it exists.

#### `pub fn contains_key(&self, idx: u32) -> bool` [src]

Does the map contain an entry for the specified index?

#### `pub fn insert(&mut self, idx: u32, value: T) -> Option<T>` [src]

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.

#### `pub fn remove(&mut self, idx: u32) -> Option<T>` [src]

Remove an item if present and return it.

#### `pub fn len(&self) -> usize` [src]

The number of items in this map.

#### `pub fn is_empty(&self) -> bool` [src]

Is this map empty?

#### `pub fn iter(&self) -> Iter<T>` [src]

Create a non-consuming iterator over this `IndexMap`'s keys and values.

#### `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>,` [src]

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.

### `impl<T: Deserialize> IndexMap<T> where
T: Deserialize,
Error: From<<T as Deserialize>::Error>,` [src]

#### `pub fn deserialize<R: Read>(
max_entry_space: usize,
rdr: &mut R
) -> Result<Self, Error>` [src]

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

### `impl<T> Serialize for IndexMap<T> where
T: Serialize,
Error: From<<T as Serialize>::Error>,` [src]

#### `type Error = Error`

Serialization error produced by serialization routine.

#### `fn serialize<W: Write>(self, wtr: &mut W) -> Result<(), Self::Error>` [src]

Serialize type to serial i/o

### `impl<T> IntoIterator for IndexMap<T>` [src]

#### `type Item = (u32, T)`

The type of the elements being iterated over.

#### `type IntoIter = IntoIter<T>`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> IntoIter<T>` [src]

Creates an iterator from a value. Read more

### `impl<'a, T: 'static> IntoIterator for &'a IndexMap<T>` [src]

#### `type Item = (u32, &'a T)`

The type of the elements being iterated over.

#### `type IntoIter = Iter<'a, T>`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> Iter<'a, T>` [src]

Creates an iterator from a value. Read more

### `impl<T: Clone> Clone for IndexMap<T>` [src]

#### `fn clone(&self) -> IndexMap<T>` [src]

Returns a copy of the value. Read more

#### `fn clone_from(&mut self, source: &Self)`1.0.0 [src]

Performs copy-assignment from `source`. Read more

### `impl<T: Default> Default for IndexMap<T>` [src]

#### `fn default() -> IndexMap<T>` [src]

Returns the "default value" for a type. Read more

### `impl<T: Eq> Eq for IndexMap<T>` [src]

### `impl<T: PartialEq> PartialEq<IndexMap<T>> for IndexMap<T>` [src]

#### `fn eq(&self, other: &IndexMap<T>) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use] fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl<T: Debug> Debug for IndexMap<T>` [src]

#### `fn fmt(&self, f: &mut Formatter) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl<T> FromIterator<(u32, T)> for IndexMap<T>` [src]

#### `fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (u32, T)>,` [src]

Create an `IndexMap` from an iterator.

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.

## Auto Trait Implementations

### `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,`

### `impl<T> RefUnwindSafe for IndexMap<T> where
T: RefUnwindSafe,`

## Blanket Implementations

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U` [src]

Performs the conversion.

### `impl<T> From<T> for T` [src]

#### `fn from(t: T) -> T` [src]

Performs the conversion.

### `impl<I> IntoIterator for I where
I: Iterator,` [src]

#### `type Item = <I as Iterator>::Item`

The type of the elements being iterated over.

#### `type IntoIter = I`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> I` [src]

Creates an iterator from a value. Read more

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

#### `fn to_owned(&self) -> T` [src]

Creates owned data from borrowed data, usually by cloning. Read more

#### `fn clone_into(&self, target: &mut T)` [src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut R

### Important traits for &'_ mut R

`impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;`
`fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut R

### Important traits for &'_ mut R

`impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;`
`fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)