SHARE
TWEET

Untitled

a guest Jan 11th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[derive(Debug)]
  2. pub struct Person {
  3.     name: String,
  4.     age: u8,
  5. }
  6.  
  7. impl Person {
  8.     fn new(name: String, age: u8) -> Person {
  9.         Person {
  10.             name: name,
  11.             age: age,
  12.         }
  13.     }
  14.  
  15.     fn say_hello(self) {
  16.         println!("Hello from {}", self.name);
  17.     }
  18. }
  19.  
  20. fn main() {
  21.     println!("Hello, world!");
  22.  
  23.     let alice = Person::new(String::from("alice"), 21);
  24.     alice.say_hello();
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top