about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-21 20:06:44 -0700
committerbors <bors@rust-lang.org>2014-03-21 20:06:44 -0700
commitf5357cf3cee42d12249006a42dfa835f96ab5422 (patch)
treeab8bd94140ba08a70796786a6e5c63529a545f34 /src/libstd
parentbbf8cdc43feea08111abc5a59dc49a7f479d3103 (diff)
parente33676b7936b12bb68f47857ab3f8ea9b757d0d5 (diff)
downloadrust-f5357cf3cee42d12249006a42dfa835f96ab5422.tar.gz
rust-f5357cf3cee42d12249006a42dfa835f96ab5422.zip
auto merge of #13016 : huonw/rust/new-opt-vec, r=cmr
Replace syntax::opt_vec with syntax::owned_slice

The `owned_slice::OwnedSlice` is  `(*T, uint)` (i.e. a direct equivalent to DSTs `~[T]`).

This shaves two words off the old OptVec type; and also makes substituting in other implementations easy, by removing all the mutation methods. (And also everything that's very rarely/never used.)
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/vec.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 47eb275823a..34e4256e538 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -121,6 +121,19 @@ impl<T> Vec<T> {
         }
     }
 
+    /// Create a `Vec<T>` directly from the raw constituents.
+    ///
+    /// This is highly unsafe:
+    ///
+    /// - if `ptr` is null, then `length` and `capacity` should be 0
+    /// - `ptr` must point to an allocation of size `capacity`
+    /// - there must be `length` valid instances of type `T` at the
+    ///   beginning of that allocation
+    /// - `ptr` must be allocated by the default `Vec` allocator
+    pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut T) -> Vec<T> {
+        Vec { len: length, cap: capacity, ptr: ptr }
+    }
+
     /// Consumes the `Vec`, partitioning it based on a predcate.
     ///
     /// Partitions the `Vec` into two `Vec`s `(A,B)`, where all elements of `A`