Enum borrowned::BorrownedBox [−][src]
Expand description
A smart pointer that either owns or mutably borrows a value.
Example
use borrowned::BorrownedBox;
fn print_text(text: &BorrownedBox<'_, String>) {
println!("{}", text);
}
let owned = BorrownedBox::Owned(Box::new("hello".to_string()));
let mut owned2 = Box::new("world".to_string());
let borrowed = BorrownedBox::Borrowed(&mut *owned2);
print_text(&owned);
print_text(&borrowed);
print_text(&owned2.into());
Variants
Owned(Box<T>)
Contains the owned value
Tuple Fields of Owned
0: Box<T>
Borrowed(&'b mut T)
Contains the borrowed value
Tuple Fields of Borrowed
0: &'b mut T
Implementations
Extracts the owned data.
Returns self
in Err
if it’s not owned.
Extracts the borrowed data.
Returns self
in Err
if it’s not borrowed.
Trait Implementations
Mutably borrows from an owned value. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<'b, T: ?Sized> RefUnwindSafe for BorrownedBox<'b, T> where
T: RefUnwindSafe,
impl<'b, T: ?Sized> Send for BorrownedBox<'b, T> where
T: Send,
impl<'b, T: ?Sized> Sync for BorrownedBox<'b, T> where
T: Sync,
impl<'b, T: ?Sized> Unpin for BorrownedBox<'b, T>
impl<'b, T> !UnwindSafe for BorrownedBox<'b, T>
Blanket Implementations
Mutably borrows from an owned value. Read more