diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ops.rs | 24 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 29 |
2 files changed, 52 insertions, 1 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 6e6f97a7af7..fee40115f39 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1148,6 +1148,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T { #[lang="fn"] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_paren_sugar] +#[cfg(stage0)] pub trait Fn<Args> { /// The returned type after the call operator is used. type Output; @@ -1156,10 +1157,21 @@ pub trait Fn<Args> { extern "rust-call" fn call(&self, args: Args) -> Self::Output; } +/// A version of the call operator that takes an immutable receiver. +#[lang="fn"] +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_paren_sugar] +#[cfg(not(stage0))] +pub trait Fn<Args> : FnMut<Args> { + /// This is called when the call operator is used. + extern "rust-call" fn call(&self, args: Args) -> Self::Output; +} + /// A version of the call operator that takes a mutable receiver. #[lang="fn_mut"] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_paren_sugar] +#[cfg(stage0)] pub trait FnMut<Args> { /// The returned type after the call operator is used. type Output; @@ -1168,6 +1180,16 @@ pub trait FnMut<Args> { extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; } +/// A version of the call operator that takes a mutable receiver. +#[lang="fn_mut"] +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_paren_sugar] +#[cfg(not(stage0))] +pub trait FnMut<Args> : FnOnce<Args> { + /// This is called when the call operator is used. + extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; +} + /// A version of the call operator that takes a by-value receiver. #[lang="fn_once"] #[stable(feature = "rust1", since = "1.0.0")] @@ -1180,6 +1202,7 @@ pub trait FnOnce<Args> { extern "rust-call" fn call_once(self, args: Args) -> Self::Output; } +#[cfg(stage0)] impl<F: ?Sized, A> FnMut<A> for F where F : Fn<A> { @@ -1190,6 +1213,7 @@ impl<F: ?Sized, A> FnMut<A> for F } } +#[cfg(stage0)] impl<F,A> FnOnce<A> for F where F : FnMut<A> { diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index b7285d30a73..7197649a0ea 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -29,7 +29,7 @@ use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator}; use marker::Sized; use mem; use num::Int; -use ops::{Fn, FnMut}; +use ops::{Fn, FnMut, FnOnce}; use option::Option::{self, None, Some}; use raw::{Repr, Slice}; use result::Result::{self, Ok, Err}; @@ -541,6 +541,7 @@ delegate_iter!{exact u8 : Bytes<'a>} #[derive(Copy, Clone)] struct BytesDeref; +#[cfg(stage0)] impl<'a> Fn<(&'a u8,)> for BytesDeref { type Output = u8; @@ -550,6 +551,32 @@ impl<'a> Fn<(&'a u8,)> for BytesDeref { } } +#[cfg(not(stage0))] +impl<'a> Fn<(&'a u8,)> for BytesDeref { + #[inline] + extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 { + *ptr + } +} + +#[cfg(not(stage0))] +impl<'a> FnMut<(&'a u8,)> for BytesDeref { + #[inline] + extern "rust-call" fn call_mut(&mut self, (ptr,): (&'a u8,)) -> u8 { + Fn::call(&*self, (ptr,)) + } +} + +#[cfg(not(stage0))] +impl<'a> FnOnce<(&'a u8,)> for BytesDeref { + type Output = u8; + + #[inline] + extern "rust-call" fn call_once(self, (ptr,): (&'a u8,)) -> u8 { + Fn::call(&self, (ptr,)) + } +} + /// An iterator over the substrings of a string, separated by `sep`. struct CharSplits<'a, P: Pattern<'a>> { /// The slice remaining to be iterated |
