Guest User

Untitled

a guest
Dec 11th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. pub struct DefaultParam<T> {
  2. value: T,
  3. name: &'static str,
  4. }
  5.  
  6. macro_rules! define {
  7. ( $name:ident, $val:expr, $t:ty ) => {
  8. pub const $name: DefaultParam<$t> = DefaultParam {
  9. value: $val,
  10. name: stringify!($val),
  11. };
  12. }
  13. }
  14.  
  15. define!(PORT, 1234, u32);
  16.  
  17. fn main() {
  18. println!("{} has the value: {}", PORT.name, PORT.value);
  19. }
Add Comment
Please, Sign In to add comment