diff options
| author | Derek Harland <derek.harland@finq.co.nz> | 2014-07-31 15:57:29 +1200 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-31 11:50:24 -0700 |
| commit | 2467c6e5a7fe008c33fdc1060a5ce869d6219a92 (patch) | |
| tree | ec8c58e4bbace51dac1c2174c98e86435e1f0192 /src/libstd | |
| parent | bc24819bb298f5ab1d89ae74cab5ae5f26423bba (diff) | |
| download | rust-2467c6e5a7fe008c33fdc1060a5ce869d6219a92.tar.gz rust-2467c6e5a7fe008c33fdc1060a5ce869d6219a92.zip | |
Implement slice::Vector for Option<T> and CVec<T>
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/c_vec.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index a7d697c8665..80fe05fcea5 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -43,6 +43,7 @@ use option::{Option, Some, None}; use ptr::RawPtr; use ptr; use raw; +use slice::Vector; /// The type representing a foreign chunk of memory pub struct CVec<T> { @@ -101,13 +102,6 @@ impl<T> CVec<T> { } } - /// View the stored data as a slice. - pub fn as_slice<'a>(&'a self) -> &'a [T] { - unsafe { - mem::transmute(raw::Slice { data: self.base as *const T, len: self.len }) - } - } - /// View the stored data as a mutable slice. pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { @@ -151,6 +145,15 @@ impl<T> CVec<T> { } } +impl<T> Vector<T> for CVec<T> { + /// View the stored data as a slice. + fn as_slice<'a>(&'a self) -> &'a [T] { + unsafe { + mem::transmute(raw::Slice { data: self.base as *const T, len: self.len }) + } + } +} + impl<T> Collection for CVec<T> { fn len(&self) -> uint { self.len } } |
