pub struct FieldDef {
pub attrs: Vec<Attribute>,
pub vis: Visibility,
pub ident: Option<String>,
pub ty: Type,
}Fields§
§attrs: Vec<Attribute>§vis: Visibility§ident: Option<String>§ty: TypeImplementations§
source§impl FieldDef
impl FieldDef
pub fn new( vis: Visibility, ident: Option<impl Into<String>>, ty: impl Into<Type> ) -> Self
sourcepub fn anonymous(ty: impl Into<Type>) -> Self
pub fn anonymous(ty: impl Into<Type>) -> Self
Examples found in repository?
examples/enum.rs (line 7)
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 = EnumDef::empty("Foo")
.with_variant(Variant::empty("Bar"))
.with_variant(Variant::tuple("Baz", vec![FieldDef::anonymous("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 inherited(ident: impl Into<String>, ty: impl Into<Type>) -> Self
pub fn inherited(ident: impl Into<String>, ty: impl Into<Type>) -> 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 public(ident: impl Into<String>, ty: impl Into<Type>) -> Self
pub fn with_attr(self, attr: impl Into<Attribute>) -> Self
pub fn add_attr(&mut self, attr: impl Into<Attribute>)
pub fn remove_attr(&mut self, index: usize) -> Attribute
Trait Implementations§
source§impl From<FieldDef> for TokenStream
impl From<FieldDef> 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 HasItem<FieldDef> for VariantData
impl HasItem<FieldDef> for VariantData
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 FieldDef
impl PartialEq for FieldDef
impl Eq for FieldDef
impl StructuralEq for FieldDef
impl StructuralPartialEq for FieldDef
Auto Trait Implementations§
impl RefUnwindSafe for FieldDef
impl Send for FieldDef
impl Sync for FieldDef
impl Unpin for FieldDef
impl UnwindSafe for FieldDef
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