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

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

Clear the map.

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

Does the map contain an entry for the specified index?

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.

Remove an item if present and return it.

The number of items in this map.

Is this map empty?

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

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.

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

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.

The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialization error produced by serialization routine.
Serialize type to serial i/o

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.