pub enum Managed<'a, T: 'a + ?Sized> {
Borrowed(&'a mut T),
Owned(Box<T>),
}
Expand description
A managed object.
This enum can be used to represent exclusive access to objects. In Rust, exclusive access to an object is obtained by either owning the object, or owning a mutable pointer to the object; hence, “managed”.
The purpose of this enum is providing good ergonomics with std
present while making
it possible to avoid having a heap at all (which of course means that std
is not present).
To achieve this, the variants other than Borrow
are only available when the corresponding
feature is opted in.
A function that requires a managed object should be generic over an Into<Managed<'a, T>>
argument; then, it will be possible to pass either a Box<T>
, Vec<T>
, or a &'a mut T
without any conversion at the call site.
Note that a Vec<T>
converted into an Into<Managed<'a, [T]>>
gets transformed
into a boxed slice, and can no longer be resized. See also
ManagedSlice, which does not have this drawback.
Variants
Borrowed(&'a mut T)
Borrowed variant.
Owned(Box<T>)
Owned variant, only available with the std
or alloc
feature enabled.
Trait Implementations
Auto Trait Implementations
impl<'a, T: ?Sized> RefUnwindSafe for Managed<'a, T> where
T: RefUnwindSafe,
impl<'a, T: ?Sized> Send for Managed<'a, T> where
T: Send,
impl<'a, T: ?Sized> Sync for Managed<'a, T> where
T: Sync,
impl<'a, T: ?Sized> Unpin for Managed<'a, T>
impl<'a, T> !UnwindSafe for Managed<'a, T>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more