You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the Secret type implements Unpin it can be moved out of a pin and therefore Pin doesn't help to pin a secret in memory AFAICT. (I might be wrong, I'm not an expert on pinning.)
Pin::into_inner() would not have been implemented if Secret didn't implement Unpin.
use pin_utils::pin_mut;use secrecy::{ExposeSecret,Secret};use std::mem;use std::pin::Pin;fnuse_secret(s:Secret<[u8;4]>){println!("Use secret {:?}", s.expose_secret());println!("ptr: {:x?}", s.expose_secret().as_ptr());}fnmain(){let a = Secret::new(*b"aaaa");println!("ptr: {:x?}", a.expose_secret().as_ptr());pin_mut!(a);println!("Use secret {:?}", a.expose_secret());let b = Pin::into_inner(a);// Moves secret even though we pinned it!let c = mem::replace(b,Secret::new(*b"bbbb"));use_secret(c);}
Since the
Secret
type implementsUnpin
it can be moved out of a pin and therefore Pin doesn't help to pin a secret in memory AFAICT. (I might be wrong, I'm not an expert on pinning.)Pin::into_inner()
would not have been implemented ifSecret
didn't implementUnpin
.I think the solution would be:
The text was updated successfully, but these errors were encountered: