diff --git a/src/lib.rs b/src/lib.rs index cbb8037..67edbac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,9 +299,9 @@ mod tests { #[test] fn example_for_why_you_should_use_fully_qualified_names() { - struct A; + pub struct A; - trait Devious { + pub trait Devious { fn abc(&self) -> isize { 42 } fn xyz(&self) -> isize { 42 } } @@ -319,13 +319,32 @@ mod tests { ::abc(&$x) } } + let c = ::abc(&a); + + macro_rules! you_gotta_be_wiser { + { [[ $x:ident ]] } => { + ::abc(&$x) + } + //{ [[ $x:ident ]] } => { + // ::abc(&$x) + //}; + + //{ -^-^- $x:ident -^-^- } => {{ + // // invoking the version that's inside `the_upside_down` + // use crate::tests::example_for_why_you_should_use_fully_qualified_names::the_upside_down::Devious as OtherDevious; + // ::xyz(&$x) + //}}; + } assert_eq!(didnt_see_it_coming!{ a <-> }, 42); + assert_eq!(you_gotta_be_wiser!{ [[ a ]] }, 42); + //assert_eq!(you_gotta_be_wiser!{ -^-^- a -^-^- }, -42); + /// muhaha fn the_upside_down(a: &A) -> isize { /// we have our own 'Devious' down here... - trait Devious { + pub trait Devious { fn abc(&self) -> isize { -42 } fn xyz(&self) -> isize { -42 } } @@ -339,4 +358,19 @@ mod tests { } + #[test] + fn make_adder_with_supplied_name_working_example() { + macro_rules! make_adder_fn { + ($f:ident, $n:expr) => { + fn $f(rhs: i32) -> i32 { + $n + rhs + } + } + } + make_adder_fn!(add_42, 42); + + assert_eq!(add_42(0), 42); + assert_eq!(add_42(42), 84); + } + }