Advertisement
mbazs

Rust: From / Into

Mar 23rd, 2018
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.29 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct MyNumber(i8);
  3.  
  4. impl From<i8> for MyNumber {
  5.     fn from(i: i8) -> MyNumber {
  6.         MyNumber(i)
  7.     }
  8. }
  9.  
  10. fn main() {
  11.     let n = MyNumber::from(42);
  12.     println!("From: {:?}", n);
  13.    
  14.     let nn: MyNumber = 5.into();
  15.     println!("Into: {:?}", nn);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement