Guest User

Untitled

a guest
May 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #![cfg_attr(feature = "const-fn", feature(const_fn))]
  2.  
  3. #[cfg(feature = "foo")]
  4. fn foo() {
  5. println!("its foo");
  6. }
  7.  
  8. #[cfg(not(feature = "foo"))]
  9. fn foo() {
  10. println!("its not foo");
  11. }
  12.  
  13. macro_rules! const_fn {
  14. ($($f:tt)*) => (
  15. #[cfg(feature = "const-fn")]
  16. const $($f)*
  17.  
  18. #[cfg(not(feature = "const-fn"))]
  19. $($f)*
  20. );
  21. }
  22.  
  23. struct A;
  24.  
  25.  
  26. impl A {
  27. const_fn!(fn new() -> A { A });
  28. }
  29.  
  30. fn main() {
  31. foo();
  32. let a = A::new();
  33. }
Add Comment
Please, Sign In to add comment