diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-08 14:05:29 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-08 14:07:20 +0100 |
commit | e66929d6d5928ca882b1060fcd8e42cae89da1dd (patch) | |
tree | a92b7a566b4ad3984738ad1ff23c5b9ca2703383 /src/util | |
parent | 24fff4c70f07fd51dee40aea52f136bc69f75d65 (diff) |
Use EnvironmentVariableName type for names of ENV variables
This makes the typing a bit more helpful by using a type for the name of
environment variables.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/mod.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/util/mod.rs b/src/util/mod.rs index 5f6a35f..478962a 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,8 +1,28 @@ +use serde::Serialize; use serde::Deserialize; -#[derive(Deserialize, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)] +#[serde(transparent)] pub struct EnvironmentVariableName(String); +impl From<&str> for EnvironmentVariableName { + fn from(s: &str) -> EnvironmentVariableName { + EnvironmentVariableName(s.to_string()) + } +} + +impl AsRef<str> for EnvironmentVariableName { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + +impl std::fmt::Display for EnvironmentVariableName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { + self.0.fmt(f) + } +} + pub mod docker; pub mod filters; pub mod git; |