pub struct Fn {
pub ident: String,
pub generics: Vec<GenericParam>,
pub fn_decl: FnDecl,
pub body: Option<Block>,
}Fields§
§ident: String§generics: Vec<GenericParam>§fn_decl: FnDecl§body: Option<Block>Implementations§
source§impl Fn
impl Fn
pub fn new( ident: impl Into<String>, generics: Vec<GenericParam>, fn_decl: FnDecl, body: Block ) -> Self
sourcepub fn main(output: Option<Type>, body: Block) -> Self
pub fn main(output: Option<Type>, body: Block) -> Self
Examples found in repository?
examples/hello.rs (lines 5-8)
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 = Fn::main(
None,
Block::from(Path::single("println").mac_call(vec![Token::lit("Hello, world!")])),
);
krate.add_item(def);
println!("{krate}");
// krate.dump("hello.rs")?;
Ok(())
}pub fn empty(ident: impl Into<String>) -> Self
sourcepub fn empty_method(ident: impl Into<String>, self_pat: Pat) -> Self
pub fn empty_method(ident: impl Into<String>, self_pat: Pat) -> Self
Examples found in repository?
examples/enum.rs (line 9)
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(())
}More examples
examples/struct.rs (line 9)
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_stmt(&mut self, stmt: impl Into<Stmt>)
pub fn add_semi_stmt(&mut self, expr: impl Into<Expr>)
pub fn with_stmt(self, stmt: impl Into<Stmt>) -> Self
pub fn with_semi_stmt(self, expr: impl Into<Expr>) -> Self
pub fn remove_stmt(&mut self, index: usize) -> Option<Stmt>
Trait Implementations§
source§impl From<Fn> for AssocItemKind
impl From<Fn> for AssocItemKind
source§impl From<Fn> for TokenStream
impl From<Fn> for TokenStream
impl Eq for Fn
impl StructuralEq for Fn
impl StructuralPartialEq for Fn
Auto Trait Implementations§
impl RefUnwindSafe for Fn
impl Send for Fn
impl Sync for Fn
impl Unpin for Fn
impl UnwindSafe for Fn
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