Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "livestock-rs"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
authors = ["Jaken Herman <jaken@rowanranch.com>"]
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
119 changes: 119 additions & 0 deletions src/donkey.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use serde::{Deserialize, Serialize};
use std::str::FromStr;

/// An enum representing the different breeds of donkeys.
///
/// Initial data from: <https://breeds.okstate.edu/other-breeds-of-livestock/donkeys/>
///
/// # 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<Self, Self::Err> {
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);
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod cattle;
pub mod donkey;
pub mod goat;
pub mod reindeer;
pub mod sheep;
Loading