}
}
+#[cfg(stage0)]
impl ops::Slice<uint, str> for String {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a str {
self[][*from..*to]
}
}
+#[cfg(not(stage0))]
+impl ops::Slice<uint, str> for String {
+ #[inline]
+ fn as_slice_<'a>(&'a self) -> &'a str {
+ self.as_slice()
+ }
+
+ #[inline]
+ fn slice_from_or_fail<'a>(&'a self, from: &uint) -> &'a str {
+ self[][*from..]
+ }
+
+ #[inline]
+ fn slice_to_or_fail<'a>(&'a self, to: &uint) -> &'a str {
+ self[][..*to]
+ }
+
+ #[inline]
+ fn slice_or_fail<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
+ self[][*from..*to]
+ }
+}
/// Unsafe operations
#[unstable = "waiting on raw module conventions"]
impl<T> TrieMap<T> {
// If `upper` is true then returns upper_bound else returns lower_bound.
+ #[cfg(stage0)]
#[inline]
fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
bound!(Entries, self = self,
slice_from = slice_from_, iter = iter,
mutability = )
}
+ #[cfg(not(stage0))]
+ #[inline]
+ fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
+ bound!(Entries, self = self,
+ key = key, is_upper = upper,
+ slice_from = slice_from_or_fail, iter = iter,
+ mutability = )
+ }
/// Gets an iterator pointing to the first key-value pair whose key is not less than `key`.
/// If all keys in the map are less than `key` an empty iterator is returned.
self.bound(key, true)
}
// If `upper` is true then returns upper_bound else returns lower_bound.
+ #[cfg(stage0)]
#[inline]
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
bound!(MutEntries, self = self,
slice_from = slice_from_mut_, iter = iter_mut,
mutability = mut)
}
+ #[cfg(not(stage0))]
+ #[inline]
+ fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
+ bound!(MutEntries, self = self,
+ key = key, is_upper = upper,
+ slice_from = slice_from_or_fail_mut, iter = iter_mut,
+ mutability = mut)
+ }
/// Deprecated: use `lower_bound_mut`.
#[deprecated = "use lower_bound_mut"]
}
}*/
+#[cfg(stage0)]
impl<T> ops::Slice<uint, [T]> for Vec<T> {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
self.as_slice().slice_(start, end)
}
}
+#[cfg(not(stage0))]
+impl<T> ops::Slice<uint, [T]> for Vec<T> {
+ #[inline]
+ fn as_slice_<'a>(&'a self) -> &'a [T] {
+ self.as_slice()
+ }
+
+ #[inline]
+ fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
+ self.as_slice().slice_from_or_fail(start)
+ }
+ #[inline]
+ fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
+ self.as_slice().slice_to_or_fail(end)
+ }
+ #[inline]
+ fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
+ self.as_slice().slice_or_fail(start, end)
+ }
+}
+
+#[cfg(stage0)]
impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
#[inline]
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
self.as_mut_slice().slice_mut_(start, end)
}
}
+#[cfg(not(stage0))]
+impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
+ #[inline]
+ fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
+ self.as_mut_slice()
+ }
+
+ #[inline]
+ fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
+ self.as_mut_slice().slice_from_or_fail_mut(start)
+ }
+
+ #[inline]
+ fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
+ self.as_mut_slice().slice_to_or_fail_mut(end)
+ }
+ #[inline]
+ fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
+ self.as_mut_slice().slice_or_fail_mut(start, end)
+ }
+}
#[experimental = "waiting on FromIterator stability"]
impl<T> FromIterator<T> for Vec<T> {
}
/// Deprecated: use `slice_mut`.
- #[deprecated = "use slice_from"]
+ #[deprecated = "use slice_mut"]
pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint)
-> &'a mut [T] {
self[mut start..end]
* println!("Slicing!");
* self
* }
- * fn slice_from_<'a>(&'a self, from: &Foo) -> &'a Foo {
+ * fn slice_from_or_fail<'a>(&'a self, from: &Foo) -> &'a Foo {
* println!("Slicing!");
* self
* }
- * fn slice_to_<'a>(&'a self, to: &Foo) -> &'a Foo {
+ * fn slice_to_or_fail<'a>(&'a self, to: &Foo) -> &'a Foo {
* println!("Slicing!");
* self
* }
- * fn slice_<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
+ * fn slice_or_fail<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
* println!("Slicing!");
* self
* }
* }
* ```
*/
-// 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_or_fail<'a>(&'a self, from: &Idx) -> &'a Result;
+ /// The method for the slicing operation foo[..to]
+ fn slice_to_or_fail<'a>(&'a self, to: &Idx) -> &'a Result;
+ /// The method for the slicing operation foo[from..to]
+ fn slice_or_fail<'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[]
* println!("Slicing!");
* self
* }
- * fn slice_from_mut_<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
+ * fn slice_from_or_fail_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_or_fail_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_or_fail_mut<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
* println!("Slicing!");
* self
* }
* }
* ```
*/
-// 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_or_fail_mut<'a>(&'a mut self, from: &Idx) -> &'a mut Result;
+ /// The method for the slicing operation foo[..to]
+ fn slice_to_or_fail_mut<'a>(&'a mut self, to: &Idx) -> &'a mut Result;
+ /// The method for the slicing operation foo[from..to]
+ fn slice_or_fail_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]
pub use ops::{Drop, Deref, DerefMut};
pub use ops::{Shl, Shr};
pub use ops::{Index, IndexMut};
+pub use ops::{Slice, SliceMut};
pub use ops::{Fn, FnMut, FnOnce};
pub use option::{Option, Some, None};
pub use result::{Result, Ok, Err};
}
}
+
+
+#[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_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
+ self.slice_or_fail(start, &self.len())
+ }
+
+ #[inline]
+ fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
+ self.slice_or_fail(&0, end)
+ }
+ #[inline]
+ fn slice_or_fail<'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] {
}
}
+#[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_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
+ let len = &self.len();
+ self.slice_or_fail_mut(start, len)
+ }
+
+ #[inline]
+ fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
+ self.slice_or_fail_mut(&0, end)
+ }
+ #[inline]
+ fn slice_or_fail_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] {
fn as_mut_slice(self) -> &'a mut [T];
/// Deprecated: use `slice_mut`.
- #[deprecated = "slice_mut"]
+ #[deprecated = "use slice_mut"]
fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] {
self.slice_mut(start, end)
}
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
}
+ #[cfg(stage0)]
impl ops::Slice<uint, str> for str {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a str {
self.slice(*from, *to)
}
}
+ #[cfg(not(stage0))]
+ impl ops::Slice<uint, str> for str {
+ #[inline]
+ fn as_slice_<'a>(&'a self) -> &'a str {
+ self
+ }
+
+ #[inline]
+ fn slice_from_or_fail<'a>(&'a self, from: &uint) -> &'a str {
+ self.slice_from(*from)
+ }
+
+ #[inline]
+ fn slice_to_or_fail<'a>(&'a self, to: &uint) -> &'a str {
+ self.slice_to(*to)
+ }
+
+ #[inline]
+ fn slice_or_fail<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
+ self.slice(*from, *to)
+ }
+ }
}
/// Any string that can be represented as a slice
assert!(v.iter().all(|&x| x < 10));
assert!(!v.iter().all(|&x| x % 2 == 0));
assert!(!v.iter().all(|&x| x > 100));
- assert!(v.slice_(&0, &0).iter().all(|_| fail!()));
+ assert!(v.slice_or_fail(&0, &0).iter().all(|_| fail!()));
}
#[test]
assert!(v.iter().any(|&x| x < 10));
assert!(v.iter().any(|&x| x % 2 == 0));
assert!(!v.iter().any(|&x| x > 100));
- assert!(!v.slice_(&0, &0).iter().any(|_| fail!()));
+ assert!(!v.slice_or_fail(&0, &0).iter().any(|_| fail!()));
}
#[test]
match fcx.tcx().lang_items.slice_mut_trait() {
Some(trait_did) => {
let method_name = match (start_expr, end_expr) {
- (&Some(_), &Some(_)) => "slice_mut_",
- (&Some(_), &None) => "slice_from_mut_",
- (&None, &Some(_)) => "slice_to_mut_",
+ (&Some(_), &Some(_)) => "slice_or_fail_mut",
+ (&Some(_), &None) => "slice_from_or_fail_mut",
+ (&None, &Some(_)) => "slice_to_or_fail_mut",
(&None, &None) => "as_mut_slice_",
};
match fcx.tcx().lang_items.slice_trait() {
Some(trait_did) => {
let method_name = match (start_expr, end_expr) {
- (&Some(_), &Some(_)) => "slice_",
- (&Some(_), &None) => "slice_from_",
- (&None, &Some(_)) => "slice_to_",
+ (&Some(_), &Some(_)) => "slice_or_fail",
+ (&Some(_), &None) => "slice_from_or_fail",
+ (&None, &Some(_)) => "slice_to_or_fail",
(&None, &None) => "as_slice_",
};
#[doc(no_inline)] pub use ops::{Drop, Deref, DerefMut};
#[doc(no_inline)] pub use ops::{Shl, Shr};
#[doc(no_inline)] pub use ops::{Index, IndexMut};
+#[doc(no_inline)] pub use ops::{Slice, SliceMut};
#[doc(no_inline)] pub use ops::{Fn, FnMut, FnOnce};
#[doc(no_inline)] pub use option::{Option, Some, None};
#[doc(no_inline)] pub use result::{Result, Ok, Err};
unsafe { COUNT += 1; }
self
}
- fn slice_from_<'a>(&'a self, _from: &Foo) -> &'a Foo {
+ fn slice_from_or_fail<'a>(&'a self, _from: &Foo) -> &'a Foo {
unsafe { COUNT += 1; }
self
}
- fn slice_to_<'a>(&'a self, _to: &Foo) -> &'a Foo {
+ fn slice_to_or_fail<'a>(&'a self, _to: &Foo) -> &'a Foo {
unsafe { COUNT += 1; }
self
}
- fn slice_<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
+ fn slice_or_fail<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
unsafe { COUNT += 1; }
self
}
unsafe { COUNT += 1; }
self
}
- fn slice_from_mut_<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
+ fn slice_from_or_fail_mut<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
unsafe { COUNT += 1; }
self
}
- fn slice_to_mut_<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
+ fn slice_to_or_fail_mut<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
unsafe { COUNT += 1; }
self
}
- fn slice_mut_<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
+ fn slice_or_fail_mut<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
unsafe { COUNT += 1; }
self
}