Skip to content

Commit 260c2dd

Browse files
donkopotamusalexcrichton
authored andcommitted
---
yaml --- r: 153975 b: refs/heads/try2 c: 2467c6e h: refs/heads/master i: 153973: 088e19c 153971: 69cebae 153967: 7a4cf56 v: v3
1 parent cbec6ef commit 260c2dd

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: bc24819bb298f5ab1d89ae74cab5ae5f26423bba
8+
refs/heads/try2: 2467c6e5a7fe008c33fdc1060a5ce869d6219a92
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/option.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
144144
use cmp::{PartialEq, Eq, Ord};
145145
use default::Default;
146+
use slice::Vector;
146147
use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize};
147148
use mem;
148149
use slice;
@@ -216,15 +217,6 @@ impl<T> Option<T> {
216217
match *self { Some(ref mut x) => Some(x), None => None }
217218
}
218219

219-
/// Convert from `Option<T>` to `&[T]` (without copying)
220-
#[inline]
221-
pub fn as_slice<'r>(&'r self) -> &'r [T] {
222-
match *self {
223-
Some(ref x) => slice::ref_slice(x),
224-
None => &[]
225-
}
226-
}
227-
228220
/// Convert from `Option<T>` to `&mut [T]` (without copying)
229221
#[inline]
230222
pub fn as_mut_slice<'r>(&'r mut self) -> &'r mut [T] {
@@ -526,6 +518,17 @@ impl<T: Default> Option<T> {
526518
// Trait implementations
527519
/////////////////////////////////////////////////////////////////////////////
528520

521+
impl<T> Vector<T> for Option<T> {
522+
/// Convert from `Option<T>` to `&[T]` (without copying)
523+
#[inline]
524+
fn as_slice<'a>(&'a self) -> &'a [T] {
525+
match *self {
526+
Some(ref x) => slice::ref_slice(x),
527+
None => &[]
528+
}
529+
}
530+
}
531+
529532
impl<T> Default for Option<T> {
530533
#[inline]
531534
fn default() -> Option<T> { None }

branches/try2/src/libstd/c_vec.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use option::{Option, Some, None};
4343
use ptr::RawPtr;
4444
use ptr;
4545
use raw;
46+
use slice::Vector;
4647

4748
/// The type representing a foreign chunk of memory
4849
pub struct CVec<T> {
@@ -101,13 +102,6 @@ impl<T> CVec<T> {
101102
}
102103
}
103104

104-
/// View the stored data as a slice.
105-
pub fn as_slice<'a>(&'a self) -> &'a [T] {
106-
unsafe {
107-
mem::transmute(raw::Slice { data: self.base as *const T, len: self.len })
108-
}
109-
}
110-
111105
/// View the stored data as a mutable slice.
112106
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
113107
unsafe {
@@ -151,6 +145,15 @@ impl<T> CVec<T> {
151145
}
152146
}
153147

148+
impl<T> Vector<T> for CVec<T> {
149+
/// View the stored data as a slice.
150+
fn as_slice<'a>(&'a self) -> &'a [T] {
151+
unsafe {
152+
mem::transmute(raw::Slice { data: self.base as *const T, len: self.len })
153+
}
154+
}
155+
}
156+
154157
impl<T> Collection for CVec<T> {
155158
fn len(&self) -> uint { self.len }
156159
}

0 commit comments

Comments
 (0)