Rust's string type is one of the core primitive types of the language. While
represented by the name `str`, the name `str` is not actually a valid type in
Rust. Each string must also be decorated with its ownership. This means that
-there are two common kinds of strings in rust:
+there are two common kinds of strings in Rust:
* `~str` - This is an owned string. This type obeys all of the normal semantics
of the `~T` types, meaning that it has one, and only one, owner. This
}
```
-From the example above, you can see that rust has 2 different kinds of string
+From the example above, you can see that Rust has 2 different kinds of string
literals. The owned literals correspond to the owned string types, but the
"borrowed literal" is actually more akin to C's concept of a static string.
# Mutability
-Many languages have immutable strings by default, and rust has a particular
+Many languages have immutable strings by default, and Rust has a particular
flavor on this idea. As with the rest of Rust types, strings are immutable by
default. If a string is declared as `mut`, however, it may be mutated. This
works the same way as the rest of Rust's type system in the sense that if
use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering};
use container::{Container, Mutable};
use fmt;
+use hash::{Hash, sip};
use iter::{Iterator, FromIterator, Extendable, range};
use iter::{Filter, AdditiveIterator, Map};
use iter::{Rev, DoubleEndedIterator, ExactSize};
use vec::{OwnedVector, OwnedCloneableVector, ImmutableVector, MutableVector};
use vec_ng::Vec;
use default::Default;
-use to_bytes::{IterBytes, Cb};
-use unstable::raw::Repr;
+use raw::Repr;
/*
Section: Creating a string
fn default() -> MaybeOwned<'a> { Slice("") }
}
-impl<'a> IterBytes for MaybeOwned<'a> {
+impl<'a> Hash for MaybeOwned<'a> {
#[inline]
- fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
- match *self {
- Slice(s) => s.iter_bytes(lsb0, f),
- Owned(ref s) => s.iter_bytes(lsb0, f)
- }
+ fn hash(&self, s: &mut sip::SipState) {
+ self.as_slice().hash(s)
}
}
use str::{is_utf8, OwnedStr, StrSlice};
use vec;
use vec::{MutableVector, ImmutableVector, OwnedVector};
- use unstable::raw::Slice;
+ use raw::Slice;
/// Create a Rust string from a *u8 buffer of the given length
pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {