mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
implement Mutable trait for vec
This commit is contained in:
parent
d95c9cbe38
commit
ec3f6e1932
@ -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 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};
|
||||
|
@ -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 @@ 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> {
|
||||
fn push_all(&mut self, rhs: &[const 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.
|
||||
}
|
||||
|
||||
#[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]) {
|
||||
|
Loading…
Reference in New Issue
Block a user