Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #![feature(core_intrinsics)]
  2. use std::io::{Stdout, stdout, Write};
  3.  
  4.  
  5.  
  6. fn print_type_of<T>(_: &T) {
  7. println!("{}", unsafe { std::intrinsics::type_name::<T>() });
  8. }
  9.  
  10. struct Foo<T> {
  11. out_sink: T
  12. }
  13.  
  14. impl Foo<Stdout> {
  15. fn new() -> Self {
  16. Foo { out_sink: stdout() }
  17. }
  18.  
  19. }
  20.  
  21. impl<T: Write> Foo<T> {
  22. fn with_writer(writer: T) -> Self {
  23. Foo { out_sink: writer }
  24. }
  25.  
  26. fn testor(&self) {
  27. print_type_of(&self.out_sink);
  28. }
  29. }
  30.  
  31. fn main() {
  32. let bar = Foo::new();
  33. let baz = Foo::with_writer(Vec::<u8>::new());
  34. bar.testor();
  35. baz.testor();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement