Guest User

Untitled

a guest
Dec 11th, 2018
123
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 : $t:ty = $val:expr ) => {
  8. pub const $name: DefaultParam<$t> = DefaultParam {
  9. value: $val,
  10. name: stringify!($val),
  11. };
  12. }
  13. }
  14.  
  15. define!(PORT: u32 = 1234);
  16.  
  17. fn main() {
  18. println!("{} has the value: {}", PORT.name, PORT.value);
  19. }
Add Comment
Please, Sign In to add comment