pub struct StructDef {
pub ident: String,
pub generics: Vec<GenericArg>,
pub variant: VariantData,
}Fields§
§ident: String§generics: Vec<GenericArg>§variant: VariantDataImplementations§
source§impl StructDef
impl StructDef
pub fn new( ident: impl Into<String>, generics: Vec<GenericArg>, variant: VariantData ) -> Self
sourcepub fn empty(ident: impl Into<String>) -> Self
pub fn empty(ident: impl Into<String>) -> Self
Examples found in repository?
examples/struct.rs (line 5)
1 2 3 4 5 6 7 8 9 10 11 12 13
fn main() -> Result<(), Box<dyn std::error::Error>> {
use ruast::*;
let mut krate = Crate::new();
let def = StructDef::empty("Foo")
.with_field(FieldDef::inherited("foo", Type::from("u32")))
.with_field(FieldDef::inherited("bar", Type::from("u32")));
krate.add_item(def);
let imp = Impl::empty("Foo").with_item(Fn::empty_method("test", Pat::ref_self()));
krate.add_item(imp);
println!("{krate}");
Ok(())
}sourcepub fn with_field(self, field: FieldDef) -> Self
pub fn with_field(self, field: FieldDef) -> Self
Examples found in repository?
examples/struct.rs (line 6)
1 2 3 4 5 6 7 8 9 10 11 12 13
fn main() -> Result<(), Box<dyn std::error::Error>> {
use ruast::*;
let mut krate = Crate::new();
let def = StructDef::empty("Foo")
.with_field(FieldDef::inherited("foo", Type::from("u32")))
.with_field(FieldDef::inherited("bar", Type::from("u32")));
krate.add_item(def);
let imp = Impl::empty("Foo").with_item(Fn::empty_method("test", Pat::ref_self()));
krate.add_item(imp);
println!("{krate}");
Ok(())
}pub fn add_field(&mut self, field: FieldDef)
pub fn remove_field(&mut self, index: usize) -> Option<FieldDef>
pub fn remove_field_by_id(&mut self, ident: &str) -> Option<FieldDef>
pub fn get_field_by_id(&self, ident: &str) -> Option<&FieldDef>
Trait Implementations§
source§impl From<StructDef> for TokenStream
impl From<StructDef> for TokenStream
source§impl HasItem<FieldDef> for StructDef
impl HasItem<FieldDef> for StructDef
fn items(&self) -> &[FieldDef]
fn items_mut(&mut self) -> &mut Vec<FieldDef>
fn with_item(self, item: impl Into<Itm>) -> Selfwhere Self: Sized,
fn add_item(&mut self, item: impl Into<Itm>)
fn add_pub_item<K>(&mut self, item: impl Into<K>)where Itm: AddVisibility<K>,
fn with_pub_item<K>(self, item: impl Into<K>) -> Selfwhere Self: Sized, Itm: AddVisibility<K>,
fn remove_item(&mut self, index: usize) -> Option<Itm>
fn remove_item_by_id(&mut self, ident: &str) -> Option<Itm>
fn get_item(&self, index: usize) -> Option<&Itm>
fn get_item_by_id(&self, ident: &str) -> Option<&Itm>
source§impl PartialEq for StructDef
impl PartialEq for StructDef
impl Eq for StructDef
impl StructuralEq for StructDef
impl StructuralPartialEq for StructDef
Auto Trait Implementations§
impl RefUnwindSafe for StructDef
impl Send for StructDef
impl Sync for StructDef
impl Unpin for StructDef
impl UnwindSafe for StructDef
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