Struct function_wrapper::WrappedFn
source · pub struct WrappedFn {
pub pre_code: Option<TokenStream>,
pub function: ItemFn,
pub wrapper_ident: Ident,
pub result_ident: Ident,
pub post_code: Option<TokenStream>,
}
Expand description
Function that can have code inserted before and after the rest of the function executes.
Can be constructed with syn::parse()
and other variations of parsing from the syn
crate.
Example:
let mut function = parse_macro_input!(token_stream as WrappedFn);
Code that runs before the function can be set using the set_pre_code()
method.
Example:
function.set_pre_code(quote!{ println!("Hi at the start :)"); });
Code that runs after the function can be set using the set_post_code()
method.
Example:
function.set_post_code(quote!{ println!("Hi at the end :)"); });
Fields§
§pre_code: Option<TokenStream>
Contains code that gets run before the rest of the function.
function: ItemFn
syn::ItemFn
that contains all of the data of the original function, including the code inside, the function signature, any attributes, etc.
wrapper_ident: Ident
Identifier token for the closure that wraps all of the original code from the wrapped function. It is wrapper
by default.
result_ident: Ident
Identifier token for the variable that holds the return value of the wrapped function. It is result
by default.
post_code: Option<TokenStream>
Contains code that gets run after the rest of the function.
Implementations§
source§impl WrappedFn
impl WrappedFn
sourcepub fn set_pre_code(&mut self, pre_code: TokenStream)
pub fn set_pre_code(&mut self, pre_code: TokenStream)
Sets the code that gets run before the rest of the function executes.
sourcepub fn set_post_code(&mut self, post_code: TokenStream)
pub fn set_post_code(&mut self, post_code: TokenStream)
Sets the code that gets run after the rest of the function executes.
Trait Implementations§
source§impl From<WrappedFn> for TokenStream
impl From<WrappedFn> for TokenStream
Allows WrappedFn
s to be converted into tokenstreams for easy use in procedural attribute macros.
Auto Trait Implementations§
impl Freeze for WrappedFn
impl RefUnwindSafe for WrappedFn
impl !Send for WrappedFn
impl !Sync for WrappedFn
impl Unpin for WrappedFn
impl UnwindSafe for WrappedFn
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)