Skip to main content

Registry

Struct Registry 

Source
pub struct Registry { /* private fields */ }
Expand description

The per-runtime-instance table of type descriptors. Descriptors drive the derived operations and type-directed JSON decode; registration is used by the interpreter now and compiled code later (plan 01).

Two-phase registration (declare, then define) exists because recursive types across definitions are legal (design §3.8): declare every member of a cycle first, then define each against the declared ids. register is the one-shot spelling for the common case.

Implementations§

Source§

impl Registry

Source

pub fn new() -> Self

Source

pub fn bool_id(&self) -> TypeId

Source

pub fn declare(&mut self, name: &str) -> Result<TypeId, SoilError>

Source

pub fn define(&mut self, id: TypeId, desc: TypeDesc) -> Result<(), SoilError>

Source

pub fn register(&mut self, desc: TypeDesc) -> Result<TypeId, SoilError>

declare + define for the non-recursive common case. Unlike a bare declare, a failed register leaves no trace: the declared name is rolled back so the caller can retry with a fixed descriptor.

Source

pub fn get(&self, id: TypeId) -> Result<&TypeDesc, SoilError>

Source

pub fn lookup(&self, name: &str) -> Option<TypeId>

Source

pub fn derivable(&self, id: TypeId) -> Result<bool, SoilError>

Whether the derived operations exist for this type: false iff its shape transitively contains a function type (“deriving eq on a type containing an arrow is a type error”, design §3.7).

The impl plan places this check at define time; it is computed on demand instead because a member of a type cycle can be defined while its cycle-mates are still only declared, so the transitive walk is not possible until the whole cycle is in. The walk is cycle-safe and cheap at registry scale.

Trait Implementations§

Source§

impl Default for Registry

Source§

fn default() -> Self

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

Auto Trait Implementations§

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