diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-01-24 23:08:16 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-01-24 23:10:14 -0500 |
| commit | ec3f6e1932db297d2a575e591d4c508d785a0a52 (patch) | |
| tree | b5576dfab3ef7c0fdbad5062ac1cbaeb24e8ef87 | |
| parent | d95c9cbe3891837b7e608473876fcd97dc35a6c9 (diff) | |
implement Mutable trait for vec
| -rw-r--r-- | src/libcore/core.rc | 2 | ||||
| -rw-r--r-- | src/libcore/prelude.rs | 2 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 15 |
3 files changed, 16 insertions, 3 deletions
diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 6707dacec3d..f7a65ed1fe4 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -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}; diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index b904e200a34..72aa828ff12 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -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}; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 007e85d13b5..7f6999e5163 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -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); @@ -2693,6 +2698,14 @@ mod tests { } #[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]) { let mut v = a; |
