Skip to content

Commit

Permalink
#: Modify AnimalEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
zdu-strong committed Jan 29, 2025
1 parent 81b66e3 commit e128ab5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rust/src/enumable/animal_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ use strum_macros::EnumIter;
#[derive(Debug, Clone, Serialize, Deserialize, EnumIter)]
#[serde(rename_all = "camelCase")]
pub enum AnimalEnum {
Tiger,
Dog,
Tiger = 1,
Dog = 2,
}

impl AnimalEnum {
pub fn values() -> Vec<AnimalEnum> {
AnimalEnum::iter().collect::<Vec<_>>()
}

pub fn of(id: usize) -> AnimalEnum {
AnimalEnum::values()
.into_iter()
.filter(|s| (s.clone() as usize) == id)
.next()
.unwrap()
}

pub fn name(&mut self) -> String {
return match self {
AnimalEnum::Tiger => "Tiger".to_string(),
Expand Down

0 comments on commit e128ab5

Please sign in to comment.