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.5.0"
version = "0.6.0"
edition = "2021"
authors = ["Jaken Herman <jaken@rowanranch.com>"]
license = "MIT"
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
A comprehensive library for managing, identifying, and working with livestock breeds. Designed to support farming and ranching applications, breed registries, and livestock data processing.

Features
- 🌱 Support for over 500+ livestock breeds, categorized by species.
- 🌱 Support for over 600+ livestock breeds, categorized by species.
- 🐄 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 swine breeds like Duroc and Hampshire.
- 🫏 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.
Expand All @@ -19,7 +20,7 @@ Add the crate to your `Cargo.toml`:

```
[dependencies]
livestock_rs = "0.1.0"
livestock_rs = "0.6.0"
```

or
Expand Down Expand Up @@ -48,6 +49,10 @@ 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.

## Swine Breeds
- Features a wide variey of swine breeds including popular types like Duroc, KuneKune, Hampshire, and more.
- Regional specialties, including Oxford Sandy & Black, Ba Xuyen, and Arapawa Island.

## Donkey Breeds
- Features common donkey breeds including Standard, Large Standard, Miniature, Mary, Mammoth Jack Stock, and more.

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod cattle;
pub mod donkey;
pub mod goat;
pub mod reindeer;
pub mod sheep;
pub mod sheep;
pub mod swine;
262 changes: 262 additions & 0 deletions src/swine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
use inflector::Inflector;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

/// An enum representing the different breeds of swine.
///
/// Initial data from: <https://breeds.okstate.edu/swine/>
///
/// # Examples
/// ``` rust
/// use livestock_rs::swine::SwineBreed;
///
/// let breed = SwineBreed::Kunekune;
/// println!("{:?}", breed);
/// ```
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum SwineBreed {
AmericanLandrace,
AmericanYorkshire,
AngelnSaddleback,
ArapawaIsland,
BaXuyen,
Bantu,
BeijingBlack,
BelarusBlackPied,
BelgianLandrace,
Berkshire,
BritishLandrace,
BritishLop,
BulgarianWhite,
Cantonese,
ChesterWhite,
ChoctawHog,
CzechImprovedWhite,
DanishLandrace,
Duroc,
DutchLandrace,
Fengjing,
FinnishLandrace,
FrenchLandrace,
GermanLandrace,
GloucestershireOldSpot,
GuineaHog,
Hampshire,
Hereford,
Hezuo,
Iberian,
ItalianLandrace,
Jinhua,
Kele,
Krskopolje,
Kunekune,
Lacombe,
LargeBlack,
LargeBlackWhite,
LargeWhite,
Lithuanian,
Mangalitza,
Meishan,
MiddleWhite,
MongCai,
Minzhu,
MoraRomagnola,
Mukota,
Mulefoot,
Neijiang,
Ningxiang,
NorwegianLandrace,
OssabawIsland,
OxfordSandyAndBlack,
PhilippineNative,
Pietrain,
PolandChina,
RedWattle,
Saddleback,
Spotted,
SwedishLandrace,
Tamworth,
ThuocNhieu,
Tibetan,
Thuropolje,
VietnamesePotbelly,
Welsh,
Wuzhishan,
Yorkshire
}


impl ToString for SwineBreed {
/// Converts the SwineBreed enum to a human readable string.
///
/// # Examples
/// ``` rust
/// use livestock_rs::swine::SwineBreed;
///
/// let kune = SwineBreed::Kunekune;
/// println!("{}", kune.to_string());
/// ```
fn to_string(&self) -> String {
match self {
SwineBreed::LargeBlackWhite => "Large Black-White".to_string(),
_ => format!("{:?}", self).to_title_case(),
}
}
}

/// Converts a string to a SwineBreed enum.
///
/// # Examples
/// ``` rust
/// use livestock_rs::swine::SwineBreed;
/// use std::str::FromStr;
///
/// let breed = SwineBreed::from_str("kunekune").unwrap();
/// println!("{:?}", breed);
/// ```

