Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. trait Console {
  2. fn print_str(&mut self, text: &str);
  3. }
  4.  
  5. trait ConsoleExt: Console {
  6. fn print<T: AsRef<str>>(&mut self, text: T) {
  7. self.print_str(text.as_ref())
  8. }
  9. }
  10.  
  11. impl<T> ConsoleExt for T where T: ?Sized + Console {}
  12.  
  13. struct RootConsole;
  14.  
  15. impl Console for RootConsole {
  16. fn print_str(&mut self, text: &str) {
  17. unimplemented!()
  18. }
  19. }
  20.  
  21. fn main() {
  22. let mut console = RootConsole;
  23. console.print("hello!");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement