Maxim
1
Wrote little macro for printing
pub fn pt<'a, S: AsRef<str>>(data: S, text: Option<S>)
where S: Into<Cow<'a, str>>{
println!("{}, {:>?}", data.into(), text.as_ref().map(|r| r.as_ref().to_string()));
}
macro_rules! pt {
($a: expr) => {
pt(a, None)
};
($a: expr, $b: expr) =>{
pt(a , b)};
}
Error: cannot find value a
in this scope.
Also, can someone explain how to use tt, item and block in macro expression, thanks!
bjorn3
2
You need to use $a
and $b
inside the macro body too instead of a
and b
.
1 Like
Maxim
3
So write in both arms ($a: expr, $b: expr)?
bjorn3
4
This is what I mean:
macro_rules! pt {
($a: expr) => {
pt($a, None)
};
($a: expr, $b: expr) =>{
pt($a , $b)};
}
2 Likes
system
Closed
5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.