impl FromStr for SwineBreed {
type Err = std::io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"american landrace" => Ok(SwineBreed::AmericanLandrace),
"american yorkshire" => Ok(SwineBreed::AmericanYorkshire),
"angeln saddleback" => Ok(SwineBreed::AngelnSaddleback),
"arapawa island" | "arapawa" => Ok(SwineBreed::ArapawaIsland),
"ba xuyen" => Ok(SwineBreed::BaXuyen),
"bantu" => Ok(SwineBreed::Bantu),
"beijing black" => Ok(SwineBreed::BeijingBlack),
"belarus black pied" => Ok(SwineBreed::BelarusBlackPied),
"belgian landrace" => Ok(SwineBreed::BelgianLandrace),
"berkshire" => Ok(SwineBreed::Berkshire),
"british landrace" => Ok(SwineBreed::BritishLandrace),
"british lop" => Ok(SwineBreed::BritishLop),
"bulgarian white" => Ok(SwineBreed::BulgarianWhite),
"cantonese" => Ok(SwineBreed::Cantonese),
"chester white" => Ok(SwineBreed::ChesterWhite),
"choctaw hog" => Ok(SwineBreed::ChoctawHog),
"czech improved white" => Ok(SwineBreed::CzechImprovedWhite),
"danish landrace" => Ok(SwineBreed::DanishLandrace),
"duroc" => Ok(SwineBreed::Duroc),
"dutch landrace" => Ok(SwineBreed::DutchLandrace),
"fengjing" => Ok(SwineBreed::Fengjing),
"finnish landrace" => Ok(SwineBreed::FinnishLandrace),
"french landrace" => Ok(SwineBreed::FrenchLandrace),
"german landrace" => Ok(SwineBreed::GermanLandrace),
"gloucestershire old spot" => Ok(SwineBreed::GloucestershireOldSpot),
"guinea hog" => Ok(SwineBreed::GuineaHog),
"hampshire" => Ok(SwineBreed::Hampshire),
"hereford" => Ok(SwineBreed::Hereford),
"hezuo" => Ok(SwineBreed::Hezuo),
"iberian" => Ok(SwineBreed::Iberian),
"italian landrace" => Ok(SwineBreed::ItalianLandrace),
"jinhua" => Ok(SwineBreed::Jinhua),
"kele" => Ok(SwineBreed::Kele),
"krskopolje" => Ok(SwineBreed::Krskopolje),
"kunekune" => Ok(SwineBreed::Kunekune),
"lacombe" => Ok(SwineBreed::Lacombe),
"large black" => Ok(SwineBreed::LargeBlack),
"large black-white" | "large black white"=> Ok(SwineBreed::LargeBlackWhite),
"large white" => Ok(SwineBreed::LargeWhite),
"lithuanian" => Ok(SwineBreed::Lithuanian),
"mangalitza" => Ok(SwineBreed::Mangalitza),
"meishan" => Ok(SwineBreed::Meishan),
"middle white" => Ok(SwineBreed::MiddleWhite),
"mong cai" => Ok(SwineBreed::MongCai),
"minzhu" => Ok(SwineBreed::Minzhu),
"mora romagnola" => Ok(SwineBreed::MoraRomagnola),
"mukota" => Ok(SwineBreed::Mukota),
"mulefoot" => Ok(SwineBreed::Mulefoot),
"neijiang" => Ok(SwineBreed::Neijiang),
"ningxiang" => Ok(SwineBreed::Ningxiang),
"norwegian landrace" => Ok(SwineBreed::NorwegianLandrace),
"ossabaw island" => Ok(SwineBreed::OssabawIsland),
"oxford sandy and black" | "oxford sandy & black"=> Ok(SwineBreed::OxfordSandyAndBlack),
"philippine native" => Ok(SwineBreed::PhilippineNative),
"pietrain" => Ok(SwineBreed::Pietrain),
"poland china" => Ok(SwineBreed::PolandChina),
"red wattle" => Ok(SwineBreed::RedWattle),
"saddleback" => Ok(SwineBreed::Saddleback),
"spotted" => Ok(SwineBreed::Spotted),
"swedish landrace" => Ok(SwineBreed::SwedishLandrace),
"tamworth" => Ok(SwineBreed::Tamworth),
"thuoc nhieu" => Ok(SwineBreed::ThuocNhieu),
"tibetan" => Ok(SwineBreed::Tibetan),
"thuropolje" => Ok(SwineBreed::Thuropolje),
"vietnamese potbelly" | "potbelly" | "potbellied" | "vietnamese potbellied" => Ok(SwineBreed::VietnamesePotbelly),
"welsh" => Ok(SwineBreed::Welsh),
"wuzhishan" => Ok(SwineBreed::Wuzhishan),
"yorkshire" => Ok(SwineBreed::Yorkshire),
_ => Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "Invalid reindeer breed")),
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_to_string() {
// We don't have many special cases, just test a few.
let breeds = [
(SwineBreed::LargeBlackWhite, "Large Black-White"),
(SwineBreed::AmericanLandrace, "American Landrace"),
(SwineBreed::AmericanYorkshire, "American Yorkshire"),
(SwineBreed::AngelnSaddleback, "Angeln Saddleback"),
(SwineBreed::ArapawaIsland, "Arapawa Island"),
(SwineBreed::BaXuyen, "Ba Xuyen"),
(SwineBreed::Bantu, "Bantu"),
(SwineBreed::BeijingBlack, "Beijing Black"),
(SwineBreed::BelarusBlackPied, "Belarus Black Pied"),
(SwineBreed::BelgianLandrace, "Belgian Landrace"),
(SwineBreed::Berkshire, "Berkshire"),
(SwineBreed::BritishLandrace, "British Landrace"),
(SwineBreed::BritishLop, "British Lop"),
(SwineBreed::BulgarianWhite, "Bulgarian White"),
(SwineBreed::Cantonese, "Cantonese"),
(SwineBreed::ChesterWhite, "Chester White"),
(SwineBreed::ChoctawHog, "Choctaw Hog"),
(SwineBreed::CzechImprovedWhite, "Czech Improved White"),
(SwineBreed::DanishLandrace, "Danish Landrace"),
(SwineBreed::Duroc, "Duroc"),
(SwineBreed::DutchLandrace, "Dutch Landrace"),
(SwineBreed::Fengjing, "Fengjing"),
(SwineBreed::FinnishLandrace, "Finnish Landrace"),
(SwineBreed::FrenchLandrace, "French Landrace"),
(SwineBreed::GermanLandrace, "German Landrace"),
(SwineBreed::GloucestershireOldSpot, "Gloucestershire Old Spot"),
(SwineBreed::GuineaHog, "Guinea Hog"),
(SwineBreed::Hampshire, "Hampshire"),
(SwineBreed::Hereford, "Hereford")
];

for (breed, expected) in breeds.iter() {
assert_eq!(breed.to_string(), *expected);
}
}

#[test]
fn test_from_str() {
// We don't have many special cases, just test a few.
let breeds = [
("american landrace", SwineBreed::AmericanLandrace),
("american yorkshire", SwineBreed::AmericanYorkshire),
("angeln saddleback", SwineBreed::AngelnSaddleback),
("arapawa island", SwineBreed::ArapawaIsland),
("ba xuyen", SwineBreed::BaXuyen),
("potbelly", SwineBreed::VietnamesePotbelly),
("potbellied", SwineBreed::VietnamesePotbelly),
("vietnamese potbelly", SwineBreed::VietnamesePotbelly),
("vietnamese potbellied", SwineBreed::VietnamesePotbelly),
("oxford sandy and black", SwineBreed::OxfordSandyAndBlack),
("oxford sandy & black", SwineBreed::OxfordSandyAndBlack),
("large black-white", SwineBreed::LargeBlackWhite),
("large black white", SwineBreed::LargeBlackWhite)
];

for (breed, expected) in breeds.iter() {
assert_eq!(SwineBreed::from_str(*breed).unwrap(), *expected);
}
}
}
Loading