about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ops.rs51
-rw-r--r--src/libcore/slice.rs127
2 files changed, 99 insertions, 79 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs
index ad0f128a02e..77cee2b9863 100644
--- a/src/libcore/ops.rs
+++ b/src/libcore/ops.rs
@@ -688,19 +688,19 @@ pub trait IndexMut<Index, Result> {
  * struct Foo;
  *
  * impl ::core::ops::Slice<Foo, Foo> for Foo {
- *     fn as_slice_<'a>(&'a self) -> &'a Foo {
+ *     fn as_slice<'a>(&'a self) -> &'a Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_from_<'a>(&'a self, from: &Foo) -> &'a Foo {
+ *     fn slice_from<'a>(&'a self, from: &Foo) -> &'a Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_to_<'a>(&'a self, to: &Foo) -> &'a Foo {
+ *     fn slice_to<'a>(&'a self, to: &Foo) -> &'a Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
+ *     fn slice<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
  *         println!("Slicing!");
  *         self
  *     }
@@ -711,7 +711,22 @@ pub trait IndexMut<Index, Result> {
  * }
  * ```
  */
-// FIXME(#17273) remove the postscript _s
+#[cfg(not(stage0))]
+#[lang="slice"]
+pub trait Slice<Idx, Sized? Result> for Sized? {
+    /// The method for the slicing operation foo[]
+    fn as_slice<'a>(&'a self) -> &'a Result;
+    /// The method for the slicing operation foo[from..]
+    fn slice_from<'a>(&'a self, from: &Idx) -> &'a Result;
+    /// The method for the slicing operation foo[..to]
+    fn slice_to<'a>(&'a self, to: &Idx) -> &'a Result;
+    /// The method for the slicing operation foo[from..to]
+    fn slice<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result;
+}
+/**
+ *
+ */
+#[cfg(stage0)]
 #[lang="slice"]
 pub trait Slice<Idx, Sized? Result> for Sized? {
     /// The method for the slicing operation foo[]
@@ -738,19 +753,19 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
  * struct Foo;
  *
  * impl ::core::ops::SliceMut<Foo, Foo> for Foo {
- *     fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo {
+ *     fn as_mut_slice<'a>(&'a mut self) -> &'a mut Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_from_mut_<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
+ *     fn slice_from_mut<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_to_mut_<'a>(&'a mut self, to: &Foo) -> &'a mut Foo {
+ *     fn slice_to_mut<'a>(&'a mut self, to: &Foo) -> &'a mut Foo {
  *         println!("Slicing!");
  *         self
  *     }
- *     fn slice_mut_<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
+ *     fn slice_mut<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
  *         println!("Slicing!");
  *         self
  *     }
@@ -761,7 +776,22 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
  * }
  * ```
  */
-// FIXME(#17273) remove the postscript _s
+#[cfg(not(stage0))]
+#[lang="slice_mut"]
+pub trait SliceMut<Idx, Sized? Result> for Sized? {
+    /// The method for the slicing operation foo[]
+    fn as_mut_slice<'a>(&'a mut self) -> &'a mut Result;
+    /// The method for the slicing operation foo[from..]
+    fn slice_from_mut<'a>(&'a mut self, from: &Idx) -> &'a mut Result;
+    /// The method for the slicing operation foo[..to]
+    fn slice_to_mut<'a>(&'a mut self, to: &Idx) -> &'a mut Result;
+    /// The method for the slicing operation foo[from..to]
+    fn slice_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
+}
+/**
+ *
+ */
+#[cfg(stage0)]
 #[lang="slice_mut"]
 pub trait SliceMut<Idx, Sized? Result> for Sized? {
     /// The method for the slicing operation foo[mut]
@@ -773,6 +803,7 @@ pub trait SliceMut<Idx, Sized? Result> for Sized? {
     /// The method for the slicing operation foo[mut from..to]
     fn slice_mut_<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
 }
+
 /**
  *
  * The `Deref` trait is used to specify the functionality of dereferencing
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index b8828d310f0..68b3a3199df 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -61,32 +61,6 @@ use raw::Slice as RawSlice;
 /// Extension methods for immutable slices.
 #[unstable = "may merge with other traits; region parameter may disappear"]
 pub trait ImmutableSlice<'a, T> {
-    /// Returns a subslice spanning the interval [`start`, `end`).
-    ///
-    /// Fails when the end of the new slice lies beyond the end of the
-    /// original slice (i.e. when `end > self.len()`) or when `start > end`.
-    ///
-    /// Slicing with `start` equal to `end` yields an empty slice.
-    #[unstable = "waiting on final error conventions"]
-    //fn slice(&self, start: uint, end: uint) -> &'a [T];
-
-    /// Returns a subslice from `start` to the end of the slice.
-    ///
-    /// Fails when `start` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing from `self.len()` yields an empty slice.
-    #[unstable = "waiting on final error conventions"]
-    // TODO
-    //fn slice_from(&self, start: uint) -> &'a [T];
-
-    /// Returns a subslice from the start of the slice to `end`.
-    ///
-    /// Fails when `end` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing to `0` yields an empty slice.
-    #[unstable = "waiting on final error conventions"]
-    //fn slice_to(&self, end: uint) -> &'a [T];
-
     /// Divides one slice into two at an index.
     ///
     /// The first will contain all indices from `[0, mid)` (excluding
@@ -444,6 +418,35 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
     }
 }
 
+#[cfg(not(stage0))]
+impl<T> ops::Slice<uint, [T]> for [T] {
+    #[inline]
+    fn as_slice<'a>(&'a self) -> &'a [T] {
+        self
+    }
+
+    #[inline]
+    fn slice_from<'a>(&'a self, start: &uint) -> &'a [T] {
+        self.slice(start, &self.len())
+    }
+
+    #[inline]
+    fn slice_to<'a>(&'a self, end: &uint) -> &'a [T] {
+        self.slice(&0, end)
+    }
+    #[inline]
+    fn slice<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
+        assert!(*start <= *end);
+        assert!(*end <= self.len());
+        unsafe {
+            transmute(RawSlice {
+                    data: self.as_ptr().offset(*start as int),
+                    len: (*end - *start)
+                })
+        }
+    }
+}
+#[cfg(stage0)]
 impl<T> ops::Slice<uint, [T]> for [T] {
     #[inline]
     fn as_slice_<'a>(&'a self) -> &'a [T] {
@@ -471,7 +474,36 @@ impl<T> ops::Slice<uint, [T]> for [T] {
         }
     }
 }
+#[cfg(not(stage0))]
+impl<T> ops::SliceMut<uint, [T]> for [T] {
+    #[inline]
+    fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
+        self
+    }
+
+    #[inline]
+    fn slice_from_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
+        let len = &self.len();
+        self.slice_mut(start, len)
+    }
 
+    #[inline]
+    fn slice_to_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
+        self.slice_mut(&0, end)
+    }
+    #[inline]
+    fn slice_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
+        assert!(*start <= *end);
+        assert!(*end <= self.len());
+        unsafe {
+            transmute(RawSlice {
+                    data: self.as_ptr().offset(*start as int),
+                    len: (*end - *start)
+                })
+        }
+    }
+}
+#[cfg(stage0)]
 impl<T> ops::SliceMut<uint, [T]> for [T] {
     #[inline]
     fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
@@ -514,49 +546,6 @@ pub trait MutableSlice<'a, T> {
     #[deprecated = "use slicing syntax"]
     fn as_mut_slice(self) -> &'a mut [T];
 
-    /// Deprecated: use `slice_mut`.
-    #[deprecated = "use slicing syntax"]
-    //fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] {
-    //    self[mut start..end]
-    //}
-
-    /// Returns a mutable subslice spanning the interval [`start`, `end`).
-    ///
-    /// Fails when the end of the new slice lies beyond the end of the
-    /// original slice (i.e. when `end > self.len()`) or when `start > end`.
-    ///
-    /// Slicing with `start` equal to `end` yields an empty slice.
-    #[unstable = "waiting on final error conventions"]
-    //fn slice_mut(self, start: uint, end: uint) -> &'a mut [T];
-
-    /// Deprecated: use `slicing syntax`.
-    #[deprecated = "use slicing syntax"]
-    //fn mut_slice_from(self, start: uint) -> &'a mut [T] {
-    //    self[mut start..]
-    //}
-
-    /// Returns a mutable subslice from `start` to the end of the slice.
-    ///
-    /// Fails when `start` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing from `self.len()` yields an empty slice.
-    #[unstable = "waiting on final error conventions"]
-    //fn slice_from_mut(self, start: uint) -> &'a mut [T];
-
-    /// Deprecated: use `slicing syntax`.
-    #[deprecated = "use slicing syntax"]
-    //fn mut_slice_to(self, end: uint) -> &'a mut [T] {
-    //    self[mut ..end]
-    //}
-
-    /// Returns a mutable subslice from the start of the slice to `end`.
-    ///
-    /// Fails when `end` is strictly greater than the length of the original slice.
-    ///
-    /// Slicing to `0` yields an empty slice.
-    #[unstable = "waiting on final error conventions"]
-    //fn slice_to_mut(self, end: uint) -> &'a mut [T];
-
     /// Deprecated: use `iter_mut`.
     #[deprecated = "use iter_mut"]
     fn mut_iter(self) -> MutItems<'a, T> {