diff --git a/jira-wip/src/koans/01_ticket/03_validation.rs b/jira-wip/src/koans/01_ticket/03_validation.rs index 940cf38..33ba651 100644 --- a/jira-wip/src/koans/01_ticket/03_validation.rs +++ b/jira-wip/src/koans/01_ticket/03_validation.rs @@ -24,8 +24,8 @@ struct Ticket { /// We will learn a better way to handle recoverable errors such as this one further along, /// but let's rely on panic for the time being. fn create_ticket(title: String, description: String, status: Status) -> Ticket { - todo!() - } + todo!() +} #[cfg(test)] mod tests { diff --git a/jira-wip/src/koans/01_ticket/05_ownership.rs b/jira-wip/src/koans/01_ticket/05_ownership.rs index 5642028..ee16a1a 100644 --- a/jira-wip/src/koans/01_ticket/05_ownership.rs +++ b/jira-wip/src/koans/01_ticket/05_ownership.rs @@ -76,8 +76,8 @@ impl Ticket { /// If you are asking yourself why we are returning &str instead of &String, check out: /// https://blog.thoughtram.io/string-vs-str-in-rust/ pub fn description(__) -> __ { - todo!() - } + todo!() + } pub fn status(__) -> __ { todo!() diff --git a/jira-wip/src/koans/01_ticket/07_derive.rs b/jira-wip/src/koans/01_ticket/07_derive.rs index 58931bb..ae12b83 100644 --- a/jira-wip/src/koans/01_ticket/07_derive.rs +++ b/jira-wip/src/koans/01_ticket/07_derive.rs @@ -14,6 +14,7 @@ /// https://github.com/dtolnay/cargo-expand /// /// ```sh +/// cargo install cargo-expand /// cargo expand -p jira-wip path_to_enlightenment::derive /// ``` /// diff --git a/jira-wip/src/koans/01_ticket/08_recap.rs b/jira-wip/src/koans/01_ticket/08_recap.rs index 050fd98..07140c6 100644 --- a/jira-wip/src/koans/01_ticket/08_recap.rs +++ b/jira-wip/src/koans/01_ticket/08_recap.rs @@ -20,16 +20,16 @@ pub struct Ticket { impl Ticket { pub fn title(&self) -> &String { - &self.title - } + &self.title + } pub fn description(&self) -> &String { - &self.description - } + &self.description + } pub fn status(&self) -> &Status { - &self.status - } + &self.status + } } pub fn create_ticket(title: String, description: String, status: Status) -> Ticket { diff --git a/jira-wip/src/koans/02_ticket_store/01_store.rs b/jira-wip/src/koans/02_ticket_store/01_store.rs index ad7ac3b..91c17bf 100644 --- a/jira-wip/src/koans/02_ticket_store/01_store.rs +++ b/jira-wip/src/koans/02_ticket_store/01_store.rs @@ -40,12 +40,12 @@ impl TicketStore { /// We take `&mut self` because we will have to mutate our HashMap to insert a new /// key-value pair. pub fn save(&mut self, ticket: Ticket, id: u32) { - todo!() - } + todo!() + } pub fn get(&self, id: &u32) -> &Ticket { - todo!() - } + todo!() + } } #[cfg(test)] diff --git a/jira-wip/src/koans/02_ticket_store/02_option.rs b/jira-wip/src/koans/02_ticket_store/02_option.rs index c4637f4..ddfa268 100644 --- a/jira-wip/src/koans/02_ticket_store/02_option.rs +++ b/jira-wip/src/koans/02_ticket_store/02_option.rs @@ -13,8 +13,8 @@ impl TicketStore { } pub fn save(&mut self, ticket: Ticket, id: u32) { - self.data.insert(id, ticket); - } + self.data.insert(id, ticket); + } /// Trying to implement `get` in the previous koan might have caused you some issues due /// to a signature mismatch: `get` on a HashMap returns an `Option<&Ticket>`, @@ -48,8 +48,8 @@ impl TicketStore { /// For more details on `Option`, there is an exhaustive introduction in the Rust book: /// https://doc.rust-lang.org/1.29.0/book/2018-edition/ch06-01-defining-an-enum.html#the-option-enum-and-its-advantages-over-null-values pub fn get(&self, id: &u32) -> Option<&Ticket> { - todo!() - } + todo!() + } } #[cfg(test)] diff --git a/jira-wip/src/koans/02_ticket_store/03_id_generation.rs b/jira-wip/src/koans/02_ticket_store/03_id_generation.rs index 0b6c5bb..091be6c 100644 --- a/jira-wip/src/koans/02_ticket_store/03_id_generation.rs +++ b/jira-wip/src/koans/02_ticket_store/03_id_generation.rs @@ -52,12 +52,12 @@ impl TicketStore { } pub fn get(&self, id: &TicketId) -> Option<&Ticket> { - self.data.get(id) - } + self.data.get(id) + } fn generate_id(__) -> TicketId { - todo!() - } + todo!() + } } #[cfg(test)] diff --git a/jira-wip/src/koans/02_ticket_store/04_metadata.rs b/jira-wip/src/koans/02_ticket_store/04_metadata.rs index 4ddb89f..fb68e88 100644 --- a/jira-wip/src/koans/02_ticket_store/04_metadata.rs +++ b/jira-wip/src/koans/02_ticket_store/04_metadata.rs @@ -36,8 +36,8 @@ impl TicketStore { } pub fn get(&self, id: &TicketId) -> Option<&Ticket> { - self.data.get(id) - } + self.data.get(id) + } fn generate_id(&mut self) -> TicketId { self.current_id += 1; @@ -54,26 +54,26 @@ pub struct Ticket { impl Ticket { pub fn title(&self) -> &String { - &self.title - } + &self.title + } pub fn description(&self) -> &String { - &self.description - } + &self.description + } pub fn status(&self) -> &Status { - &self.status - } + &self.status + } // The datetime when the ticket was saved in the store, if it was saved. pub fn created_at(&self) -> __ { - todo!() - } + todo!() + } // The id associated with the ticket when it was saved in the store, if it was saved. pub fn id(&self) -> __ { - todo!() - } + todo!() + } } pub fn create_ticket(title: String, description: String, status: Status) -> Ticket { diff --git a/jira-wip/src/koans/02_ticket_store/05_type_as_constraints.rs b/jira-wip/src/koans/02_ticket_store/05_type_as_constraints.rs index f2e312f..1ad3695 100644 --- a/jira-wip/src/koans/02_ticket_store/05_type_as_constraints.rs +++ b/jira-wip/src/koans/02_ticket_store/05_type_as_constraints.rs @@ -75,8 +75,8 @@ impl TicketStore { } pub fn get(&self, id: &TicketId) -> Option<&Ticket> { - self.data.get(id) - } + self.data.get(id) + } fn generate_id(&mut self) -> TicketId { self.current_id += 1; diff --git a/jira-wip/src/koans/02_ticket_store/06_result.rs b/jira-wip/src/koans/02_ticket_store/06_result.rs index 8bbe7b9..a6a29df 100644 --- a/jira-wip/src/koans/02_ticket_store/06_result.rs +++ b/jira-wip/src/koans/02_ticket_store/06_result.rs @@ -47,11 +47,11 @@ pub struct TicketDraft { impl TicketDraft { pub fn title(&self) -> &String { - &self.title - } + &self.title + } pub fn description(&self) -> &String { - &self.description - } + &self.description + } pub fn new(title: String, description: String) -> Result { if title.is_empty() { @@ -89,8 +89,8 @@ impl Error for ValidationError {} impl std::fmt::Display for ValidationError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.0) - } + write!(f, "{}", self.0) + } } #[derive(Debug, Clone, PartialEq)] @@ -129,8 +129,8 @@ impl TicketStore { } pub fn get(&self, id: &TicketId) -> Option<&Ticket> { - self.data.get(id) - } + self.data.get(id) + } fn generate_id(&mut self) -> TicketId { self.current_id += 1; @@ -140,20 +140,20 @@ impl TicketStore { impl Ticket { pub fn title(&self) -> &String { - &self.title - } + &self.title + } pub fn description(&self) -> &String { - &self.description - } + &self.description + } pub fn status(&self) -> &Status { - &self.status - } + &self.status + } pub fn created_at(&self) -> &DateTime { - &self.created_at - } + &self.created_at + } pub fn id(&self) -> &TicketId { - &self.id - } + &self.id + } } #[cfg(test)] diff --git a/jira-wip/src/koans/02_ticket_store/07_vec.rs b/jira-wip/src/koans/02_ticket_store/07_vec.rs index 7f408d9..96cabc5 100644 --- a/jira-wip/src/koans/02_ticket_store/07_vec.rs +++ b/jira-wip/src/koans/02_ticket_store/07_vec.rs @@ -35,8 +35,8 @@ impl TicketStore { } pub fn get(&self, id: &TicketId) -> Option<&Ticket> { - self.data.get(id) - } + self.data.get(id) + } /// List will return a `Vec`. /// Check the Rust book for a primer: https://doc.rust-lang.org/book/ch08-01-vectors.html @@ -60,11 +60,11 @@ pub struct TicketDraft { impl TicketDraft { pub fn title(&self) -> &String { - &self.title - } + &self.title + } pub fn description(&self) -> &String { - &self.description - } + &self.description + } pub fn new(title: String, description: String) -> Result { if title.is_empty() { @@ -93,8 +93,8 @@ impl Error for ValidationError {} impl std::fmt::Display for ValidationError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.0) - } + write!(f, "{}", self.0) + } } #[derive(Debug, Clone, PartialEq)] @@ -108,20 +108,20 @@ pub struct Ticket { impl Ticket { pub fn title(&self) -> &String { - &self.title - } + &self.title + } pub fn description(&self) -> &String { - &self.description - } + &self.description + } pub fn status(&self) -> &Status { - &self.status - } + &self.status + } pub fn created_at(&self) -> &DateTime { - &self.created_at - } + &self.created_at + } pub fn id(&self) -> &TicketId { - &self.id - } + &self.id + } } #[cfg(test)] diff --git a/jira-wip/src/koans/02_ticket_store/08_delete_and_update.rs b/jira-wip/src/koans/02_ticket_store/08_delete_and_update.rs index b19de8e..85f4dc2 100644 --- a/jira-wip/src/koans/02_ticket_store/08_delete_and_update.rs +++ b/jira-wip/src/koans/02_ticket_store/08_delete_and_update.rs @@ -39,12 +39,12 @@ impl TicketStore { } pub fn get(&self, id: &TicketId) -> Option<&Ticket> { - self.data.get(id) - } + self.data.get(id) + } pub fn list(&self) -> Vec<&Ticket> { - self.data.values().collect() - } + self.data.values().collect() + } /// We take in an `id` and a `patch` struct: this allows us to constrain which of the /// fields in a `Ticket` can actually be updated. @@ -58,15 +58,15 @@ impl TicketStore { /// If the `id` passed in matches a ticket in the store, we return the edited ticket. /// If it doesn't, we return `None`. pub fn update(&mut self, id: &TicketId, patch: TicketPatch) -> Option<&Ticket> { - todo!() - } + todo!() + } /// If the `id` passed in matches a ticket in the store, we return the deleted ticket /// with some additional metadata. /// If it doesn't, we return `None`. pub fn delete(&mut self, id: &TicketId) -> Option { - todo!() - } + todo!() + } fn generate_id(&mut self) -> TicketId { self.current_id += 1; @@ -150,11 +150,11 @@ pub struct DeletedTicket { impl DeletedTicket { pub fn ticket(&self) -> &Ticket { - &self.ticket - } + &self.ticket + } pub fn deleted_at(&self) -> &DateTime { - &self.deleted_at - } + &self.deleted_at + } } #[derive(PartialEq, Debug, Clone)] @@ -164,8 +164,8 @@ impl Error for ValidationError {} impl std::fmt::Display for ValidationError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.0) - } + write!(f, "{}", self.0) + } } #[derive(Debug, Clone, PartialEq)] @@ -180,23 +180,23 @@ pub struct Ticket { impl Ticket { pub fn title(&self) -> &TicketTitle { - &self.title - } + &self.title + } pub fn description(&self) -> &TicketDescription { - &self.description - } + &self.description + } pub fn status(&self) -> &Status { - &self.status - } + &self.status + } pub fn created_at(&self) -> &DateTime { - &self.created_at - } + &self.created_at + } pub fn id(&self) -> &TicketId { - &self.id - } + &self.id + } pub fn updated_at(&self) -> &DateTime { - &self.updated_at - } + &self.updated_at + } } #[cfg(test)] @@ -303,8 +303,8 @@ mod tests { #[test] fn title_cannot_be_empty() { - assert!(TicketTitle::new("".into()).is_err()) - } + assert!(TicketTitle::new("".into()).is_err()) + } #[test] fn title_cannot_be_longer_than_fifty_chars() { diff --git a/jira-wip/src/koans/02_ticket_store/09_store_recap.rs b/jira-wip/src/koans/02_ticket_store/09_store_recap.rs index fc77f08..e9924c0 100644 --- a/jira-wip/src/koans/02_ticket_store/09_store_recap.rs +++ b/jira-wip/src/koans/02_ticket_store/09_store_recap.rs @@ -41,12 +41,12 @@ impl TicketStore { } pub fn get(&self, id: &TicketId) -> Option<&Ticket> { - self.data.get(id) - } + self.data.get(id) + } pub fn list(&self) -> Vec<&Ticket> { - self.data.values().collect() - } + self.data.values().collect() + } pub fn update(&mut self, id: &TicketId, patch: TicketPatch) -> Option<&Ticket> { if let Some(ticket) = self.data.get_mut(id) { @@ -134,11 +134,11 @@ pub struct DeletedTicket { impl DeletedTicket { pub fn ticket(&self) -> &Ticket { - &self.ticket - } + &self.ticket + } pub fn deleted_at(&self) -> &DateTime { - &self.deleted_at - } + &self.deleted_at + } } #[derive(PartialEq, Debug, Clone)] @@ -148,8 +148,8 @@ impl Error for ValidationError {} impl std::fmt::Display for ValidationError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.0) - } + write!(f, "{}", self.0) + } } #[derive(PartialEq, Debug, Clone)] @@ -172,23 +172,23 @@ pub struct Ticket { impl Ticket { pub fn title(&self) -> &TicketTitle { - &self.title - } + &self.title + } pub fn description(&self) -> &TicketDescription { - &self.description - } + &self.description + } pub fn status(&self) -> &Status { - &self.status - } + &self.status + } pub fn created_at(&self) -> &DateTime { - &self.created_at - } + &self.created_at + } pub fn id(&self) -> &TicketId { - &self.id - } + &self.id + } pub fn updated_at(&self) -> &DateTime { - &self.updated_at - } + &self.updated_at + } } #[cfg(test)] diff --git a/jira-wip/src/koans/03_cli/00_cli.rs b/jira-wip/src/koans/03_cli/00_cli.rs index df81f92..2d120b0 100644 --- a/jira-wip/src/koans/03_cli/00_cli.rs +++ b/jira-wip/src/koans/03_cli/00_cli.rs @@ -68,8 +68,8 @@ impl FromStr for Status { type Err = ParsingError; fn from_str(s: &str) -> Result { - __ - } + __ + } } impl FromStr for TicketTitle { diff --git a/koans-framework/src/lib.rs b/koans-framework/src/lib.rs index e644a16..6aee6c1 100644 --- a/koans-framework/src/lib.rs +++ b/koans-framework/src/lib.rs @@ -60,9 +60,16 @@ impl KoanCollection { &configuration.koans_path() ); let directory_name = entry.file_name(); - read_dir(entry.path()) - .unwrap() - .map(move |f| (directory_name.to_owned(), f.unwrap().file_name())) + read_dir(entry.path()).unwrap().filter_map(move |f| { + let name = f.unwrap().file_name(); + let name_str = name.clone().into_string().unwrap(); + if name_str.ends_with(".rs") && u32::from_str_radix(&name_str[..2], 10).is_ok() + { + Some((directory_name.to_owned(), name)) + } else { + None + } + }) }) .flatten() .collect();