diff --git a/exercises/06_ticket_management/01_arrays/src/lib.rs b/exercises/06_ticket_management/01_arrays/src/lib.rs index e06cb2b..3c70cb3 100644 --- a/exercises/06_ticket_management/01_arrays/src/lib.rs +++ b/exercises/06_ticket_management/01_arrays/src/lib.rs @@ -1,7 +1,7 @@ // TODO: Flesh out the `WeekTemperatures` struct and its method implementations to pass the tests. pub struct WeekTemperatures { - // TODO + temps: [Option; 7], } pub enum Weekday { @@ -16,15 +16,15 @@ pub enum Weekday { impl WeekTemperatures { pub fn new() -> Self { - todo!() + WeekTemperatures { temps: [None; 7] } } pub fn get_temperature(&self, day: Weekday) -> Option { - todo!() + return self.temps[day as usize]; } pub fn set_temperature(&mut self, day: Weekday, temperature: i32) { - todo!() + self.temps[day as usize] = Some(temperature); } } diff --git a/exercises/06_ticket_management/02_vec/src/lib.rs b/exercises/06_ticket_management/02_vec/src/lib.rs index 2e8b498..ee8c93d 100644 --- a/exercises/06_ticket_management/02_vec/src/lib.rs +++ b/exercises/06_ticket_management/02_vec/src/lib.rs @@ -15,7 +15,11 @@ pub fn fibonacci(n: u32) -> u32 { // // Hint: use a `Vec` to memoize the results you have already calculated // so that you don't have to recalculate them several times. - todo!() + let mut fibNums = vec![0, 1]; + for i in 2..=n { + fibNums.push(fibNums[(i - 1) as usize] + fibNums[(i - 2) as usize]); + } + fibNums[(n) as usize] } #[cfg(test)] diff --git a/exercises/06_ticket_management/03_resizing/src/lib.rs b/exercises/06_ticket_management/03_resizing/src/lib.rs index 000ca2d..f29eb7e 100644 --- a/exercises/06_ticket_management/03_resizing/src/lib.rs +++ b/exercises/06_ticket_management/03_resizing/src/lib.rs @@ -12,6 +12,6 @@ mod tests { // Can you guess what the new capacity will be? // Beware that the standard library makes no guarantees about the // algorithm used to resize the vector, so this may change in the future. - assert_eq!(v.capacity(), todo!()); + assert_eq!(v.capacity(), 4); } } diff --git a/exercises/06_ticket_management/04_iterators/src/lib.rs b/exercises/06_ticket_management/04_iterators/src/lib.rs index e7eb9f9..ba3d1d5 100644 --- a/exercises/06_ticket_management/04_iterators/src/lib.rs +++ b/exercises/06_ticket_management/04_iterators/src/lib.rs @@ -13,6 +13,14 @@ pub struct TicketStore { tickets: Vec, } +impl IntoIterator for TicketStore { + type Item = Ticket; + type IntoIter = std::vec::IntoIter; + fn into_iter(self) -> Self::IntoIter { + return self.tickets.into_iter(); + } +} + #[derive(Clone, Debug, PartialEq)] pub struct Ticket { pub title: TicketTitle, diff --git a/exercises/06_ticket_management/05_iter/src/lib.rs b/exercises/06_ticket_management/05_iter/src/lib.rs index 71d3e51..1e1fb42 100644 --- a/exercises/06_ticket_management/05_iter/src/lib.rs +++ b/exercises/06_ticket_management/05_iter/src/lib.rs @@ -17,6 +17,20 @@ pub struct Ticket { status: Status, } +impl TicketStore { + // type Itr=std::vec::I + pub fn iter(&self) -> std::slice::Iter { + self.tickets.iter() + } +} + +// impl Iterator for TicketStore { +// type Item = Ticket; +// fn next(&mut self) -> Self::Item { + +// } +// } + #[derive(Clone, Debug, Copy, PartialEq)] pub enum Status { ToDo, diff --git a/exercises/06_ticket_management/06_lifetimes/src/lib.rs b/exercises/06_ticket_management/06_lifetimes/src/lib.rs index 545ed75..d7fa231 100644 --- a/exercises/06_ticket_management/06_lifetimes/src/lib.rs +++ b/exercises/06_ticket_management/06_lifetimes/src/lib.rs @@ -6,6 +6,14 @@ pub struct TicketStore { tickets: Vec, } +impl<'a> IntoIterator for &'a TicketStore { + type Item = &'a Ticket; + type IntoIter = std::slice::Iter<'a, Ticket>; + fn into_iter(self) -> Self::IntoIter { + self.tickets.iter() + } +} + #[derive(Clone, Debug, PartialEq)] pub struct Ticket { pub title: TicketTitle, diff --git a/exercises/06_ticket_management/07_combinators/src/lib.rs b/exercises/06_ticket_management/07_combinators/src/lib.rs index 2731211..170e033 100644 --- a/exercises/06_ticket_management/07_combinators/src/lib.rs +++ b/exercises/06_ticket_management/07_combinators/src/lib.rs @@ -7,6 +7,18 @@ pub struct TicketStore { tickets: Vec, } +impl TicketStore { + fn to_dos(&self) -> Vec<&Ticket> { + self.tickets + .iter() + .filter(|&a| match a.status { + Status::ToDo => true, + _ => false, + }) + .collect::>() + } +} + #[derive(Clone, Debug, PartialEq)] pub struct Ticket { pub title: TicketTitle,