@@ -32,6 +32,14 @@ pub struct Secret<T> {
3232}
3333
3434impl < T > Secret < T > {
35+ /// Unwraps the contained value.
36+ ///
37+ /// Use of this method marks the boundary of where the contained value is
38+ /// hidden.
39+ pub fn expose ( self ) -> T {
40+ self . inner
41+ }
42+
3543 /// Converts a `Secret<T>` to a `Secret<&T::Target>`.
3644 ///
3745 /// For example, this can be used to convert from `&Secret<String>` to
@@ -43,16 +51,16 @@ impl<T> Secret<T> {
4351 Secret :: from ( self . inner . deref ( ) )
4452 }
4553
54+ pub fn as_ref ( & self ) -> Secret < & T > {
55+ Secret :: from ( & self . inner )
56+ }
57+
4658 pub fn map < U , F > ( self , f : F ) -> Secret < U >
4759 where
4860 F : FnOnce ( T ) -> U ,
4961 {
5062 Secret :: from ( f ( self . inner ) )
5163 }
52-
53- fn into_inner ( self ) -> T {
54- self . inner
55- }
5664}
5765
5866impl < T : ToOwned + ?Sized > Secret < & T > {
@@ -66,6 +74,12 @@ impl<T: ToOwned + ?Sized> Secret<&T> {
6674 }
6775}
6876
77+ impl < T , E > Secret < Result < T , E > > {
78+ pub fn transpose ( self ) -> Result < Secret < T > , E > {
79+ self . inner . map ( |v| Secret :: from ( v) )
80+ }
81+ }
82+
6983impl < T : AsRef < str > > Secret < T > {
7084 pub fn is_empty ( & self ) -> bool {
7185 self . inner . as_ref ( ) . is_empty ( )
0 commit comments