Field descriptor.
This struct provides compile-time reflection information about a field of a struct or union.
It is created by calling fields.
Methods
impl Field<StructT, FieldT> { ... }
-
Returns the name of the field.
-
Returns the byte offset of the field in the struct.
-
Returns the type descriptor of the field.
-
fn as_ptr(self: &Field<StructT, FieldT>, inst: &StructT) -> &FieldT
Returns the pointer to the field in the struct for the given instance.
Example
use std::typing::Type; struct Foo { bar: i32, } let field: Type<Foo> = Type::new(); let field_desc = field.fields().0; let foo = Foo { bar: 42 }; assert_eq!(*field_desc.as_ptr(&foo), 42);
Run this example -
fn as_mut_ptr(self: &Field<StructT, FieldT>, inst: &mut StructT) -> &mut FieldT
Returns the mutable pointer to the field in the struct for the given instance.
Example
use std::typing::Type; struct Foo { bar: i32, } let field: Type<Foo> = Type::new(); let field_desc = field.fields().0; let foo = Foo { bar: 42 }; *field_desc.as_mut_ptr(&foo) = 1337; assert_eq!(foo.bar, 1337);
Run this example