Advertisement
mbazs

Rust - beginner display

Nov 27th, 2017
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.31 KB | None | 0 0
  1. use std::fmt;
  2. use std::fmt::Display;
  3.  
  4. struct A<T: Display> {
  5.     value: T
  6. }
  7.  
  8. impl<T> fmt::Display for A<T> {
  9.     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  10.         write!(f, "I have the value {}", self.value);
  11.     }
  12. }
  13.  
  14. fn main() {
  15.     let a = A { value: 55 };
  16.     println!("{}", a);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement