pub struct ScopedMut<'a, T: Closeable> { /* private fields */ }
Expand description
A wrapper for a non-shared (mutable) reference to a Closeable
type.
The wrapped item is reached by de-referencing the Scoped
handle,
and is automatically close()
d when the Scoped
handle
is dropped.
Note that de-referencing returns a shared reference to the wrapped item.
A mutable reference is obtained by calling as_mut()
, which returns a Pin<&mut T>
Implementations§
§impl<'a, T: Closeable> ScopedMut<'a, T>
impl<'a, T: Closeable> ScopedMut<'a, T>
pub fn as_mut(&mut self) -> Pin<&mut T>
pub fn as_mut(&mut self) -> Pin<&mut T>
Get a non-shared (mutable) reference to the contained item
Note that the returned type is Pin<&mut T>
rather than &mut T
(owing to constraints
imposed by cxx
)
Example
The scoped bytes writer returned by ExcerptAppender::scoped_bytes_writer()
is a ScopedMut
wrapping a BytesWriter
.
let mut appender = queue.acquire_appender().unwrap();
let mut bytes = appender.scoped_bytes_writer(MSGSIZE);
let slice = bytes.as_mut().as_slice();