Enum borrowned::Borrowned [−][src]
pub enum Borrowned<'b, T> {
Owned(T),
Borrowed(&'b mut T),
}
Expand description
A smart pointer that either owns or mutably borrows a value.
Example
use borrowned::Borrowned;
fn print_text(text: &Borrowned<'_, String>) {
println!("{}", text);
}
let owned = Borrowned::Owned("hello".to_string());
let mut owned2 = "world".to_string();
let borrowed = Borrowned::Borrowed(&mut owned2);
print_text(&owned);
print_text(&borrowed);
print_text(&owned2.into());
Variants
Contains the owned value
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> RefUnwindSafe for Borrowned<'b, T> where
T: RefUnwindSafe,
impl<'b, T> !UnwindSafe for Borrowned<'b, T>
Blanket Implementations
Mutably borrows from an owned value. Read more