Guest User

Untitled

a guest
May 16th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #![feature(specialization)]
  2.  
  3. use std::fmt::Debug;
  4.  
  5. fn foo(v :impl Sized) -> impl Sized {
  6. #[derive(Debug)]
  7. struct T<I>(I);
  8. T(v)
  9. }
  10.  
  11. fn main() {
  12. trait MaybeDebug {
  13. fn maybe_debug(&self);
  14. }
  15. impl<T> MaybeDebug for T {
  16. default fn maybe_debug(&self) {
  17. println!("Can't debug, sorry :(");
  18. }
  19. }
  20. impl<T: Debug> MaybeDebug for T {
  21. fn maybe_debug(&self) {
  22. println!("{:?}", self);
  23. }
  24. }
  25. foo(42).maybe_debug();
  26. struct NoDebug;
  27. foo(NoDebug).maybe_debug();
  28. }
Add Comment
Please, Sign In to add comment