[][src]Struct artichoke_backend::module::Registry

pub struct Registry<S = RandomState>(_);

A registry for Module specs that uses types as keys.

This data structure is used for associating data type metadata with a Rust type which can be used to ensure the lifetime of the associated metadata.

Example: mrb_data_type

In the mruby C API, custom data types define a mrb_data_type struct which contains the custom data type's module name and free function. The C API requires that this struct live at least as long as the mrb_state. Typically, the mrb_data_type is static.

static const struct mrb_data_type mrb_time_type = { "Time", mrb_free };

The registry resembles an append-only HashMap.

The registry stores Module specs behind a Box pointer to ensure pointers to the interior of the spec, like the CString module name, are not invalidated as the underlying storage reallocates.


impl Registry<RandomState>[src]

#[must_use]pub fn new() -> Self[src]

Construct a new, empty Registry.

#[must_use]pub fn with_capacity(capacity: usize) -> Self[src]

Construct a new Registry with the given capacity.

impl<S> Registry<S>[src]

#[must_use]pub fn with_hasher(hash_builder: S) -> Self[src]

Construct a new Registry with the given hash_builder.

#[must_use]pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self[src]

Construct a new Registry with the given capacity and hash_builder.

#[must_use]pub fn capacity(&self) -> usize[src]

Returns the number of module specs the registry can hold without reallocating.

This number is a lower bound; the Registry might be able to hold more, but is guaranteed to be able to hold at least this many.

#[must_use]pub fn module_specs(&self) -> ModuleSpecs<'_>[src]

An iterator of all module specs stored in the Registry in arbitrary order.

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

Returns the number of module specs in the registry.

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

Returns true if the registry contains module specs.

#[must_use]pub fn hasher(&self) -> &S[src]

Returns a reference to the registry's BuildHasher.

impl<S> Registry<S> where
    S: BuildHasher

#[must_use]pub fn contains<K>(&self) -> bool where
    K: Any

Returns true if the registry contains a module spec for the specified type.

pub fn insert<K>(&mut self, spec: Box<Spec>) where
    K: Any

Inserts a type-module spec pair into the registry.

This operation will only succeed if K has never been inserted into the registry.


If insert has previously been called with type K, this function will panic. Registry is append-only and does not allow mutations.

#[must_use]pub fn get<K>(&self) -> Option<&Spec> where
    K: Any

Returns a reference to the module spec corresponding to the type key.

If the type K has not been registered, None is returned.

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for at least additional more elements to be inserted in the Registry. The collection may reserve more space to avoid frequent reallocations.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

Trait Implementations

impl<S: Debug> Debug for Registry<S>[src]

impl<S: Default> Default for Registry<S>[src]

impl<S> Eq for Registry<S> where
    S: BuildHasher

impl<'a, S> IntoIterator for &'a Registry<S>[src]

type Item = &'a Spec

The type of the elements being iterated over.

type IntoIter = ModuleSpecs<'a>

Which kind of iterator are we turning this into?

impl<S> PartialEq<Registry<S>> for Registry<S> where
    S: BuildHasher

Auto Trait Implementations

impl<S> RefUnwindSafe for Registry<S> where
    S: RefUnwindSafe

impl<S> Send for Registry<S> where
    S: Send

impl<S> Sync for Registry<S> where
    S: Sync

impl<S> Unpin for Registry<S> where
    S: Unpin

impl<S> UnwindSafe for Registry<S> where
    S: UnwindSafe

Blanket Implementations

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

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

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

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

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,