sosecrets_rs/runtime/
traits.rs

1/// A trait for exposing secrets with runtime checking.
2pub trait RTExposeSecret<'secret, T> {
3    /// The type representing the `Error` variant as part of the `Result` returned type in `try_expose_secret`.
4    type Error: core::fmt::Display + core::fmt::Debug;
5
6    /// The type representing the exposed secret.
7    type Exposed<'brand>
8    where
9        'secret: 'brand;
10
11    /// Exposes the secret with runtime checking.
12    ///
13    /// # Parameters
14    /// - `scope`: A closure that takes the exposed secret and returns a value of the `ReturnType`.
15    ///
16    /// # Returns
17    /// The value returned by the closure.
18    fn expose_secret<ReturnType, ClosureType>(&self, scope: ClosureType) -> ReturnType
19    where
20        for<'brand> ClosureType: FnOnce(Self::Exposed<'brand>) -> ReturnType;
21
22    /// Tries to expose the secret with runtime checking.
23    ///
24    /// # Parameters
25    /// - `scope`: A closure that takes the exposed secret and returns a value of the `ReturnType`.
26    ///
27    /// # Returns
28    /// - `Ok`: The value returned by the closure.
29    /// - `Err`: If there is an error during exposure, it returns an error of type `Self::Error`.
30    fn try_expose_secret<ReturnType, ClosureType>(
31        &self,
32        scope: ClosureType,
33    ) -> Result<ReturnType, Self::Error>
34    where
35        for<'brand> ClosureType: FnOnce(Self::Exposed<'brand>) -> ReturnType;
36}