提交 ec3f6e19 编写于 作者: D Daniel Micay

implement Mutable trait for vec

上级 d95c9cbe
......@@ -190,7 +190,7 @@ pub use path::PosixPath;
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
pub use str::{StrSlice, Trimmable};
pub use container::Container;
pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector};
......
......@@ -29,7 +29,7 @@
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
pub use str::{StrSlice, Trimmable};
pub use container::Container;
pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector};
......
......@@ -14,7 +14,7 @@
#[forbid(deprecated_pattern)];
#[warn(non_camel_case_types)];
use container::Container;
use container::{Container, Mutable};
use cast::transmute;
use cast;
use cmp::{Eq, Ord};
......@@ -1941,6 +1941,11 @@ fn partition(self, f: fn(&T) -> bool) -> (~[T], ~[T]) {
}
}
impl<T> ~[T]: Mutable {
/// Clear the vector, removing all values.
fn clear(&mut self) { self.truncate(0) }
}
pub trait OwnedCopyableVector<T: Copy> {
fn push_all(&mut self, rhs: &[const T]);
fn grow(&mut self, n: uint, initval: &T);
......@@ -2692,6 +2697,14 @@ fn test_truncate() {
// 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]
fn test_dedup() {
fn case(a: ~[uint], b: ~[uint]) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册