SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. enum JobTitle {
  2.     CEO,
  3.     Owner,
  4.     Employee,
  5. }
  6.  
  7. struct Person {
  8.     first_name: String,
  9.     last_name: String,
  10.     age: i32,
  11.     job_title: JobTitle,
  12.     salary: f32, //Option<f32>
  13. }
  14.  
  15. impl Person {
  16.     fn profile(&self) {
  17.         println!(
  18.             "{} {}  is an {} at  ",
  19.             self.last_name, self.first_name, self.job_title
  20.         );
  21.     }
  22.     fn anual_revenue(&self) -> f32 {
  23.         let mut salary: f32 = self.salary;
  24.         match salary {
  25.             666.6 => salary += (salary + 100.0) % 100.0,
  26.             333.6 => salary += (salary + 0.50) % 100.0,
  27.             _ => println!("I am the owner"),
  28.         }
  29.         salary
  30.     }
  31. }
  32.  
  33. struct Company {
  34.     id: i32,
  35.     name: String,
  36.     owners: Vec<Person>,
  37. }
  38.  
  39. fn main() {
  40.     //team
  41.     let p1: Person = Person {
  42.         first_name: String::from("mehdi"),
  43.         last_name: String::from("bCheikh"),
  44.         age: 26,
  45.         job_title: JobTitle::CEO,
  46.         salary: 666.6,
  47.     };
  48.     let p2: Person = Person {
  49.         first_name: String::from("Zied"),
  50.         last_name: String::from("sama"),
  51.         age: 26,
  52.         job_title: JobTitle::Owner,
  53.         salary: 0.0,
  54.     };
  55.     let p3: Person = Person {
  56.         first_name: String::from("Anis"),
  57.         last_name: String::from("senya"),
  58.         age: 26,
  59.         job_title: JobTitle::Owner,
  60.         salary: 0.0,
  61.     };
  62.     let p4: Person = Person {
  63.         first_name: String::from("Asma"),
  64.         last_name: String::from("asma"),
  65.         age: 26,
  66.         job_title: JobTitle::Employee,
  67.         salary: 333.6,
  68.     };
  69.  
  70.     //owners
  71.     let mut v: Vec<Person> = vec![];
  72.     v.push(p2);
  73.     v.push(p3);
  74.     //company
  75.     let company: Company = Company {
  76.         id: 32,
  77.         name: String::from("Astrolab"),
  78.         owners: v,
  79.     };
  80.  
  81.     p1.profile();
  82. }
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