[src]

Enum std::str::MaybeOwned

pub enum MaybeOwned<'a> {
    Slice(&'a str),
    Owned(~str),
}

A MaybeOwned is a string that can hold either a ~str or a &str. This can be useful as an optimization when an allocation is sometimes needed but not always.

Variants

Slice

A borrowed string

Owned

An owned string

Methods

impl<'a> MaybeOwned<'a>

fn is_owned(&self) -> bool

Returns true if this MaybeOwned wraps an owned string

fn is_slice(&self) -> bool

Returns true if this MaybeOwned wraps a borrowed string

Trait Implementations

impl<'a> IntoMaybeOwned<'a> for MaybeOwned<'a>

fn into_maybe_owned(self) -> MaybeOwned<'a>

Moves self into a MaybeOwned

impl<'a> Eq for MaybeOwned<'a>

fn eq(&self, other: &MaybeOwned) -> bool

fn ne(&self, other: &Self) -> bool

impl<'a> TotalEq for MaybeOwned<'a>

impl<'a> Ord for MaybeOwned<'a>

fn lt(&self, other: &MaybeOwned) -> bool

fn le(&self, other: &Self) -> bool

fn gt(&self, other: &Self) -> bool

fn ge(&self, other: &Self) -> bool

impl<'a> TotalOrd for MaybeOwned<'a>

fn cmp(&self, other: &MaybeOwned) -> Ordering

impl<'a, S: Str> Equiv<S> for MaybeOwned<'a>

fn equiv(&self, other: &S) -> bool

impl<'a> Str for MaybeOwned<'a>

fn as_slice<'b>(&'b self) -> &'b str

Work with self as a slice.

fn into_owned(self) -> ~str

Convert self into a ~str, not making a copy if possible

impl<'a> Container for MaybeOwned<'a>

fn len(&self) -> uint

Return the number of elements in the container

fn is_empty(&self) -> bool

Return true if the container contains no elements

impl<'a> Clone for MaybeOwned<'a>

fn clone(&self) -> MaybeOwned<'a>

Returns a copy of the value. The contents of owned pointers are copied to maintain uniqueness, while the contents of managed pointers are not copied.

fn clone_from(&mut self, source: &Self)

Perform copy-assignment from source.

a.clone_from(&b) is equivalent to a = b.clone() in functionality, but can be overridden to reuse the resources of a to avoid unnecessary allocations.

impl<'a> Default for MaybeOwned<'a>

fn default() -> MaybeOwned<'a>

Return the "default value" for a type.

impl<'a, H: Writer> Hash<H> for MaybeOwned<'a>

fn hash(&self, hasher: &mut H)

Compute a hash of the value.

impl<'a> Show for MaybeOwned<'a>

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl<'a> BytesContainer for MaybeOwned<'a>

fn container_as_bytes<'b>(&'b self) -> &'b [u8]

Returns a &[u8] representing the receiver

fn container_into_owned_bytes(self) -> ~[u8]

Consumes the receiver and converts it into ~[u8]

fn container_as_str<'b>(&'b self) -> Option<&'b str>

Returns the receiver interpreted as a utf-8 string, if possible

fn is_str(_: Option<MaybeOwned>) -> bool

Returns whether .container_as_str() is guaranteed to not fail