implement Mutable trait for vec

This commit is contained in:
Daniel Micay 2013-01-24 23:08:16 -05:00
parent d95c9cbe38
commit ec3f6e1932
3 changed files with 16 additions and 3 deletions

View File

@ -190,7 +190,7 @@ pub use path::PosixPath;
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps}; pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
pub use str::{StrSlice, Trimmable}; pub use str::{StrSlice, Trimmable};
pub use container::Container; pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector}; pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector}; pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector}; pub use vec::{OwnedVector, OwnedCopyableVector};

View File

@ -29,7 +29,7 @@ pub use path::PosixPath;
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps}; pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
pub use str::{StrSlice, Trimmable}; pub use str::{StrSlice, Trimmable};
pub use container::Container; pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector}; pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector}; pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector}; pub use vec::{OwnedVector, OwnedCopyableVector};

View File

@ -14,7 +14,7 @@
#[forbid(deprecated_pattern)]; #[forbid(deprecated_pattern)];
#[warn(non_camel_case_types)]; #[warn(non_camel_case_types)];
use container::Container; use container::{Container, Mutable};
use cast::transmute; use cast::transmute;
use cast; use cast;
use cmp::{Eq, Ord}; use cmp::{Eq, Ord};
@ -1941,6 +1941,11 @@ impl<T> ~[T]: OwnedVector<T> {
} }
} }
impl<T> ~[T]: Mutable {
/// Clear the vector, removing all values.
fn clear(&mut self) { self.truncate(0) }
}
pub trait OwnedCopyableVector<T: Copy> { pub trait OwnedCopyableVector<T: Copy> {
fn push_all(&mut self, rhs: &[const T]); fn push_all(&mut self, rhs: &[const T]);
fn grow(&mut self, n: uint, initval: &T); fn grow(&mut self, n: uint, initval: &T);
@ -2692,6 +2697,14 @@ mod tests {
// If the unsafe block didn't drop things properly, we blow up here. // If the unsafe block didn't drop things properly, we blow up here.
} }
#[test]
fn test_clear() {
let mut v = ~[@6,@5,@4];
v.clear();
assert(v.len() == 0);
// If the unsafe block didn't drop things properly, we blow up here.
}
#[test] #[test]
fn test_dedup() { fn test_dedup() {
fn case(a: ~[uint], b: ~[uint]) { fn case(a: ~[uint], b: ~[uint]) {