Skip to content

Commit

Permalink
feat: make associated functions on Secret #[must_use]
Browse files Browse the repository at this point in the history
  • Loading branch information
eopb committed Nov 1, 2023
1 parent 3170192 commit bb34087
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ pub struct Secret<T>(T);
impl<T> Secret<T> {
/// See [module level documentation][crate]
#[inline]
#[must_use = "the secret will be dropped if not used"]
pub const fn new(secret: T) -> Self {
Self(secret)
}
#[inline]
#[must_use]
pub fn from(secret: impl Into<T>) -> Self {
Self(secret.into())
}
#[inline]
#[must_use]
pub fn try_from<U: TryInto<T>>(secret: U) -> Result<Self, Secret<U::Error>> {
secret.try_into().map(Self).map_err(Secret)
}
/// See [module level documentation][crate]
#[inline]
#[must_use = "expose_secret does nothing unless used"]
pub const fn expose_secret(&self) -> &T {
&self.0
}
Expand Down

0 comments on commit bb34087

Please sign in to comment.