Struct rust_codegen::Struct
source · [−]pub struct Struct { /* private fields */ }
Expand description
Defines a struct.
Implementations
sourceimpl Struct
impl Struct
sourcepub fn ty(&self) -> &Type
pub fn ty(&self) -> &Type
Returns a reference to the type.
Examples
use rust_codegen::Struct;
let foo_struct = Struct::new("Foo");
println!("{:?}", foo_struct.ty());
sourcepub fn repr(&mut self, repr: &str) -> &mut Self
pub fn repr(&mut self, repr: &str) -> &mut Self
Specify representation.
repr
- The representation to specify.
Examples
use rust_codegen::Struct;
let mut foo_struct = Struct::new("Foo");
foo_struct.repr("C");
sourcepub fn push_field(&mut self, field: Field) -> &mut Self
pub fn push_field(&mut self, field: Field) -> &mut Self
Push a named field to the struct.
A struct can either set named fields with this function or tuple fields
with push_tuple_field
, but not both.
Arguments
field
- The named field to push.
Examples
use rust_codegen::{Field,Struct};
let mut foo_struct = Struct::new("Foo");
let mut bar_field = Field::new("bar", "i32");
foo_struct.push_field(bar_field);
sourcepub fn field<T>(&mut self, name: &str, ty: T) -> &mut Self where
T: Into<Type>,
pub fn field<T>(&mut self, name: &str, ty: T) -> &mut Self where
T: Into<Type>,
Add a named field to the struct.
A struct can either set named fields with this function or tuple fields
with tuple_field
, but not both.
Arguments
name
- The name of the field.ty
- The type of the field.
Examples
use rust_codegen::Struct;
let mut foo_struct = Struct::new("Foo");
foo_struct.field("bar", "i32");
sourcepub fn tuple_field<T>(&mut self, ty: T) -> &mut Self where
T: Into<Type>,
pub fn tuple_field<T>(&mut self, ty: T) -> &mut Self where
T: Into<Type>,
Add a tuple field to the struct.
A struct can either set tuple fields with this function or named fields
with field
, but not both.
Arguments
ty
- The type of the tuple field to add.
Examples
use rust_codegen::{Struct,Type};
let mut foo_struct = Struct::new("Foo");
let mut bar_type = Type::new("bar");
foo_struct.tuple_field(bar_type);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Struct
impl Send for Struct
impl Sync for Struct
impl Unpin for Struct
impl UnwindSafe for Struct
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more