aztec-nr - std

Primitive type TypeDefinition

Implementations

impl TypeDefinition

pub comptime fn add_attribute<let N: u32>(self, attribute: str<N>) pub comptime fn add_generic<let N: u32>(self, generic_name: str<N>) -> Type pub comptime fn as_type(self) -> Type

Return a syntactic version of this type definition as a type. For example, type Foo<A, B> { ... }) would return Foo<A, B> when called with this method.

pub comptime fn as_type_with_generics(self, generics: [Type]) -> Option<Type>

Return this type applied to the given generic arguments. For example, given type Foo<A, B> { ... }) could be applied to &[quote[i32].as_type(), quote[Field].as_type()] to return Foo<i32, Field>.

If an incorrect number of generic arguments are given, this function will return None. Otherwise, this function returns Some with the resulting type inside.

pub comptime fn has_named_attribute<let N: u32>(self, name: str<N>) -> bool pub comptime fn generics(self) -> [(Type, Option<Type>)]

Return (type, option<type>) pairs of each generic in this type definition. If a generic is numeric, the second element of the pair will contain the numeric type.

pub comptime fn fields(self, generic_args: [Type]) -> [(Quoted, Type, Quoted)]

Returns (name, type, visibility) tuples of each field in this type. Any generic types used in each field type is automatically substituted with the provided generic arguments.

pub comptime fn fields_as_written(self) -> [(Quoted, Type, Quoted)]

Returns (name, type, visibility) tuples of each field in this type. Each type is as-is with any generic arguments unchanged. Unless the field types are not needed, users should generally prefer to use TypeDefinition::fields over this function if possible.

pub comptime fn module(self) -> Module pub comptime fn name(self) -> Quoted pub comptime fn set_fields(self, new_fields: [(Quoted, Type, Quoted)])

Sets the fields of this type to the given fields list. All existing fields of the type will be overridden with the given fields. Each element of the fields list corresponds to the name and type of a field. Each name is expected to be a single identifier.

Trait implementations

impl Eq for TypeDefinition

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

impl Hash for TypeDefinition

pub comptime fn hash<H>(self, state: &mut H)
where H: Hasher