Skip to content

Instantly share code, notes, and snippets.

@Enigo
Created February 1, 2023 04:00
Show Gist options
  • Save Enigo/8c2d2314fba6bf64ee65c266730d8b80 to your computer and use it in GitHub Desktop.
Save Enigo/8c2d2314fba6bf64ee65c266730d8b80 to your computer and use it in GitHub Desktop.
pub fn as_parsed<T: FromStr>(key: &str) -> T
where
<T as FromStr>::Err: Debug,
{
as_string(key)
.parse::<T>()
.expect(format!("{} should be a valid u16", key).as_str())
}
pub fn as_string(key: &str) -> String {
String::from(
env::var(key)
.expect(format!("{} should be set", key).as_str())
.as_str(),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment