Question & Answer: How can i access the elemts of pieces in money_maker??…..

Question & Answer: How can i access the elemts of pieces in money_maker??..... 1

How can i access the elemts of pieces in money_maker???

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: How can i access the elemts of pieces in money_maker??…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

//An attribute to hide warnings for unused code. #! [allow(dead_code)] #![allow/non_snake_case)] #[allow(non_camel_case_types)] pub enum Salary_grade{ one, three, three, } pub enum Person { Engineer(Salary_grade), Scientist(Salary_grade), Height (i32), Weight (i32), } fn Salary_grade_inspect(s: Salary_grade) { match s { Salary_grade:: one = > println! (“has salary grade of one”), Salary_grade:: two = > println! (“has salary grade of two”), Salary_grade:: three = > println!(“has salary grade of three”), } } fn inspect (p: Person) { match p { Person:: Engineer(i) = > Salary_grade_inspect (i), Person:: Scientist (i) = > Salary_grade-_inspect (i), Person:: Height (i) = > println! (“Has a height of {}.”, i), Person:: Weight (i) = > println! (“Has a weight of {}.”, i), } } put fn money_maker(pieces 0: &[Person]) 0ption { println! (“{ }”,pieces.len()): //how can i access the elements of pieces here??? unimplemented! (): } fn main() { money_maker(& [Person:: Height (71), Person:: Weight (92), Person:: Height (72), Person:: Engineer(Salary_grade:: one), Person:: Scientist(Salary_grade:: three)]): }

Expert Answer

 

First of all you need to allow clone of enum Person by adding below code on top of enum Person definition:

#[derive(Clone)]

After this you add below line in place of //how can i access the ements of pieces here??

let mut i = 0;
while i < pieces.len() {
inspect(pieces[i].clone());
i += 1;
}

Still stressed from student homework?
Get quality assistance from academic writers!