Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can i access the elemts of pieces in money_maker??? //An attribute to hide w

ID: 3867997 • Letter: H

Question

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

//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:: 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)]): }

Explanation / 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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote