pub struct UniqueArena<T> { /* private fields */ }
Expand description

An arena whose elements are guaranteed to be unique.

A UniqueArena holds a set of unique values of type T, each with an associated Span. Inserting a value returns a Handle<T>, which can be used to index the UniqueArena and obtain shared access to the T element. Access via a Handle is an array lookup - no hash lookup is necessary.

The element type must implement Eq and Hash. Insertions of equivalent elements, according to Eq, all return the same Handle.

Once inserted, elements may not be mutated.

UniqueArena is similar to Arena: If Arena is vector-like, UniqueArena is HashSet-like.

Implementations

Create a new arena with no initial capacity allocated.

Return the current number of items stored in this arena.

Return true if the arena contains no elements.

Clears the arena, keeping all allocations.

Return the span associated with handle.

If a value has been inserted multiple times, the span returned is the one provided with the first insertion.

If the span feature is not enabled, always return Span::default. This can be detected with Span::is_defined.

Returns an iterator over the items stored in this arena, returning both the item’s handle and a reference to it.

Insert a new value into the arena.

Return a Handle<T>, which can be used to index this arena to get a shared reference to the element.

If this arena already contains an element that is Eq to value, return a Handle to the existing element, and drop value.

When the span feature is enabled, if value is inserted into the arena, associate span with it. An element’s span can be retrieved with the get_span method.

Return this arena’s handle for value, if present.

If this arena already contains an element equal to value, return its handle. Otherwise, return None.

Return this arena’s value at handle, if that is a valid handle.

Trait Implementations

Generate an arbitrary value of Self from the given unstructured data. Read more

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Serialize this value into the given Serde serializer. Read more

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 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.