Skip to content

Commit

Permalink
Add FromStr and Display trait implementation for Lang
Browse files Browse the repository at this point in the history
Closed #30

Signed-off-by: Avimitin <dev@avimit.in>
  • Loading branch information
Avimitin committed Apr 28, 2024
1 parent 4dd5c20 commit dc8a691
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/lang.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{fmt::Display, str::FromStr};

use paste::paste;
use serde::{Deserialize, Deserializer, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -88,12 +90,6 @@ macro_rules! generate_langs {
}
}
}

impl ToString for Lang {
fn to_string(&self) -> String {
self.as_ref().to_string()
}
}
}
};
}
Expand Down Expand Up @@ -151,3 +147,17 @@ impl<'de> Deserialize<'de> for Lang {
Ok(lang)
}
}

impl FromStr for Lang {
type Err = LangConvertError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Lang::try_from(s)
}
}

impl Display for Lang {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_ref())
}
}

0 comments on commit dc8a691

Please sign in to comment.