pub struct FnBuilder<'a, P> { /* private fields */ }
Expand description
A builder for functions.
Implementations§
Source§impl<'a, P: FnParent> FnBuilder<'a, P>
impl<'a, P: FnParent> FnBuilder<'a, P>
Sourcepub fn with_lifetime(self, name: impl Into<String>) -> Self
pub fn with_lifetime(self, name: impl Into<String>) -> Self
Add a lifetime parameter.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.with_lifetime("a") // fn foo<'a>()
Sourcepub fn as_async(self) -> Self
pub fn as_async(self) -> Self
Make the function async
generator
.r#impl()
.generate_fn("foo") // fn foo()
.as_async() // async fn foo()
Sourcepub fn with_lifetime_deps<ITER, I>(
self,
name: impl Into<String>,
dependencies: ITER,
) -> Self
pub fn with_lifetime_deps<ITER, I>( self, name: impl Into<String>, dependencies: ITER, ) -> Self
Add a lifetime parameter.
dependencies
are the lifetime dependencies of the given lifetime.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.with_lifetime("a") // fn foo<'a>()
.with_lifetime_deps("b", ["a"]) // fn foo<'b: 'a>()
Sourcepub fn with_generic(self, name: impl Into<String>) -> Self
pub fn with_generic(self, name: impl Into<String>) -> Self
Add a generic parameter. Keep in mind that will not work for lifetimes.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.with_generic("D") // fn foo<D>()
Sourcepub fn with_generic_deps<DEP, I>(
self,
name: impl Into<String>,
dependencies: DEP,
) -> Self
pub fn with_generic_deps<DEP, I>( self, name: impl Into<String>, dependencies: DEP, ) -> Self
Add a generic parameter. Keep in mind that will not work for lifetimes.
dependencies
are the dependencies of the parameter.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.with_generic("D") // fn foo<D>()
.with_generic_deps("E", ["Encodable"]) // fn foo<D, E: Encodable>();
Sourcepub fn with_self_arg(self, self_arg: FnSelfArg) -> Self
pub fn with_self_arg(self, self_arg: FnSelfArg) -> Self
Set the value for self
. See FnSelfArg for more information.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.with_self_arg(FnSelfArg::RefSelf) // fn foo(&self)
Sourcepub fn with_arg(self, name: impl Into<String>, ty: impl Into<String>) -> Self
pub fn with_arg(self, name: impl Into<String>, ty: impl Into<String>) -> Self
Add an argument with a name
and a ty
.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.with_arg("a", "u32") // fn foo(a: u32)
.with_arg("b", "u32") // fn foo(a: u32, b: u32)
Sourcepub fn with_return_type(self, ret_type: impl Into<String>) -> Self
pub fn with_return_type(self, ret_type: impl Into<String>) -> Self
Set the return type for the function. By default the function will have no return type.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.with_return_type("u32") // fn foo() -> u32
Sourcepub fn make_pub(self) -> Self
pub fn make_pub(self) -> Self
Make the function pub
. If this is not called, the function will have no visibility modifier.
Sourcepub fn body(
self,
body_builder: impl FnOnce(&mut StreamBuilder) -> Result,
) -> Result
pub fn body( self, body_builder: impl FnOnce(&mut StreamBuilder) -> Result, ) -> Result
Complete the function definition. This function takes a callback that will form the body of the function.
generator
.r#impl()
.generate_fn("foo") // fn foo()
.body(|b| {
b.push_parsed("println!(\"hello world\");")?;
Ok(())
})
.unwrap();
// fn foo() {
// println!("Hello world");
// }
Auto Trait Implementations§
impl<'a, P> Freeze for FnBuilder<'a, P>
impl<'a, P> RefUnwindSafe for FnBuilder<'a, P>where
P: RefUnwindSafe,
impl<'a, P> Send for FnBuilder<'a, P>where
P: Send,
impl<'a, P> Sync for FnBuilder<'a, P>where
P: Sync,
impl<'a, P> Unpin for FnBuilder<'a, P>
impl<'a, P> !UnwindSafe for FnBuilder<'a, P>
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