[−][src]Enum cervine::Cow
Cow
is a clone-on-write smart pointer largely analogous to alloc::borrow::Cow
, with one key difference:
Instead of requiring ToOwned
, the owned and borrowed type are both configurable and most methods require T: Borrow<R>
.
serde::Deserialize
and serde::Serialize
are only available with the "serde"
feature.
Variants
Implementations
impl<'a, T: Borrow<R>, R: ?Sized> Cow<'a, T, R>
[src]
pub fn is_borrowed(&self) -> bool
[src]
Returns whether this value is a borrowed variant.
Example
use cervine::Cow; let borrowed: Cow<String, _> = Cow::Borrowed("borrowed"); let owned: Cow<_, str> = Cow::Owned("owned".to_string()); assert!(borrowed.is_borrowed()); assert!(!owned.is_borrowed());
pub fn is_owned(&self) -> bool
[src]
Returns whether this value is an owned variant.
Example
use cervine::Cow; let borrowed: Cow<String, _> = Cow::Borrowed("borrowed"); let owned: Cow<_, str> = Cow::Owned("owned".to_string()); assert!(!borrowed.is_owned()); assert!(owned.is_owned());
impl<'a, T: From<&'a R>, R: ?Sized> Cow<'a, T, R>
[src]
pub fn into_owned(self) -> T
[src]
Converts this value into T
.
Example
use cervine::Cow; let borrowed = Cow::Borrowed("borrowed"); let owned: Cow<_, str> = Cow::Owned("owned".into()); let not_borrowed: String = borrowed.into_owned(); // Clones the `String`. let owned: String = owned.into_owned(); // Moves the `String`.
pub fn make_mut(&mut self) -> &mut T
[src]
Retrieves a mutable reference to the contained T
.
If this value is a borrowed variant, it is converted in place into an owned variant first.
Example
use cervine::Cow; let mut borrowed = Cow::Borrowed("borrowed"); let mut owned: Cow<_, str> = Cow::Owned("owned".into()); let mutable_copy: &mut String = borrowed.make_mut(); // Clones the `String`. let mutable_borrow: &mut String = owned.make_mut();
impl<'a, T: TryFrom<&'a R>, R: ?Sized> Cow<'a, T, R>
[src]
pub fn try_into_owned(self) -> Result<T, T::Error>
[src]
Converts this value into T
if possible.
Example
use cervine::Cow; let borrowed = Cow::Borrowed("borrowed"); let owned: Cow<_, str> = Cow::Owned("owned".into()); let not_borrowed: String = borrowed.try_into_owned()?; // Clones the `String`. let owned: String = owned.try_into_owned()?; // Moves the `String`.
Errors
<T as TryFrom<&'a R>>::Error
: Returned iff this value is a borrowed variant and conversion intoT
fails.
pub fn try_make_mut(&mut self) -> Result<&mut T, T::Error>
[src]
Retrieves a mutable reference to the contained T
, if possible.
If this value is a borrowed variant, an attempt is made to convert it in place into an owned variant first.
Example
use cervine::Cow; let mut borrowed = Cow::Borrowed("borrowed"); let mut owned: Cow<_, str> = Cow::Owned("owned".into()); let mutable_copy: &mut String = borrowed.try_make_mut()?; // Clones the `String`. let mutable_borrow: &mut String = owned.try_make_mut()?; // Moves the `String`.
Errors
<T as TryFrom<&'a R>>::Error
: Returned iff this value is a borrowed variant and conversion into the owned variant fails.
Trait Implementations
impl<'a, T: AsRef<R>, R: ?Sized> AsRef<R> for Cow<'a, T, R>
[src]
impl<'a, T: Borrow<R>, R: ?Sized> Borrow<R> for Cow<'a, T, R>
[src]
impl<'a, T: Clone, R: ?Sized> Clone for Cow<'a, T, R>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, T: Copy, R: ?Sized> Copy for Cow<'a, T, R>
[src]
impl<'a, T: Debug, R: Debug + ?Sized> Debug for Cow<'a, T, R>
[src]
impl<'a, T: Default, R: ?Sized> Default for Cow<'a, T, R>
[src]
impl<'a, T: Deref<Target = R>, R: ?Sized> Deref for Cow<'a, T, R>
[src]
impl<'a, T: Borrow<R>, R: Display + ?Sized> Display for Cow<'a, T, R>
[src]
impl<'a, T: Borrow<R>, R: Eq + ?Sized> Eq for Cow<'a, T, R>
[src]
impl<'a, T: Borrow<R>, R: Hash + ?Sized> Hash for Cow<'a, T, R>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, T: Borrow<R>, R: Ord + ?Sized> Ord for Cow<'a, T, R>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a, T: Borrow<R>, R: PartialEq + ?Sized> PartialEq<Cow<'a, T, R>> for Cow<'a, T, R>
[src]
impl<'a, T: Borrow<R>, R: PartialEq + ?Sized> PartialEq<R> for Cow<'a, T, R>
[src]
impl<'a, T: Borrow<R>, R: PartialOrd + ?Sized> PartialOrd<Cow<'a, T, R>> for Cow<'a, T, R>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn lt(&self, other: &Self) -> bool
[src]
fn le(&self, other: &Self) -> bool
[src]
fn gt(&self, other: &Self) -> bool
[src]
fn ge(&self, other: &Self) -> bool
[src]
impl<'a, T: Borrow<R>, R: PartialOrd + ?Sized> PartialOrd<R> for Cow<'a, T, R>
[src]
Auto Trait Implementations
impl<'a, T, R: ?Sized> Send for Cow<'a, T, R> where
R: Sync,
T: Send,
R: Sync,
T: Send,
impl<'a, T, R: ?Sized> Sync for Cow<'a, T, R> where
R: Sync,
T: Sync,
R: Sync,
T: Sync,
impl<'a, T, R: ?Sized> Unpin for Cow<'a, T, R> where
T: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,