Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Nov 19, 2024
1 parent c339ec3 commit 918340a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ impl typesize::TypeSize for SecretString {
pub struct Token(SecretString);

impl Token {
/// Fetch and parses the token out of the given environment variable.
///
/// # Errors
///
/// Returns [`TokenError::Env`] if fetching the variable fails (see [`std::env::var`] for
/// details). May also return [`TokenError::InvalidToken`] if the token is in an invalid
/// format (see [`Token::from_str`]).
pub fn from_env<K: AsRef<OsStr>>(key: K) -> Result<Self, TokenError> {
env::var(key).map_err(TokenError::Env).and_then(|token| token.parse())
}
Expand Down

0 comments on commit 918340a

Please sign in to comment.