pub struct Struct { /* private fields */ }
Expand description
Defines a struct.
Implementations§
Source§impl 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
pub fn field<T>(&mut self, name: &str, ty: T) -> &mut Self
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
pub fn tuple_field<T>(&mut self, ty: T) -> &mut Self
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 Freeze for Struct
impl RefUnwindSafe for Struct
impl Send for Struct
impl Sync for Struct
impl Unpin for Struct
impl UnwindSafe for Struct
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more