Expand description
§Usage
ⓘ
#[fn_mut(disable_self, disable_output, enable_attrs = "attr1,attr2,...")]
fn(attr1: T1, attr2: T2, ...) -> OutT { ... }
By default fn_mut macro generates function which takes mutable reference to
self and returns mutable reference, if in original function there is any
reference.
Possible options are:
disable_self: do not change&selfto&mut selfdisable_output: do not change output valueenable_attrs = "attr1,attr2,...": change mutability in attr
Requires nightly compiler and #![feature(proc_macro)].
§Examples
ⓘ
#![feature(proc_macro)]
extern crate fn_mut;
use fn_mut::fn_mut;
struct Test(u64);
impl Test {
#[fn_mut(enable_attrs = "text")]
fn test(&self, text: &str) -> Option<&u64> {
if_mut! {
println!("This is mut fn: {}", text);
}
if_const! {
println!("This is const fn: {}", text);
}
Some(ptr!(self.0))
}
}
This example expands to:
struct Test(u64);
impl Test {
fn test(&self, text: &str) -> Option<&u64> {
println!("This is const fn: {}", text);
Some(&self.0)
}
fn test_mut(&mut self, text: &mut str) -> Option<&mut u64> {
println!("This is mut fn: {}", text);
Some(&mut self.0)
}
}