diff --git a/Cargo.lock b/Cargo.lock index 97da952..b46d67e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,7 +29,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "livestock-rs" -version = "0.4.0" +version = "0.5.0" dependencies = [ "Inflector", "serde", diff --git a/Cargo.toml b/Cargo.toml index 11875f3..031852b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "livestock-rs" -version = "0.4.0" +version = "0.5.0" edition = "2021" authors = ["Jaken Herman "] license = "MIT" diff --git a/README.md b/README.md index b28bc54..224c022 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Features - πŸ„ Includes common cattle breeds like Angus and Brahman. - 🐐 Includes common goat breeds like Alpine and Boer. - πŸ‘ Includes common sheep breeds like Dorper and St. Croix. + - 🫏 Includes common donkey breeds like Miniature and Standard. - 🦌 Includes common reindeer breeds like Even and Nentsi. - πŸ› οΈ Utilities for converting between enum variants and human-readable strings. - πŸ”’ Serde support for serialization and deserialization. @@ -47,6 +48,9 @@ println!("{:?}", breed); // prints "CanindΓ©" - Features a wide variety of sheep breeds including popular types like Dorper, Romney, and Merino. - Regional and specialty breeds such as the Icelandic, Navajo Churro, and Valais Blacknose. +## Donkey Breeds +- Features common donkey breeds including Standard, Large Standard, Miniature, Mary, Mammoth Jack Stock, and more. + ## Reindeer Breeds - Features common reindeer breeds including Chukotka, Even, Evenk, and Nentsi. diff --git a/src/donkey.rs b/src/donkey.rs new file mode 100644 index 0000000..685addf --- /dev/null +++ b/src/donkey.rs @@ -0,0 +1,119 @@ +use serde::{Deserialize, Serialize}; +use std::str::FromStr; + +/// An enum representing the different breeds of donkeys. +/// +/// Initial data from: +/// +/// # Examples +/// ``` rust +/// use livestock_rs::donkey::DonkeyBreed; +/// +/// let breed = DonkeyBreed::Abyssinian; +/// println!("{:?}", breed); +/// ``` +#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)] +pub enum DonkeyBreed { + Abyssinian, + Anatolia, + LargeStandard, + MammothJackStock, + Mary, + Miniature, + Poitou, + Standard +} + +impl ToString for DonkeyBreed { + /// Converts the DonkeyBreed enum to a human readable string. + /// + /// # Examples + /// ``` rust + /// use livestock_rs::donkey::DonkeyBreed; + /// + /// let evenk = DonkeyBreed::Standard; + /// println!("{}", evenk.to_string()); + /// ``` + fn to_string(&self) -> String { + match self { + DonkeyBreed::Abyssinian => "Abyssinian".to_string(), + DonkeyBreed::Anatolia => "Anatolia".to_string(), + DonkeyBreed::LargeStandard => "Large Standard".to_string(), + DonkeyBreed::MammothJackStock => "Mammoth Jack Stock".to_string(), + DonkeyBreed::Mary => "Mary".to_string(), + DonkeyBreed::Miniature => "Miniature".to_string(), + DonkeyBreed::Poitou => "Poitou".to_string(), + DonkeyBreed::Standard => "Standard".to_string(), + } + } +} + +/// Converts a string to a DonkeyBreed enum. +/// +/// # Examples +/// ``` rust +/// use livestock_rs::donkey::DonkeyBreed; +/// use std::str::FromStr; +/// +/// let breed = DonkeyBreed::from_str("standard").unwrap(); +/// println!("{:?}", breed); +/// ``` + +impl FromStr for DonkeyBreed { + type Err = std::io::Error; + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + "abyssinian" => Ok(DonkeyBreed::Abyssinian), + "anatolia" => Ok(DonkeyBreed::Anatolia), + "large standard" => Ok(DonkeyBreed::LargeStandard), + "mammoth jack stock" => Ok(DonkeyBreed::MammothJackStock), + "mary" => Ok(DonkeyBreed::Mary), + "miniature" | "mini" => Ok(DonkeyBreed::Miniature), + "poitou" => Ok(DonkeyBreed::Poitou), + "standard" => Ok(DonkeyBreed::Standard), + _ => Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "Invalid reindeer breed")), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_to_string() { + let breeds = [ + (DonkeyBreed::Abyssinian, "Abyssinian"), + (DonkeyBreed::Anatolia, "Anatolia"), + (DonkeyBreed::LargeStandard, "Large Standard"), + (DonkeyBreed::MammothJackStock, "Mammoth Jack Stock"), + (DonkeyBreed::Mary, "Mary"), + (DonkeyBreed::Miniature, "Miniature"), + (DonkeyBreed::Poitou, "Poitou"), + (DonkeyBreed::Standard, "Standard"), + ]; + + for (breed, expected) in breeds.iter() { + assert_eq!(breed.to_string(), *expected); + } + } + + #[test] + fn test_from_str() { + let breeds = [ + ("abyssinian", DonkeyBreed::Abyssinian), + ("anatolia", DonkeyBreed::Anatolia), + ("large standard", DonkeyBreed::LargeStandard), + ("mammoth jack stock", DonkeyBreed::MammothJackStock), + ("mary", DonkeyBreed::Mary), + ("miniature", DonkeyBreed::Miniature), + ("mini", DonkeyBreed::Miniature), + ("poitou", DonkeyBreed::Poitou), + ("standard", DonkeyBreed::Standard) + ]; + + for (breed, expected) in breeds.iter() { + assert_eq!(DonkeyBreed::from_str(*breed).unwrap(), *expected); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index badad81..e19b6ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod cattle; +pub mod donkey; pub mod goat; pub mod reindeer; pub mod sheep; \ No newline at end of file