StructDefinition
std::meta::struct_def
contains methods on the built-in StructDefinition
type.
This type corresponds to struct Name { field1: Type1, ... }
items in the source program.
Methods
as_type
as_type
fn as_type(self) -> Type {}
Returns this struct as a type in the source program. If this struct has any generics, the generics are also included as-is.
generics
generics
fn generics(self) -> [Type] {}
Returns each generic on this struct.
Example:
#[example]
struct Foo<T, U> {
bar: [T; 2],
baz: Baz<U, U>,
}
comptime fn example(foo: StructDefinition) {
assert_eq(foo.generics().len(), 2);
// Fails because `T` isn't in scope
// let t = quote { T }.as_type();
// assert_eq(foo.generics()[0], t);
}
fields
fields
fn fields(self) -> [(Quoted, Type)] {}
Returns each field of this struct as a pair of (field name, field type).