Skip to content

Commit

Permalink
Simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
Razz4780 committed Feb 6, 2025
1 parent 147db39 commit 22b7b19
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions mirrord/agent/env/src/checked_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ pub trait EnvValue: Sized {
fn from_repr(repr: &[u8]) -> Result<Self, Self::FromReprError>;
}

pub trait StoredAsString: fmt::Display + FromStr {}
/// Convenience trait to mark value types that can be converted with [`ToString`] and [`FromStr`].
///
/// Implementors are provided with a blanket implementation of [`EnvValue`].
pub trait StoredAsString: ToString + FromStr {}

impl<T: StoredAsString> EnvValue for T {
type IntoReprError = Infallible;
Expand Down Expand Up @@ -132,18 +135,7 @@ impl StoredAsString for u32 {}

impl StoredAsString for SocketAddr {}

impl EnvValue for String {
type IntoReprError = Infallible;
type FromReprError = Utf8Error;

fn into_repr(&self) -> Result<String, Self::IntoReprError> {
Ok(self.clone())
}

fn from_repr(repr: &[u8]) -> Result<Self, Self::FromReprError> {
std::str::from_utf8(repr).map(From::from)
}
}
impl StoredAsString for String {}

impl EnvValue for Vec<IpAddr> {
type IntoReprError = Infallible;
Expand Down

0 comments on commit 22b7b19

Please sign in to comment.