completed till 11
This commit is contained in:
@@ -7,6 +7,14 @@ pub struct TicketStore {
|
|||||||
tickets: Vec<Ticket>,
|
tickets: Vec<Ticket>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TicketStore {
|
||||||
|
fn in_progress(&self) -> impl Iterator<Item = &Ticket> {
|
||||||
|
self.tickets
|
||||||
|
.iter()
|
||||||
|
.filter(|&a| a.status == Status::InProgress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Ticket {
|
pub struct Ticket {
|
||||||
pub title: TicketTitle,
|
pub title: TicketTitle,
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ impl TicketStore {
|
|||||||
// that can be infallibly converted into a `Ticket`.
|
// that can be infallibly converted into a `Ticket`.
|
||||||
// This can make it nicer to use the method, as it removes the syntax noise of `.into()`
|
// This can make it nicer to use the method, as it removes the syntax noise of `.into()`
|
||||||
// from the calling site. It can worsen the quality of the compiler error messages, though.
|
// from the calling site. It can worsen the quality of the compiler error messages, though.
|
||||||
pub fn add_ticket(&mut self, ticket: impl Into<Ticket>) {
|
pub fn add_ticket<T>(&mut self, ticket: T)
|
||||||
|
where
|
||||||
|
T: Into<Ticket>,
|
||||||
|
{
|
||||||
self.tickets.push(ticket.into());
|
self.tickets.push(ticket.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
// TODO: Define a function named `sum` that takes a reference to a slice of `u32` and returns the sum of all
|
// TODO: Define a function named `sum` that takes a reference to a slice of `u32` and returns the sum of all
|
||||||
// elements in the slice.
|
// elements in the slice.
|
||||||
|
|
||||||
|
fn sum(v: &[u32]) -> u32 {
|
||||||
|
v.iter().sum()
|
||||||
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
// TODO: Define a function named `squared` that raises all `i32`s within a slice to the power of 2.
|
// TODO: Define a function named `squared` that raises all `i32`s within a slice to the power of 2.
|
||||||
// The slice should be modified in place.
|
// The slice should be modified in place.
|
||||||
|
|
||||||
|
fn squared(v: &mut [i32]) {
|
||||||
|
for val in v.iter_mut() {
|
||||||
|
*val = val.pow(2);
|
||||||
|
}
|
||||||
|
// let b = v.iter().map(|a| a.pow(2)).collect::<Vec<_>>().as_slice();
|
||||||
|
// v = b;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user