Open andrewwhitehead opened 2 weeks ago
Actually that definition doesn't work because the lifetime of S
needs to be guaranteed. It would probably need to be something like this:
/// Expose a reference to an inner secret
pub trait ExposeSecret<'a, S: ?Sized> {
type Ref: Deref<Target=S>;
/// Expose secret: this is the only method providing access to a secret.
fn expose_secret(&'a self) -> Self::Ref;
}
/// Expose a mutable reference to an inner secret
pub trait ExposeSecretMut<'a, S: ?Sized> {
type RefMut: DerefMut<Target=S>;
/// Expose secret: this is the only method providing access to a secret.
fn expose_secret_mut(&'a mut self) -> Self::RefMut;
}
I'm also not sure why ExposeSecretMut
doesn't require ExposeSecret
, such as how DerefMut
requires Deref
.
The ExposeSecret interface seems a little restricted by only being able to return references and not managed handles. I wonder how much a breaking change something this would be?