Skip to content

Commit c1df7e9

Browse files
secrecy: rename constructor methods to init_with (#1212)
Previously they were named `*new_with_ctr` which is a somewhat confusing name (particularly to anyone who works in cryptography where "ctr" registers as counter mode). The `init_with` name is commonly used for these sorts of `Fn`-based constructors.
1 parent 59267c0 commit c1df7e9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

secrecy/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<S: Zeroize + Clone> SecretBox<S> {
106106
///
107107
/// **Note:** using [`Self::new`] or [`Self::new_with_mut`] is preferable when possible,
108108
/// since this method's safety relies on empyric evidence and may be violated on some targets.
109-
pub fn new_with_ctr(ctr: impl FnOnce() -> S) -> Self {
109+
pub fn init_with(ctr: impl FnOnce() -> S) -> Self {
110110
let mut data = ctr();
111111
let secret = Self {
112112
inner_secret: Box::new(data.clone()),
@@ -115,12 +115,12 @@ impl<S: Zeroize + Clone> SecretBox<S> {
115115
secret
116116
}
117117

118-
/// Same as [`Self::new_with_ctr`], but the constructor can be fallible.
118+
/// Same as [`Self::init_with`], but the constructor can be fallible.
119119
///
120120
///
121121
/// **Note:** using [`Self::new`] or [`Self::new_with_mut`] is preferable when possible,
122122
/// since this method's safety relies on empyric evidence and may be violated on some targets.
123-
pub fn try_new_with_ctr<E>(ctr: impl FnOnce() -> Result<S, E>) -> Result<Self, E> {
123+
pub fn try_init_with<E>(ctr: impl FnOnce() -> Result<S, E>) -> Result<Self, E> {
124124
let mut data = ctr()?;
125125
let secret = Self {
126126
inner_secret: Box::new(data.clone()),
@@ -209,7 +209,7 @@ where
209209
where
210210
D: de::Deserializer<'de>,
211211
{
212-
Self::try_new_with_ctr(|| T::deserialize(deserializer))
212+
Self::try_init_with(|| T::deserialize(deserializer))
213213
}
214214
}
215215

0 commit comments

Comments
 (0)