core: Inherit non-allocating slice functionality

This commit adds a new trait, MutableVectorAllocating, which represents
functions on vectors which can allocate.

This is another extension trait to slices which should be removed once a lang
item exists for the ~ allocation.
This commit is contained in:
Alex Crichton 2014-04-30 22:54:25 -07:00
parent be0a11729e
commit 91ede1f09a
7 changed files with 1538 additions and 1556 deletions

View File

@ -69,4 +69,5 @@ pub mod iter;
pub mod option;
pub mod raw;
pub mod char;
pub mod slice;
pub mod tuple;

1483
src/libcore/slice.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1398,7 +1398,6 @@ impl<T: Iterator<char>> Parser<T> {
'n' => res.push_char('\n'),
'r' => res.push_char('\r'),
't' => res.push_char('\t'),
//<<<<<<< HEAD
'u' => match try!(self.decode_hex_escape()) {
0xDC00 .. 0xDFFF => return self.error(LoneLeadingSurrogateInHexEscape),

View File

@ -1291,6 +1291,39 @@ impl<T: Show> Show for Option<T> {
}
}
impl<'a, T: Show> Show for &'a [T] {
fn fmt(&self, f: &mut Formatter) -> Result {
if f.flags & (1 << (parse::FlagAlternate as uint)) == 0 {
try!(write!(f.buf, "["));
}
let mut is_first = true;
for x in self.iter() {
if is_first {
is_first = false;
} else {
try!(write!(f.buf, ", "));
}
try!(write!(f.buf, "{}", *x))
}
if f.flags & (1 << (parse::FlagAlternate as uint)) == 0 {
try!(write!(f.buf, "]"));
}
Ok(())
}
}
impl<'a, T: Show> Show for &'a mut [T] {
fn fmt(&self, f: &mut Formatter) -> Result {
secret_show(&self.as_slice(), f)
}
}
impl<T: Show> Show for ~[T] {
fn fmt(&self, f: &mut Formatter) -> Result {
secret_show(&self.as_slice(), f)
}
}
impl Show for () {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad("()")

View File

@ -76,7 +76,7 @@ pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
pub use slice::{ImmutableEqVector, ImmutableTotalOrdVector, ImmutableCloneableVector};
pub use slice::{OwnedVector};
pub use slice::{MutableVector, MutableTotalOrdVector};
pub use slice::{MutableVector, MutableTotalOrdVector, MutableVectorAllocating};
pub use slice::{Vector, VectorVector, CloneableVector, ImmutableVector};
pub use strbuf::StrBuf;
pub use vec::Vec;

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,7 @@ use rt::global_heap::{malloc_raw, realloc_raw};
use raw::Slice;
use slice::{ImmutableEqVector, ImmutableVector, Items, MutItems, MutableVector};
use slice::{MutableTotalOrdVector, OwnedVector, Vector};
use slice::{MutableVectorAllocating};
/// An owned, growable vector.
///