Skip to main content

Arena

Struct Arena 

Source
pub struct Arena<T: ?Sized, Storage = T> { /* private fields */ }
Expand description

Interning arena for values of type T, storing them with the given Storage type (that needs to be Sized).

For Sized values, Storage = T is a good default that incurs no overhead. For non-Sized values such as [str], you need to specify a Sized storage type, such as Box<T>.

Implementations§

Source§

impl<T: ?Sized, Storage> Arena<T, Storage>

Source

pub fn with_capacity(len: usize) -> Self

Creates a new arena with pre-allocated space to store at least len values of type T.

Source

pub fn len(&self) -> usize

Returns the number of values in this arena.

Note that because Arena is a concurrent data structure, this is only a snapshot as viewed by this thread, and the result may change if other threads are inserting values.

Source

pub fn is_empty(&self) -> bool

Checks if this arena is empty.

Note that because Arena is a concurrent data structure, this is only a snapshot as viewed by this thread, and the result may change if other threads are inserting values.

Source§

impl<T, Storage> Arena<T, Storage>
where T: Eq + Hash + ?Sized, Storage: Borrow<T>,

Source

pub fn find(&self, value: &T) -> Option<Interned<T, Storage>>

Returns the given value’s Interned handle if it is already interned.

Otherwise, this simply returns None without adding the value to this arena.

Source§

impl<T, Storage> Arena<T, Storage>
where T: Eq + Hash + ?Sized, Storage: Borrow<T>,

Source

pub fn push_mut(&mut self, value: Storage) -> u32

Available on crate feature raw only.

Unconditionally push a value, without validating that it’s already interned.

Source§

impl<T: ?Sized, Storage> Arena<T, Storage>
where Storage: GetSize,

Source

pub fn print_summary(&self, prefix: &str, title: &str, total_bytes: usize)

Available on crate feature debug only.

Prints a summary of the storage used by this arena to stdout.

Source§

impl<T, Storage> Arena<T, Storage>
where T: Eq + Hash + ?Sized, Storage: Borrow<T>,

Source

pub fn intern( &self, value: impl Borrow<T> + Into<Storage>, ) -> Interned<T, Storage>

Interns the given value in this arena.

If the value was already interned in this arena, it will simply be borrowed to retrieve its interning index. Otherwise it will then be converted to store it into the arena.

Source§

impl<T: ?Sized, Storage> Arena<T, Storage>
where Storage: Clone,

Source

pub fn lookup(&self, interned: Interned<T, Storage>) -> Storage

Retrieves the given Interned value from this arena.

The caller is responsible for ensuring that the same arena was used to intern this value, otherwise an arbitrary value will be returned or a panic will happen.

See also lookup_ref() if you only need a reference.

Source§

impl<T: ?Sized, Storage> Arena<T, Storage>
where Storage: Borrow<T>,

Source

pub fn lookup_ref(&self, interned: Interned<T, Storage>) -> &T

Retrieves a reference to the given Interned value from this arena.

The caller is responsible for ensuring that the same arena was used to intern this value, otherwise an arbitrary value will be returned or a panic will happen.

See also lookup() if you need an owned value.

Trait Implementations§

Source§

impl<T, Storage> Clone for Arena<T, Storage>
where T: Eq + Hash + ?Sized, Storage: Borrow<T> + Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, Storage> Debug for Arena<T, Storage>
where T: Debug + ?Sized, Storage: Borrow<T>,

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized, Storage> Default for Arena<T, Storage>

Source§

fn default() -> Self

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

impl<'de, T, Storage> Deserialize<'de> for Arena<T, Storage>
where T: Eq + Hash + ?Sized, Storage: Borrow<T> + Deserialize<'de>,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: ?Sized, Storage> GetSize for Arena<T, Storage>
where Storage: GetSize,

Available on crate feature get-size2 only.
Source§

fn get_heap_size_with_tracker<Tr: GetSizeTracker>( &self, tracker: Tr, ) -> (usize, Tr)

Determines how many bytes this object occupies inside the heap while using a tracker. Read more
Source§

fn get_stack_size() -> usize

Determines how may bytes this object occupies inside the stack. Read more
Source§

fn get_heap_size(&self) -> usize

Determines how many bytes this object occupies inside the heap. Read more
Source§

fn get_size(&self) -> usize

Determines the total size of the object. Read more
Source§

fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)
where T: GetSizeTracker,

Determines the total size of the object while using a tracker. Read more
Source§

impl<T, Storage> PartialEq for Arena<T, Storage>
where T: Eq + ?Sized, Storage: Borrow<T>,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, Storage> Serialize for Arena<T, Storage>
where T: Serialize + ?Sized, Storage: Borrow<T>,

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, Storage> Eq for Arena<T, Storage>
where T: Eq + ?Sized, Storage: Borrow<T>,

Auto Trait Implementations§

§

impl<T, Storage = T> !Freeze for Arena<T, Storage>

§

impl<T, Storage = T> !RefUnwindSafe for Arena<T, Storage>

§

impl<T, Storage> Send for Arena<T, Storage>
where Storage: Send + Sync, T: ?Sized,

§

impl<T, Storage> Sync for Arena<T, Storage>
where Storage: Send + Sync, T: ?Sized,

§

impl<T, Storage> Unpin for Arena<T, Storage>
where T: ?Sized,

§

impl<T, Storage> UnsafeUnpin for Arena<T, Storage>
where T: ?Sized,

§

impl<T, Storage> UnwindSafe for Arena<T, Storage>
where Storage: RefUnwindSafe, T: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,