Struct artichoke_backend::class::Registry[][src]

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

A registry for Class 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 class 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 Class specs behind a Box pointer to ensure pointers to the interior of the spec, like the CString class name, are not invalidated as the underlying storage reallocates.

Implementations

Construct a new, empty Registry.

Construct a new Registry with the given capacity.

Construct a new Registry with the given hash_builder.

Construct a new Registry with the given capacity and hash_builder.

Returns the number of class 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.

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

Returns the number of class specs in the registry.

Returns true if the registry contains class specs.

Returns a reference to the registry’s BuildHasher.

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

Inserts a type-class spec pair into the registry.

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

Panics

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

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

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

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

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.

Shrinks the capacity of the symbol table with a lower bound. The capacity will remain at least as large as both the length and the supplied value.

If the current capacity is less than the lower limit, this is a no-op.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. 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 !=.

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

Performs the conversion.

Performs the conversion.

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.