Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make associated functions on Secret #[must_use] #42

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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