Enum std::str::MaybeOwnedDeprecated [-]  [+] [src]

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

A string type that can hold either a String 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.

Examples

fn main() { let string = String::from_str("orange"); let maybe_owned_string = string.into_maybe_owned(); assert_eq!(true, maybe_owned_string.is_owned()); }
let string = String::from_str("orange");
let maybe_owned_string = string.into_maybe_owned();
assert_eq!(true, maybe_owned_string.is_owned());

fn is_slice(&self) -> bool

Returns true if this MaybeOwned wraps a borrowed string.

Examples

fn main() { let string = "orange"; let maybe_owned_string = string.as_slice().into_maybe_owned(); assert_eq!(true, maybe_owned_string.is_slice()); }
let string = "orange";
let maybe_owned_string = string.as_slice().into_maybe_owned();
assert_eq!(true, maybe_owned_string.is_slice());

fn len(&self) -> uint

Return the number of bytes in this string.

fn is_empty(&self) -> bool

Returns true if the string contains no bytes

Trait Implementations

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

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

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

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

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

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

Examples

fn main() { let str = "orange"; let maybe_owned_str = str.as_slice().into_maybe_owned(); let maybe_maybe_owned_str = maybe_owned_str.into_maybe_owned(); assert_eq!(false, maybe_maybe_owned_str.is_owned()); }
let str = "orange";
let maybe_owned_str = str.as_slice().into_maybe_owned();
let maybe_maybe_owned_str = maybe_owned_str.into_maybe_owned();
assert_eq!(false, maybe_maybe_owned_str.is_owned());

impl<'a> PartialEq<MaybeOwned<'a>> for MaybeOwned<'a>

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

fn ne(&self, &MaybeOwned<'a>) -> bool

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

fn assert_receiver_is_total_eq(&self)

impl<'a> PartialOrd<MaybeOwned<'a>> for MaybeOwned<'a>

fn partial_cmp(&self, other: &MaybeOwned) -> Option<Ordering>

fn lt(&self, &MaybeOwned<'a>) -> bool

fn le(&self, &MaybeOwned<'a>) -> bool

fn gt(&self, &MaybeOwned<'a>) -> bool

fn ge(&self, &MaybeOwned<'a>) -> bool

impl<'a> Ord 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 self) -> &'b str

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

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

fn clone_from(&mut self, &MaybeOwned<'a>)

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

fn default() -> MaybeOwned<'a>

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

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

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

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