Struct candid::types::internal::TypeContainer

source ·
pub struct TypeContainer {
    pub env: TypeEnv,
}
Expand description

Used for candid_derive::export_service to generate TypeEnv from Type.

It performs a global rewriting of Type to resolve:

  • Duplicate type names in different modules/namespaces.
  • Give different names to instantiated polymorphic types.
  • Find the type name of a recursive node Knot(TypeId) and convert to Var node.

There are some drawbacks of this approach:

  • The type name is based on type_name::<T>(), whose format is unspecified and long. We use some regex to shorten the name.
  • Several Rust types can map to the same Candid type, and we only get to remember one name (currently we choose the shortest name). As a result, some of the type names in Rust is lost.
  • Unless we do equivalence checking, recursive types can be unrolled and assigned to multiple names.

Fields§

§env: TypeEnv

Implementations§

source§

impl TypeContainer

source

pub fn new() -> Self

source

pub fn add<T: CandidType>(&mut self) -> Type

Trait Implementations§

source§

impl Default for TypeContainer

source§

fn default() -> TypeContainer

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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.