daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest May 16th, 2018 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Top