Rename Sensitive::into_inner() from ::unwrap()
By analogy with similar methods on Mutex, Cell, BufReader, etc. etc. Discussed here https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/890#note_2856885 Make it a method, as per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/928
This commit is contained in:
parent
879c4cdbf3
commit
5611d5cb0c
|
@ -0,0 +1,2 @@
|
|||
ADDED: Sensitive::into_inner
|
||||
DEPRECATED: Sensitive::unwrap
|
|
@ -86,10 +86,14 @@ impl<T> Sensitive<T> {
|
|||
}
|
||||
|
||||
/// Extract the inner value from this `Sensitive<T>`.
|
||||
//
|
||||
// TODO(Diziet) shouldn't this be called `into_inner` ?
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Extract the inner value from this `Sensitive<T>`.
|
||||
#[deprecated = "Use the new into_inner method instead"]
|
||||
pub fn unwrap(sensitive: Sensitive<T>) -> T {
|
||||
sensitive.0
|
||||
sensitive.into_inner()
|
||||
}
|
||||
|
||||
/// Converts `&Sensitive<T>` to `Sensitive<&T>`
|
||||
|
@ -171,7 +175,7 @@ impl<T> BoxSensitive<T> {
|
|||
pub fn into_inner(self) -> T {
|
||||
// TODO want unstable Box::into_inner(self.0) rust-lang/rust/issues/80437
|
||||
let unboxed = *self.0;
|
||||
Sensitive::unwrap(unboxed)
|
||||
unboxed.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,10 +347,20 @@ mod test {
|
|||
assert_eq!(format!("{:?}", &sv), "[104, 49]");
|
||||
|
||||
assert_eq!(sv, SVec::from(vec![104, 49]));
|
||||
assert_eq!(SVec::unwrap(sv.clone()), vec![104, 49]);
|
||||
assert_eq!(sv.clone().into_inner(), vec![104, 49]);
|
||||
assert_eq!(*sv, vec![104, 49]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
#[allow(deprecated)]
|
||||
fn deprecated() {
|
||||
type SVec = Sensitive<Vec<u32>>;
|
||||
let sv = Sensitive(vec![104, 49]);
|
||||
|
||||
assert_eq!(SVec::unwrap(sv), vec![104, 49]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn display_various() {
|
||||
|
|
Loading…
Reference in New Issue