initial commit
This commit is contained in:
7
exercises/06_ticket_management/08_impl_trait/Cargo.toml
Normal file
7
exercises/06_ticket_management/08_impl_trait/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "impl_trait"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
ticket_fields = { path = "../../../helpers/ticket_fields" }
|
||||
63
exercises/06_ticket_management/08_impl_trait/src/lib.rs
Normal file
63
exercises/06_ticket_management/08_impl_trait/src/lib.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
// TODO: Implement the `in_progress` method. It must return an iterator over the tickets in
|
||||
// `TicketStore` with status set to `Status::InProgress`.
|
||||
use ticket_fields::{TicketDescription, TicketTitle};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TicketStore {
|
||||
tickets: Vec<Ticket>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Ticket {
|
||||
pub title: TicketTitle,
|
||||
pub description: TicketDescription,
|
||||
pub status: Status,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Copy, PartialEq)]
|
||||
pub enum Status {
|
||||
ToDo,
|
||||
InProgress,
|
||||
Done,
|
||||
}
|
||||
|
||||
impl TicketStore {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
tickets: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_ticket(&mut self, ticket: Ticket) {
|
||||
self.tickets.push(ticket);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ticket_fields::test_helpers::{ticket_description, ticket_title};
|
||||
|
||||
#[test]
|
||||
fn in_progress() {
|
||||
let mut store = TicketStore::new();
|
||||
|
||||
let todo = Ticket {
|
||||
title: ticket_title(),
|
||||
description: ticket_description(),
|
||||
status: Status::ToDo,
|
||||
};
|
||||
store.add_ticket(todo);
|
||||
|
||||
let in_progress = Ticket {
|
||||
title: ticket_title(),
|
||||
description: ticket_description(),
|
||||
status: Status::InProgress,
|
||||
};
|
||||
store.add_ticket(in_progress.clone());
|
||||
|
||||
let in_progress_tickets: Vec<&Ticket> = store.in_progress().collect();
|
||||
assert_eq!(in_progress_tickets.len(), 1);
|
||||
assert_eq!(in_progress_tickets[0], &in_progress);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user