libstd: Change all uses of &fn(A)->B over to |A|->B in libstd

This commit is contained in:
Patrick Walton 2013-11-18 21:15:42 -08:00
parent eef913b290
commit 1946265e1a
58 changed files with 270 additions and 236 deletions

View File

@ -235,7 +235,7 @@ impl ToStrConsume for ~[Ascii] {
impl IterBytes for Ascii {
#[inline]
fn iter_bytes(&self, _lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool {
fn iter_bytes(&self, _lsb0: bool, f: |buf: &[u8]| -> bool) -> bool {
f([self.to_byte()])
}
}

View File

@ -43,7 +43,7 @@ pub fn capacity<T>(v: @[T]) -> uint {
* onto the vector being constructed.
*/
#[inline]
pub fn build<A>(size: Option<uint>, builder: &fn(push: &fn(v: A))) -> @[A] {
pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> @[A] {
let mut vec = @[];
unsafe { raw::reserve(&mut vec, size.unwrap_or(4)); }
builder(|x| unsafe { raw::push(&mut vec, x) });
@ -68,7 +68,7 @@ pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] {
/// Apply a function to each element of a vector and return the results
pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] {
do build(Some(v.len())) |push| {
for elem in v.iter() {
push(f(elem));
@ -82,7 +82,7 @@ pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> @[T] {
pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] {
do build(Some(n_elts)) |push| {
let mut i: uint = 0u;
while i < n_elts { push(op(i)); i += 1u; }

View File

@ -58,7 +58,7 @@ use num::FromPrimitive;
/// }
/// ```
#[inline]
pub fn all_values(blk: &fn(v: bool)) {
pub fn all_values(blk: |v: bool|) {
blk(true);
blk(false);
}

View File

@ -117,7 +117,7 @@ impl CString {
/// # Failure
///
/// Fails if the CString is null.
pub fn with_ref<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
pub fn with_ref<T>(&self, f: |*libc::c_char| -> T) -> T {
if self.buf.is_null() { fail!("CString is null!"); }
f(self.buf)
}
@ -127,7 +127,7 @@ impl CString {
/// # Failure
///
/// Fails if the CString is null.
pub fn with_mut_ref<T>(&mut self, f: &fn(*mut libc::c_char) -> T) -> T {
pub fn with_mut_ref<T>(&mut self, f: |*mut libc::c_char| -> T) -> T {
if self.buf.is_null() { fail!("CString is null!"); }
f(unsafe { cast::transmute_mut_unsafe(self.buf) })
}
@ -223,13 +223,13 @@ pub trait ToCStr {
///
/// Raises the `null_byte` condition if the receiver has an interior null.
#[inline]
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
self.to_c_str().with_ref(f)
}
/// Unsafe variant of `with_c_str()` that doesn't check for nulls.
#[inline]
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
self.to_c_str_unchecked().with_ref(f)
}
}
@ -246,12 +246,12 @@ impl<'self> ToCStr for &'self str {
}
#[inline]
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
self.as_bytes().with_c_str(f)
}
#[inline]
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
self.as_bytes().with_c_str_unchecked(f)
}
}
@ -282,17 +282,17 @@ impl<'self> ToCStr for &'self [u8] {
}
}
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
unsafe { with_c_str(*self, true, f) }
}
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
with_c_str(*self, false, f)
}
}
// Unsafe function that handles possibly copying the &[u8] into a stack array.
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: &fn(*libc::c_char) -> T) -> T {
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T {
if v.len() < BUF_LEN {
let mut buf: [u8, .. BUF_LEN] = intrinsics::uninit();
vec::bytes::copy_memory(buf, v, v.len());
@ -357,7 +357,7 @@ impl<'self> Iterator<libc::c_char> for CStringIterator<'self> {
/// is found, and the number of strings found is returned.
pub unsafe fn from_c_multistring(buf: *libc::c_char,
count: Option<uint>,
f: &fn(&CString)) -> uint {
f: |&CString|) -> uint {
let mut curr_ptr: uint = buf as uint;
let mut ctr = 0;

View File

@ -71,12 +71,12 @@ impl<T> Cell<T> {
}
/// Calls a closure with a reference to the value.
pub fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
pub fn with_ref<R>(&self, op: |v: &T| -> R) -> R {
do self.with_mut_ref |ptr| { op(ptr) }
}
/// Calls a closure with a mutable reference to the value.
pub fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
pub fn with_mut_ref<R>(&self, op: |v: &mut T| -> R) -> R {
let mut v = Some(self.take());
do (|| {
op(v.get_mut_ref())

View File

@ -241,7 +241,7 @@ static N_COUNT: uint = (V_COUNT * T_COUNT);
static S_COUNT: uint = (L_COUNT * N_COUNT);
// Decompose a precomposed Hangul syllable
fn decompose_hangul(s: char, f: &fn(char)) {
fn decompose_hangul(s: char, f: |char|) {
let si = s as uint - S_BASE;
let li = si / N_COUNT;
@ -259,7 +259,7 @@ fn decompose_hangul(s: char, f: &fn(char)) {
}
/// Returns the canonical decompostion of a character
pub fn decompose_canonical(c: char, f: &fn(char)) {
pub fn decompose_canonical(c: char, f: |char|) {
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
decompose::canonical(c, f);
} else {
@ -268,7 +268,7 @@ pub fn decompose_canonical(c: char, f: &fn(char)) {
}
/// Returns the compatibility decompostion of a character
pub fn decompose_compatible(c: char, f: &fn(char)) {
pub fn decompose_compatible(c: char, f: |char|) {
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
decompose::compatibility(c, f);
} else {
@ -285,7 +285,7 @@ pub fn decompose_compatible(c: char, f: &fn(char)) {
/// - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
/// - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
///
pub fn escape_unicode(c: char, f: &fn(char)) {
pub fn escape_unicode(c: char, f: |char|) {
// avoid calling str::to_str_radix because we don't really need to allocate
// here.
f('\\');
@ -316,7 +316,7 @@ pub fn escape_unicode(c: char, f: &fn(char)) {
/// - Any other chars in the range [0x20,0x7e] are not escaped.
/// - Any other chars are given hex unicode escapes; see `escape_unicode`.
///
pub fn escape_default(c: char, f: &fn(char)) {
pub fn escape_default(c: char, f: |char|) {
match c {
'\t' => { f('\\'); f('t'); }
'\r' => { f('\\'); f('r'); }
@ -367,8 +367,8 @@ pub trait Char {
fn is_digit_radix(&self, radix: uint) -> bool;
fn to_digit(&self, radix: uint) -> Option<uint>;
fn from_digit(num: uint, radix: uint) -> Option<char>;
fn escape_unicode(&self, f: &fn(char));
fn escape_default(&self, f: &fn(char));
fn escape_unicode(&self, f: |char|);
fn escape_default(&self, f: |char|);
fn len_utf8_bytes(&self) -> uint;
/// Encodes this character as utf-8 into the provided byte-buffer. The
@ -403,9 +403,9 @@ impl Char for char {
fn from_digit(num: uint, radix: uint) -> Option<char> { from_digit(num, radix) }
fn escape_unicode(&self, f: &fn(char)) { escape_unicode(*self, f) }
fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) }
fn escape_default(&self, f: &fn(char)) { escape_default(*self, f) }
fn escape_default(&self, f: |char|) { escape_default(*self, f) }
fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) }

View File

@ -30,7 +30,8 @@ struct AnnihilateStats {
}
unsafe fn each_live_alloc(read_next_before: bool,
f: &fn(box: *mut raw::Box<()>, uniq: bool) -> bool) -> bool {
f: |box: *mut raw::Box<()>, uniq: bool| -> bool)
-> bool {
//! Walks the internal list of allocations
use managed;

View File

@ -133,7 +133,7 @@ impl<T, U> Condition<T, U> {
/// Performs the same functionality as `raise`, except that when no handler
/// is found the `default` argument is called instead of failing the task.
pub fn raise_default(&self, t: T, default: &fn() -> U) -> U {
pub fn raise_default(&self, t: T, default: || -> U) -> U {
match local_data::pop(self.key) {
None => {
debug!("Condition.raise: found no handler");
@ -145,7 +145,7 @@ impl<T, U> Condition<T, U> {
None => {}
Some(hp) => local_data::set(self.key, hp)
}
let handle : &fn(T) -> U = unsafe {
let handle : |T| -> U = unsafe {
::cast::transmute(handler.handle)
};
let u = handle(t);

View File

@ -38,7 +38,7 @@ impl<L, R> Either<L, R> {
/// `value` is `Right(R)` then `f_right` is applied to its contents, and the
/// result is returned.
#[inline]
pub fn either<T>(&self, f_left: &fn(&L) -> T, f_right: &fn(&R) -> T) -> T {
pub fn either<T>(&self, f_left: |&L| -> T, f_right: |&R| -> T) -> T {
match *self {
Left(ref l) => f_left(l),
Right(ref r) => f_right(r)

View File

@ -931,8 +931,10 @@ impl<'self> Formatter<'self> {
}
}
fn with_padding(&mut self, padding: uint,
default: parse::Alignment, f: &fn(&mut Formatter)) {
fn with_padding(&mut self,
padding: uint,
default: parse::Alignment,
f: |&mut Formatter|) {
let align = match self.align {
parse::AlignUnknown => default,
parse::AlignLeft | parse::AlignRight => self.align

View File

@ -408,7 +408,7 @@ mod tests {
// Hash just the bytes of the slice, without length prefix
struct Bytes<'self>(&'self [u8]);
impl<'self> IterBytes for Bytes<'self> {
fn iter_bytes(&self, _lsb0: bool, f: &fn(&[u8]) -> bool) -> bool {
fn iter_bytes(&self, _lsb0: bool, f: |&[u8]| -> bool) -> bool {
f(**self)
}
}

View File

@ -80,8 +80,7 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
}
#[inline]
fn bucket_sequence(&self, hash: uint,
op: &fn(uint) -> bool) -> bool {
fn bucket_sequence(&self, hash: uint, op: |uint| -> bool) -> bool {
let start_idx = self.to_bucket(hash);
let len_buckets = self.buckets.len();
let mut idx = start_idx;
@ -360,8 +359,14 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
/// Modify and return the value corresponding to the key in the map, or
/// insert and return a new value if it doesn't exist.
pub fn mangle<'a,A>(&'a mut self, k: K, a: A, not_found: &fn(&K, A) -> V,
found: &fn(&K, &mut V, A)) -> &'a mut V {
pub fn mangle<'a,
A>(
&'a mut self,
k: K,
a: A,
not_found: |&K, A| -> V,
found: |&K, &mut V, A|)
-> &'a mut V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
// that we do not resize if this call to insert is
@ -395,7 +400,7 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
/// Return the value corresponding to the key in the map, or create,
/// insert, and return a new value if it doesn't exist.
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V)
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: |&K| -> V)
-> &'a mut V {
self.mangle(k, (), |k,_a| f(k), |_k,_v,_a| ())
}
@ -403,8 +408,12 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
/// Insert a key-value pair into the map if the key is not already present.
/// Otherwise, modify the existing value for the key.
/// Returns the new or modified value for the key.
pub fn insert_or_update_with<'a>(&'a mut self, k: K, v: V,
f: &fn(&K, &mut V)) -> &'a mut V {
pub fn insert_or_update_with<'a>(
&'a mut self,
k: K,
v: V,
f: |&K, &mut V|)
-> &'a mut V {
self.mangle(k, v, |_k,a| a, |k,v,_a| f(k,v))
}
@ -446,12 +455,12 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
}
/// Visit all keys
pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
pub fn each_key(&self, blk: |k: &K| -> bool) -> bool {
self.iter().advance(|(k, _)| blk(k))
}
/// Visit all values
pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
pub fn each_value<'a>(&'a self, blk: |v: &'a V| -> bool) -> bool {
self.iter().advance(|(_, v)| blk(v))
}

View File

@ -54,8 +54,7 @@ impl<'self, R: Reader> Iterator<u8> for ByteIterator<R> {
}
}
pub fn u64_to_le_bytes<T>(n: u64, size: uint,
f: &fn(v: &[u8]) -> T) -> T {
pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
assert!(size <= 8u);
match size {
1u => f(&[n as u8]),
@ -88,8 +87,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
}
}
pub fn u64_to_be_bytes<T>(n: u64, size: uint,
f: &fn(v: &[u8]) -> T) -> T {
pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
assert!(size <= 8u);
match size {
1u => f(&[n as u8]),

View File

@ -75,7 +75,7 @@ pub struct File {
priv last_nread: int,
}
fn io_raise<T>(f: &fn(io: &mut IoFactory) -> Result<T, IoError>) -> Option<T> {
fn io_raise<T>(f: |io: &mut IoFactory| -> Result<T, IoError>) -> Option<T> {
do with_local_io |io| {
match f(io) {
Ok(t) => Some(t),
@ -499,7 +499,7 @@ pub fn rmdir(path: &Path) {
/// use std::io::fs;
///
/// // one possible implementation of fs::walk_dir only visiting files
/// fn visit_dirs(dir: &Path, cb: &fn(&Path)) {
/// fn visit_dirs(dir: &Path, cb: |&Path|) {
/// if dir.is_dir() {
/// let contents = fs::readdir(dir).unwrap();
/// for entry in contents.iter() {

View File

@ -240,7 +240,7 @@ impl<'self> Buffer for BufReader<'self> {
///Calls a function with a MemWriter and returns
///the writer's stored vector.
pub fn with_mem_writer(writeFn:&fn(&mut MemWriter)) -> ~[u8] {
pub fn with_mem_writer(writeFn: |&mut MemWriter|) -> ~[u8] {
let mut writer = MemWriter::new();
writeFn(&mut writer);
writer.inner()

View File

@ -394,7 +394,7 @@ condition! {
/// Helper for wrapper calls where you want to
/// ignore any io_errors that might be raised
pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
pub fn ignore_io_error<T>(cb: || -> T) -> T {
do io_error::cond.trap(|_| {
// just swallow the error.. downstream users
// who can make a decision based on a None result
@ -407,7 +407,7 @@ pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
/// Helper for catching an I/O error and wrapping it in a Result object. The
/// return result will be the last I/O error that happened or the result of the
/// closure if no error occurred.
pub fn result<T>(cb: &fn() -> T) -> Result<T, IoError> {
pub fn result<T>(cb: || -> T) -> Result<T, IoError> {
let mut err = None;
let ret = io_error::cond.trap(|e| {
if err.is_none() {

View File

@ -33,7 +33,7 @@ use vec;
#[cfg(windows)] use ptr;
#[cfg(windows)] use str;
fn keep_going(data: &[u8], f: &fn(*u8, uint) -> i64) -> i64 {
fn keep_going(data: &[u8], f: |*u8, uint| -> i64) -> i64 {
#[cfg(windows)] static eintr: int = 0; // doesn't matter
#[cfg(not(windows))] static eintr: int = libc::EINTR as int;

View File

@ -432,7 +432,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
}
#[cfg(unix)]
fn with_argv<T>(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T {
fn with_argv<T>(prog: &str, args: &[~str], cb: |**libc::c_char| -> T) -> T {
use vec;
// We can't directly convert `str`s into `*char`s, as someone needs to hold
@ -460,7 +460,7 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T {
}
#[cfg(unix)]
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*c_void| -> T) -> T {
use vec;
// On posixy systems we can pass a char** for envp, which is a
@ -490,7 +490,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
}
#[cfg(windows)]
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T {
// On win32 we pass an "environment block" which is not a char**, but
// rather a concatenation of null-terminated k=v\0 sequences, with a final
// \0 to terminate.
@ -514,7 +514,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
}
}
fn with_dirp<T>(d: Option<&Path>, cb: &fn(*libc::c_char) -> T) -> T {
fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T {
match d {
Some(dir) => dir.with_c_str(|buf| cb(buf)),
None => cb(ptr::null())

View File

@ -81,7 +81,8 @@ impl<'self> Parser<'self> {
}
// Commit only if parser returns Some
fn read_atomically<T>(&mut self, cb: &fn(&mut Parser) -> Option<T>) -> Option<T> {
fn read_atomically<T>(&mut self, cb: |&mut Parser| -> Option<T>)
-> Option<T> {
let pos = self.pos;
let r = cb(self);
if r.is_none() {
@ -91,14 +92,16 @@ impl<'self> Parser<'self> {
}
// Commit only if parser read till EOF
fn read_till_eof<T>(&mut self, cb: &fn(&mut Parser) -> Option<T>) -> Option<T> {
fn read_till_eof<T>(&mut self, cb: |&mut Parser| -> Option<T>)
-> Option<T> {
do self.read_atomically |p| {
cb(p).filtered(|_| p.is_eof())
}
}
// Return result of first successful parser
fn read_or<T>(&mut self, parsers: &[&fn(&mut Parser) -> Option<T>]) -> Option<T> {
fn read_or<T>(&mut self, parsers: &[|&mut Parser| -> Option<T>])
-> Option<T> {
for pf in parsers.iter() {
match self.read_atomically(|p: &mut Parser| (*pf)(p)) {
Some(r) => return Some(r),
@ -109,12 +112,14 @@ impl<'self> Parser<'self> {
}
// Apply 3 parsers sequentially
fn read_seq_3<A, B, C>(&mut self,
pa: &fn(&mut Parser) -> Option<A>,
pb: &fn(&mut Parser) -> Option<B>,
pc: &fn(&mut Parser) -> Option<C>
) -> Option<(A, B, C)>
{
fn read_seq_3<A,
B,
C>(
&mut self,
pa: |&mut Parser| -> Option<A>,
pb: |&mut Parser| -> Option<B>,
pc: |&mut Parser| -> Option<C>)
-> Option<(A, B, C)> {
do self.read_atomically |p| {
let a = pa(p);
let b = if a.is_some() { pb(p) } else { None };

View File

@ -74,7 +74,9 @@ pub struct UdpStream {
}
impl UdpStream {
pub fn as_socket<T>(&mut self, f: &fn(&mut UdpSocket) -> T) -> T { f(&mut self.socket) }
pub fn as_socket<T>(&mut self, f: |&mut UdpSocket| -> T) -> T {
f(&mut self.socket)
}
pub fn disconnect(self) -> UdpSocket { self.socket }
}

View File

@ -69,7 +69,7 @@ enum StdSource {
File(~RtioFileStream),
}
fn src<T>(fd: libc::c_int, readable: bool, f: &fn(StdSource) -> T) -> T {
fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {
do with_local_io |io| {
let fd = unsafe { libc::dup(fd) };
match io.tty_open(fd, readable) {
@ -121,7 +121,7 @@ pub fn stderr() -> StdWriter {
// // io1 aliases io2
// }
// }
fn with_task_stdout(f: &fn(&mut Writer)) {
fn with_task_stdout(f: |&mut Writer|) {
use rt::local::Local;
use rt::task::Task;

View File

@ -433,7 +433,7 @@ pub trait Iterator<A> {
/// range(0, 5).advance(|x| {print!("{} ", x); true});
/// ```
#[inline]
fn advance(&mut self, f: &fn(A) -> bool) -> bool {
fn advance(&mut self, f: |A| -> bool) -> bool {
loop {
match self.next() {
Some(x) => {
@ -522,7 +522,7 @@ pub trait Iterator<A> {
/// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
/// ```
#[inline]
fn fold<B>(&mut self, init: B, f: &fn(B, A) -> B) -> B {
fn fold<B>(&mut self, init: B, f: |B, A| -> B) -> B {
let mut accum = init;
loop {
match self.next() {
@ -558,7 +558,7 @@ pub trait Iterator<A> {
/// assert!(!a.iter().all(|&x| *x > 2));
/// ```
#[inline]
fn all(&mut self, f: &fn(A) -> bool) -> bool {
fn all(&mut self, f: |A| -> bool) -> bool {
for x in *self { if !f(x) { return false; } }
true
}
@ -575,14 +575,14 @@ pub trait Iterator<A> {
/// assert!(!it.any(|&x| *x == 3));
/// ```
#[inline]
fn any(&mut self, f: &fn(A) -> bool) -> bool {
fn any(&mut self, f: |A| -> bool) -> bool {
for x in *self { if f(x) { return true; } }
false
}
/// Return the first element satisfying the specified predicate
#[inline]
fn find(&mut self, predicate: &fn(&A) -> bool) -> Option<A> {
fn find(&mut self, predicate: |&A| -> bool) -> Option<A> {
for x in *self {
if predicate(&x) { return Some(x) }
}
@ -591,7 +591,7 @@ pub trait Iterator<A> {
/// Return the index of the first element satisfying the specified predicate
#[inline]
fn position(&mut self, predicate: &fn(A) -> bool) -> Option<uint> {
fn position(&mut self, predicate: |A| -> bool) -> Option<uint> {
let mut i = 0;
for x in *self {
if predicate(x) {
@ -604,7 +604,7 @@ pub trait Iterator<A> {
/// Count the number of elements satisfying the specified predicate
#[inline]
fn count(&mut self, predicate: &fn(A) -> bool) -> uint {
fn count(&mut self, predicate: |A| -> bool) -> uint {
let mut i = 0;
for x in *self {
if predicate(x) { i += 1 }
@ -622,7 +622,7 @@ pub trait Iterator<A> {
/// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10);
/// ```
#[inline]
fn max_by<B: Ord>(&mut self, f: &fn(&A) -> B) -> Option<A> {
fn max_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A> {
self.fold(None, |max: Option<(A, B)>, x| {
let x_val = f(&x);
match max {
@ -646,7 +646,7 @@ pub trait Iterator<A> {
/// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0);
/// ```
#[inline]
fn min_by<B: Ord>(&mut self, f: &fn(&A) -> B) -> Option<A> {
fn min_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A> {
self.fold(None, |min: Option<(A, B)>, x| {
let x_val = f(&x);
match min {
@ -729,7 +729,7 @@ pub trait ExactSize<A> : DoubleEndedIterator<A> {
///
/// If no element matches, None is returned.
#[inline]
fn rposition(&mut self, predicate: &fn(A) -> bool) -> Option<uint> {
fn rposition(&mut self, predicate: |A| -> bool) -> Option<uint> {
let (lower, upper) = self.size_hint();
assert!(upper == Some(lower));
let mut i = lower;

View File

@ -177,7 +177,7 @@ pub fn pop<T: 'static>(key: Key<T>) -> Option<T> {
///
/// It is considered a runtime error to attempt to get a value which is already
/// on loan via the `get_mut` method provided.
pub fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U {
pub fn get<T: 'static, U>(key: Key<T>, f: |Option<&T>| -> U) -> U {
get_with(key, ImmLoan, f)
}
@ -188,7 +188,7 @@ pub fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U {
/// It is considered a runtime error to attempt to get a value which is already
/// on loan via this or the `get` methods. This is similar to how it's a runtime
/// error to take two mutable loans on an `@mut` box.
pub fn get_mut<T: 'static, U>(key: Key<T>, f: &fn(Option<&mut T>) -> U) -> U {
pub fn get_mut<T: 'static, U>(key: Key<T>, f: |Option<&mut T>| -> U) -> U {
do get_with(key, MutLoan) |x| {
match x {
None => f(None),
@ -202,9 +202,12 @@ pub fn get_mut<T: 'static, U>(key: Key<T>, f: &fn(Option<&mut T>) -> U) -> U {
}
}
fn get_with<T: 'static, U>(key: Key<T>,
state: LoanState,
f: &fn(Option<&T>) -> U) -> U {
fn get_with<T:'static,
U>(
key: Key<T>,
state: LoanState,
f: |Option<&T>| -> U)
-> U {
// This function must be extremely careful. Because TLS can store owned
// values, and we must have some form of `get` function other than `pop`,
// this function has to give a `&` reference back to the caller.
@ -335,7 +338,7 @@ pub fn set<T: 'static>(key: Key<T>, data: T) {
///
/// This function will have the same runtime errors as generated from `pop` and
/// `set` (the key must not currently be on loan
pub fn modify<T: 'static>(key: Key<T>, f: &fn(Option<T>) -> Option<T>) {
pub fn modify<T: 'static>(key: Key<T>, f: |Option<T>| -> Option<T>) {
match f(pop(key)) {
Some(next) => { set(key, next); }
None => {}

View File

@ -415,7 +415,7 @@ impl FromStrRadix for $T {
/// Convert to a string as a byte slice in a given base.
#[inline]
pub fn to_str_bytes<U>(n: $T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
// The radix can be as low as 2, so we need at least 64 characters for a
// base 2 number, and then we need another for a possible '-' character.
let mut buf = [0u8, ..65];

View File

@ -108,7 +108,7 @@ pub trait Unsigned: Num {}
/// ```
///
pub trait Times {
fn times(&self, it: &fn());
fn times(&self, it: ||);
}
pub trait Integer: Num

View File

@ -132,9 +132,19 @@ static NAN_BUF: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8];
* # Failure
* - Fails if `radix` < 2 or `radix` > 36.
*/
pub fn int_to_str_bytes_common<T:NumCast+Zero+Eq+Ord+Integer+
Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>(
num: T, radix: uint, sign: SignFormat, f: &fn(u8)) {
pub fn int_to_str_bytes_common<T:NumCast
+Zero
+Eq
+Ord
+Integer
+Div<T,T>
+Neg<T>
+Rem<T,T>
+Mul<T,T>>(
num: T,
radix: uint,
sign: SignFormat,
f: |u8|) {
assert!(2 <= radix && radix <= 36);
let _0: T = Zero::zero();

View File

@ -85,7 +85,7 @@ impl num::Times for uint {
/// use with integer literals of inferred integer-type as
/// the self-value (eg. `do 100.times { ... }`).
///
fn times(&self, it: &fn()) {
fn times(&self, it: ||) {
let mut i = *self;
while i > 0 {
it();

View File

@ -266,7 +266,7 @@ impl FromStrRadix for $T {
/// Convert to a string as a byte slice in a given base.
#[inline]
pub fn to_str_bytes<U>(n: $T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
// The radix can be as low as 2, so we need at least 64 characters for a
// base 2 number.
let mut buf = [0u8, ..64];

View File

@ -147,7 +147,7 @@ impl<T> Option<T> {
/// Returns the contained value or computes it from a closure
#[inline]
pub fn unwrap_or_else(self, f: &fn() -> T) -> T {
pub fn unwrap_or_else(self, f: || -> T) -> T {
match self {
Some(x) => x,
None => f()
@ -160,19 +160,19 @@ impl<T> Option<T> {
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
#[inline]
pub fn map<U>(self, f: &fn(T) -> U) -> Option<U> {
pub fn map<U>(self, f: |T| -> U) -> Option<U> {
match self { Some(x) => Some(f(x)), None => None }
}
/// Applies a function to the contained value or returns a default.
#[inline]
pub fn map_default<U>(self, def: U, f: &fn(T) -> U) -> U {
pub fn map_default<U>(self, def: U, f: |T| -> U) -> U {
match self { None => def, Some(t) => f(t) }
}
/// Apply a function to the contained value or do nothing.
/// Returns true if the contained value was mutated.
pub fn mutate(&mut self, f: &fn(T) -> T) -> bool {
pub fn mutate(&mut self, f: |T| -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
true
@ -181,7 +181,7 @@ impl<T> Option<T> {
/// Apply a function to the contained value or set it to a default.
/// Returns true if the contained value was mutated, or false if set to the default.
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool {
pub fn mutate_default(&mut self, def: T, f: |T| -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
true
@ -235,7 +235,7 @@ impl<T> Option<T> {
/// Returns `None` if the option is `None`, otherwise calls `f` with the
/// wrapped value and returns the result.
#[inline]
pub fn and_then<U>(self, f: &fn(T) -> Option<U>) -> Option<U> {
pub fn and_then<U>(self, f: |T| -> Option<U>) -> Option<U> {
match self {
Some(x) => f(x),
None => None,
@ -254,7 +254,7 @@ impl<T> Option<T> {
/// Returns the option if it contains a value, otherwise calls `f` and
/// returns the result.
#[inline]
pub fn or_else(self, f: &fn() -> Option<T>) -> Option<T> {
pub fn or_else(self, f: || -> Option<T>) -> Option<T> {
match self {
Some(_) => self,
None => f(),
@ -273,7 +273,7 @@ impl<T> Option<T> {
/// Filters an optional value using a given function.
#[inline(always)]
pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option<T> {
pub fn filtered(self, f: |t: &T| -> bool) -> Option<T> {
match self {
Some(x) => if(f(&x)) {Some(x)} else {None},
None => None
@ -282,7 +282,7 @@ impl<T> Option<T> {
/// Applies a function zero or more times until the result is `None`.
#[inline]
pub fn while_some(self, blk: &fn(v: T) -> Option<T>) {
pub fn while_some(self, blk: |v: T| -> Option<T>) {
let mut opt = self;
while opt.is_some() {
opt = blk(opt.unwrap());

View File

@ -94,7 +94,7 @@ pub mod win32 {
use os::TMPBUF_SZ;
use libc::types::os::arch::extra::DWORD;
pub fn fill_utf16_buf_and_decode(f: &fn(*mut u16, DWORD) -> DWORD)
pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD)
-> Option<~str> {
unsafe {
@ -125,7 +125,7 @@ pub mod win32 {
}
}
pub fn as_utf16_p<T>(s: &str, f: &fn(*u16) -> T) -> T {
pub fn as_utf16_p<T>(s: &str, f: |*u16| -> T) -> T {
let mut t = s.to_utf16();
// Null terminate before passing on.
t.push(0u16);
@ -137,7 +137,7 @@ pub mod win32 {
Accessing environment variables is not generally threadsafe.
Serialize access through a global lock.
*/
fn with_env_lock<T>(f: &fn() -> T) -> T {
fn with_env_lock<T>(f: || -> T) -> T {
use unstable::mutex::{Mutex, MUTEX_INIT};
use unstable::finally::Finally;

View File

@ -559,7 +559,7 @@ impl<'self, P: GenericPath> Display<'self, P> {
/// If the path is not UTF-8, invalid sequences will be replaced with the
/// unicode replacement char. This involves allocation.
#[inline]
pub fn with_str<T>(&self, f: &fn(&str) -> T) -> T {
pub fn with_str<T>(&self, f: |&str| -> T) -> T {
let opt = if self.filename { self.path.filename_str() }
else { self.path.as_str() };
match opt {

View File

@ -87,7 +87,7 @@ impl ToCStr for Path {
impl IterBytes for Path {
#[inline]
fn iter_bytes(&self, lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool {
fn iter_bytes(&self, lsb0: bool, f: |buf: &[u8]| -> bool) -> bool {
self.repr.iter_bytes(lsb0, f)
}
}

View File

@ -112,7 +112,7 @@ impl ToCStr for Path {
impl IterBytes for Path {
#[inline]
fn iter_bytes(&self, lsb0: bool, f: &fn(&[u8]) -> bool) -> bool {
fn iter_bytes(&self, lsb0: bool, f: |&[u8]| -> bool) -> bool {
self.repr.iter_bytes(lsb0, f)
}
}
@ -970,7 +970,8 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> {
}
return None;
fn parse_two_comps<'a>(mut path: &'a str, f: &fn(char)->bool) -> Option<(uint, uint)> {
fn parse_two_comps<'a>(mut path: &'a str, f: |char| -> bool)
-> Option<(uint, uint)> {
let idx_a = match path.find(|x| f(x)) {
None => return None,
Some(x) => x

View File

@ -56,7 +56,7 @@ impl<T> Clone for *mut T {
/// Return the first offset `i` such that `f(buf[i]) == true`.
#[inline]
pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
pub unsafe fn position<T>(buf: *T, f: |&T| -> bool) -> uint {
let mut i = 0;
loop {
if f(&(*offset(buf, i as int))) { return i; }
@ -195,7 +195,7 @@ pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
SAFETY NOTE: Pointer-arithmetic. Dragons be here.
*/
pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: &fn(*T)) {
pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
debug!("array_each_with_len: before iterate");
if (arr as uint == 0) {
fail!("ptr::array_each_with_len failure: arr input is null pointer");
@ -217,7 +217,7 @@ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: &fn(*T)) {
pointer array. Barely less-dodgy Pointer Arithmetic.
Dragons be here.
*/
pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
pub unsafe fn array_each<T>(arr: **T, cb: |*T|) {
if (arr as uint == 0) {
fail!("ptr::array_each_with_len failure: arr input is null pointer");
}

View File

@ -203,7 +203,7 @@ impl<T> RcMut<T> {
impl<T> RcMut<T> {
/// Fails if there is already a mutable borrow of the box
#[inline]
pub fn with_borrow<U>(&self, f: &fn(&T) -> U) -> U {
pub fn with_borrow<U>(&self, f: |&T| -> U) -> U {
unsafe {
assert!((*self.ptr).borrow != Mutable);
let previous = (*self.ptr).borrow;
@ -216,7 +216,7 @@ impl<T> RcMut<T> {
/// Fails if there is already a mutable or immutable borrow of the box
#[inline]
pub fn with_mut_borrow<U>(&self, f: &fn(&mut T) -> U) -> U {
pub fn with_mut_borrow<U>(&self, f: |&mut T| -> U) -> U {
unsafe {
assert_eq!((*self.ptr).borrow, Nothing);
(*self.ptr).borrow = Mutable;

View File

@ -28,7 +28,7 @@ use unstable::raw;
* then build a MovePtrAdaptor wrapped around your struct.
*/
pub trait MovePtr {
fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void);
fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void);
fn push_ptr(&mut self);
fn pop_ptr(&mut self);
}

View File

@ -116,7 +116,7 @@ pub fn ReprVisitor<'a>(ptr: *c_void,
impl<'self> MovePtr for ReprVisitor<'self> {
#[inline]
fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void) {
fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void) {
self.ptr = adjustment(self.ptr);
}
fn push_ptr(&mut self) {
@ -131,7 +131,7 @@ impl<'self> ReprVisitor<'self> {
// Various helpers for the TyVisitor impl
#[inline]
pub fn get<T>(&mut self, f: &fn(&mut ReprVisitor, &T)) -> bool {
pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T|) -> bool {
unsafe {
f(self, transmute::<*c_void,&T>(self.ptr));
}

View File

@ -143,7 +143,7 @@ impl<T, E: ToStr> Result<T, E> {
/// parse_bytes(buf)
/// }
#[inline]
pub fn map<U>(self, op: &fn(T) -> U) -> Result<U,E> {
pub fn map<U>(self, op: |T| -> U) -> Result<U,E> {
match self {
Ok(t) => Ok(op(t)),
Err(e) => Err(e)
@ -156,7 +156,7 @@ impl<T, E: ToStr> Result<T, E> {
/// This function can be used to pass through a successful result while handling
/// an error.
#[inline]
pub fn map_err<F>(self, op: &fn(E) -> F) -> Result<T,F> {
pub fn map_err<F>(self, op: |E| -> F) -> Result<T,F> {
match self {
Ok(t) => Ok(t),
Err(e) => Err(op(e))
@ -208,7 +208,7 @@ impl<T, E: ToStr> Result<T, E> {
///
/// This function can be used for control flow based on result values
#[inline]
pub fn and_then<U>(self, op: &fn(T) -> Result<U, E>) -> Result<U, E> {
pub fn and_then<U>(self, op: |T| -> Result<U, E>) -> Result<U, E> {
match self {
Ok(t) => op(t),
Err(e) => Err(e),
@ -228,7 +228,7 @@ impl<T, E: ToStr> Result<T, E> {
///
/// This function can be used for control flow based on result values
#[inline]
pub fn or_else<F>(self, op: &fn(E) -> Result<T, F>) -> Result<T, F> {
pub fn or_else<F>(self, op: |E| -> Result<T, F>) -> Result<T, F> {
match self {
Ok(t) => Ok(t),
Err(e) => op(e),
@ -378,12 +378,14 @@ pub fn collect<T, E, Iter: Iterator<Result<T, E>>>(mut iterator: Iter)
/// If an `Err` is encountered, it is immediately returned.
/// Otherwise, the folded value is returned.
#[inline]
pub fn fold<T, V, E,
pub fn fold<T,
V,
E,
Iter: Iterator<Result<T, E>>>(
mut iterator: Iter,
mut init: V,
f: &fn(V, T) -> V)
-> Result<V, E> {
f: |V, T| -> V)
-> Result<V, E> {
for t in iterator {
match t {
Ok(v) => init = f(init, v),
@ -399,9 +401,7 @@ pub fn fold<T, V, E,
/// If an `Err` is encountered, it is immediately returned.
/// Otherwise, a simple `Ok(())` is returned.
#[inline]
pub fn fold_<T, E, Iter: Iterator<Result<T, E>>>(
iterator: Iter)
-> Result<(), E> {
pub fn fold_<T,E,Iter:Iterator<Result<T,E>>>(iterator: Iter) -> Result<(),E> {
fold(iterator, (), |_, _| ())
}

View File

@ -107,9 +107,8 @@ mod imp {
})
}
fn with_lock<T>(f: &fn() -> T) -> T {
fn with_lock<T>(f: || -> T) -> T {
static mut lock: Mutex = MUTEX_INIT;
do (|| {
unsafe {
lock.lock();

View File

@ -170,7 +170,7 @@ impl EventLoop for BasicLoop {
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback
}
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)) {
fn io<'a>(&'a mut self, f: |&'a mut IoFactory|) {
f(self.io)
}
}

View File

@ -40,7 +40,7 @@ fn try_take_task_borrow_list() -> Option<~[BorrowRecord]> {
}
}
fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
fn swap_task_borrow_list(f: |~[BorrowRecord]| -> ~[BorrowRecord]) {
let borrows = match try_take_task_borrow_list() {
Some(l) => l,
None => ~[]

View File

@ -79,8 +79,10 @@ fn version(crate_map: &CrateMap) -> i32 {
}
}
fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry),
visited: &mut HashSet<*CrateMap<'a>>) {
fn do_iter_crate_map<'a>(
crate_map: &'a CrateMap<'a>,
f: |&ModEntry|,
visited: &mut HashSet<*CrateMap<'a>>) {
if visited.insert(crate_map as *CrateMap) {
match version(crate_map) {
2 => {
@ -98,7 +100,7 @@ fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry),
}
/// Iterates recursively over `crate_map` and all child crate maps
pub fn iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry)) {
pub fn iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: |&ModEntry|) {
// XXX: use random numbers as keys from the OS-level RNG when there is a nice
// way to do this
let mut v: HashSet<*CrateMap<'a>> = HashSet::with_capacity_and_keys(0, 0, 32);

View File

@ -369,7 +369,7 @@ impl BlockedTask {
// So that KillHandle can be hashed in the taskgroup bookkeeping code.
impl IterBytes for KillHandle {
fn iter_bytes(&self, lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool {
fn iter_bytes(&self, lsb0: bool, f: |buf: &[u8]| -> bool) -> bool {
self.data.iter_bytes(lsb0, f)
}
}
@ -525,9 +525,8 @@ impl KillHandle {
// NB: Takes a pthread mutex -- 'blk' not allowed to reschedule.
#[inline]
fn add_lazy_tombstone(parent: &mut KillHandle,
blk: &fn(Option<proc() -> bool>)
-> proc() -> bool) {
blk: |Option<proc() -> bool>| -> proc() -> bool)
{
let inner: &mut KillHandleInner = unsafe { &mut *parent.get() };
unsafe {
do inner.graveyard_lock.lock {

View File

@ -18,7 +18,7 @@ pub trait Local {
fn put(value: ~Self);
fn take() -> ~Self;
fn exists(unused_value: Option<Self>) -> bool;
fn borrow<T>(f: &fn(&mut Self) -> T) -> T;
fn borrow<T>(f: |&mut Self| -> T) -> T;
unsafe fn unsafe_take() -> ~Self;
unsafe fn unsafe_borrow() -> *mut Self;
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
@ -30,7 +30,7 @@ impl Local for Task {
#[inline]
fn take() -> ~Task { unsafe { local_ptr::take() } }
fn exists(_: Option<Task>) -> bool { local_ptr::exists() }
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
fn borrow<T>(f: |&mut Task| -> T) -> T {
let mut res: Option<T> = None;
let res_ptr: *mut Option<T> = &mut res;
unsafe {
@ -78,7 +78,7 @@ impl Local for Scheduler {
}
}
}
fn borrow<T>(f: &fn(&mut Scheduler) -> T) -> T {
fn borrow<T>(f: |&mut Scheduler| -> T) -> T {
do Local::borrow |task: &mut Task| {
match task.sched {
Some(~ref mut task) => {

View File

@ -103,7 +103,7 @@ pub fn exists() -> bool {
/// # Safety note
///
/// Does not validate the pointer type.
pub unsafe fn borrow<T>(f: &fn(&mut T)) {
pub unsafe fn borrow<T>(f: |&mut T|) {
let mut value = take();
// XXX: Need a different abstraction from 'finally' here to avoid unsafety

View File

@ -36,7 +36,7 @@ pub trait EventLoop {
/// The asynchronous I/O services. Not all event loops may provide one
// FIXME(#9382) this is an awful interface
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory));
fn io<'a>(&'a mut self, f: |&'a mut IoFactory|);
}
pub trait RemoteCallback {
@ -75,7 +75,7 @@ pub enum CloseBehavior {
CloseAsynchronously,
}
pub fn with_local_io<T>(f: &fn(&mut IoFactory) -> Option<T>) -> Option<T> {
pub fn with_local_io<T>(f: |&mut IoFactory| -> Option<T>) -> Option<T> {
use rt::sched::Scheduler;
use rt::local::Local;
use io::native;

View File

@ -556,7 +556,7 @@ impl Scheduler {
pub fn change_task_context(mut ~self,
next_task: ~Task,
f: &fn(&mut Scheduler, ~Task)) {
f: |&mut Scheduler, ~Task|) {
// The current task is grabbed from TLS, not taken as an input.
// Doing an unsafe_take to avoid writing back a null pointer -
// We're going to call `put` later to do that.
@ -568,8 +568,8 @@ impl Scheduler {
// These transmutes do something fishy with a closure.
let f_fake_region = unsafe {
transmute::<&fn(&mut Scheduler, ~Task),
&fn(&mut Scheduler, ~Task)>(f)
transmute::<|&mut Scheduler, ~Task|,
|&mut Scheduler, ~Task|>(f)
};
let f_opaque = ClosureConverter::from_fn(f_fake_region);
@ -678,7 +678,7 @@ impl Scheduler {
/// in order to prevent that fn from performing further scheduling operations.
/// Doing further scheduling could easily result in infinite recursion.
pub fn deschedule_running_task_and_then(mut ~self,
f: &fn(&mut Scheduler, BlockedTask)) {
f: |&mut Scheduler, BlockedTask|) {
// Trickier - we need to get the scheduler task out of self
// and use it as the destination.
let stask = self.sched_task.take_unwrap();
@ -687,7 +687,7 @@ impl Scheduler {
}
pub fn switch_running_tasks_and_then(~self, next_task: ~Task,
f: &fn(&mut Scheduler, BlockedTask)) {
f: |&mut Scheduler, BlockedTask|) {
// This is where we convert the BlockedTask-taking closure into one
// that takes just a Task, and is aware of the block-or-killed protocol.
do self.change_task_context(next_task) |sched, task| {
@ -829,18 +829,18 @@ impl CleanupJob {
}
}
// XXX: Some hacks to put a &fn in Scheduler without borrowck
// XXX: Some hacks to put a || closure in Scheduler without borrowck
// complaining
type UnsafeTaskReceiver = raw::Closure;
trait ClosureConverter {
fn from_fn(&fn(&mut Scheduler, ~Task)) -> Self;
fn to_fn(self) -> &fn(&mut Scheduler, ~Task);
fn from_fn(|&mut Scheduler, ~Task|) -> Self;
fn to_fn(self) -> |&mut Scheduler, ~Task|;
}
impl ClosureConverter for UnsafeTaskReceiver {
fn from_fn(f: &fn(&mut Scheduler, ~Task)) -> UnsafeTaskReceiver {
fn from_fn(f: |&mut Scheduler, ~Task|) -> UnsafeTaskReceiver {
unsafe { transmute(f) }
}
fn to_fn(self) -> &fn(&mut Scheduler, ~Task) { unsafe { transmute(self) } }
fn to_fn(self) -> |&mut Scheduler, ~Task| { unsafe { transmute(self) } }
}
// On unix, we read randomness straight from /dev/urandom, but the

View File

@ -282,7 +282,7 @@ impl Task {
}
}
pub fn run(&mut self, f: &fn()) {
pub fn run(&mut self, f: ||) {
rtdebug!("run called on task: {}", borrow::to_uint(self));
// The only try/catch block in the world. Attempt to run the task's
@ -494,7 +494,7 @@ impl Coroutine {
static UNWIND_TOKEN: uintptr_t = 839147;
impl Unwinder {
pub fn try(&mut self, f: &fn()) {
pub fn try(&mut self, f: ||) {
use unstable::raw::Closure;
unsafe {
@ -512,7 +512,7 @@ impl Unwinder {
code: transmute(code),
env: transmute(env),
};
let closure: &fn() = transmute(closure);
let closure: || = transmute(closure);
closure();
}
}

View File

@ -925,7 +925,7 @@ pub fn is_utf16(v: &[u16]) -> bool {
/// # Failures
///
/// * Fails on invalid utf-16 data
pub fn utf16_chars(v: &[u16], f: &fn(char)) {
pub fn utf16_chars(v: &[u16], f: |char|) {
let len = v.len();
let mut i = 0u;
while (i < len && v[i] != 0u16) {
@ -1762,7 +1762,7 @@ pub trait StrSlice<'self> {
/// Work with the byte buffer and length of a slice.
///
/// The buffer does not have a null terminator.
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T;
fn as_imm_buf<T>(&self, f: |*u8, uint| -> T) -> T;
}
impl<'self> StrSlice<'self> for &'self str {
@ -2268,7 +2268,7 @@ impl<'self> StrSlice<'self> for &'self str {
}
#[inline]
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T {
fn as_imm_buf<T>(&self, f: |*u8, uint| -> T) -> T {
let v: &[u8] = unsafe { cast::transmute(*self) };
v.as_imm_buf(f)
}
@ -2355,7 +2355,7 @@ pub trait OwnedStr {
///
/// The caller must make sure any mutations to this buffer keep the string
/// valid UTF-8!
fn as_mut_buf<T>(&mut self, f: &fn(*mut u8, uint) -> T) -> T;
fn as_mut_buf<T>(&mut self, f: |*mut u8, uint| -> T) -> T;
}
impl OwnedStr for ~str {
@ -2456,7 +2456,7 @@ impl OwnedStr for ~str {
}
#[inline]
fn as_mut_buf<T>(&mut self, f: &fn(*mut u8, uint) -> T) -> T {
fn as_mut_buf<T>(&mut self, f: |*mut u8, uint| -> T) -> T {
unsafe {
raw::as_owned_vec(self).as_mut_buf(f)
}

View File

@ -554,7 +554,7 @@ pub fn try<T:Send>(f: proc() -> T) -> Result<T, ~Any> {
/* Lifecycle functions */
/// Read the name of the current task.
pub fn with_task_name<U>(blk: &fn(Option<&str>) -> U) -> U {
pub fn with_task_name<U>(blk: |Option<&str>| -> U) -> U {
use rt::task::Task;
if in_green_task_context() {
@ -605,7 +605,7 @@ pub fn failing() -> bool {
* }
* ```
*/
pub fn unkillable<U>(f: &fn() -> U) -> U {
pub fn unkillable<U>(f: || -> U) -> U {
use rt::task::Task;
unsafe {
@ -640,7 +640,7 @@ pub fn unkillable<U>(f: &fn() -> U) -> U {
* // Task is unkillable again
* }
*/
pub fn rekillable<U>(f: &fn() -> U) -> U {
pub fn rekillable<U>(f: || -> U) -> U {
use rt::task::Task;
unsafe {
@ -1201,7 +1201,7 @@ fn test_spawn_sched_blocking() {
}
#[cfg(test)]
fn avoid_copying_the_body(spawnfn: &fn(v: proc())) {
fn avoid_copying_the_body(spawnfn: |v: proc()|) {
let (p, ch) = stream::<uint>();
let x = ~1;

View File

@ -164,15 +164,17 @@ struct AncestorList(Option<Exclusive<AncestorNode>>);
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
#[inline]
fn access_group<U>(x: &TaskGroupArc, blk: &fn(TaskGroupInner) -> U) -> U {
fn access_group<U>(x: &TaskGroupArc, blk: |TaskGroupInner| -> U) -> U {
unsafe {
x.with(blk)
}
}
#[inline]
fn access_ancestors<U>(x: &Exclusive<AncestorNode>,
blk: &fn(x: &mut AncestorNode) -> U) -> U {
fn access_ancestors<U>(
x: &Exclusive<AncestorNode>,
blk: |x: &mut AncestorNode| -> U)
-> U {
unsafe {
x.with(blk)
}
@ -197,17 +199,17 @@ fn incr_generation(_ancestors: &AncestorList) -> uint { 0 }
// is NOT called on the block that forward_blk broke on!).
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
fn each_ancestor(list: &mut AncestorList,
bail_blk: &fn(TaskGroupInner),
forward_blk: &fn(TaskGroupInner) -> bool)
-> bool {
bail_blk: |TaskGroupInner|,
forward_blk: |TaskGroupInner| -> bool)
-> bool {
// "Kickoff" call - there was no last generation.
return !coalesce(list, bail_blk, forward_blk, uint::max_value);
// Recursively iterates, and coalesces afterwards if needed. Returns
// whether or not unwinding is needed (i.e., !successful iteration).
fn coalesce(list: &mut AncestorList,
bail_blk: &fn(TaskGroupInner),
forward_blk: &fn(TaskGroupInner) -> bool,
bail_blk: |TaskGroupInner|,
forward_blk: |TaskGroupInner| -> bool,
last_generation: uint) -> bool {
let (coalesce_this, early_break) =
iterate(list, bail_blk, forward_blk, last_generation);
@ -229,8 +231,8 @@ fn each_ancestor(list: &mut AncestorList,
// True if the supplied block did 'break', here or in any recursive
// calls. If so, must call the unwinder on all previous nodes.
fn iterate(ancestors: &mut AncestorList,
bail_blk: &fn(TaskGroupInner),
forward_blk: &fn(TaskGroupInner) -> bool,
bail_blk: |TaskGroupInner|,
forward_blk: |TaskGroupInner| -> bool,
last_generation: uint)
-> (Option<AncestorList>, bool) {
// At each step of iteration, three booleans are at play which govern
@ -457,7 +459,7 @@ impl RuntimeGlue {
};
}
fn with_task_handle_and_failing(blk: &fn(&KillHandle, bool)) {
fn with_task_handle_and_failing(blk: |&KillHandle, bool|) {
assert!(in_green_task_context());
unsafe {
// Can't use safe borrow, because the taskgroup destructor needs to
@ -467,7 +469,7 @@ impl RuntimeGlue {
}
}
fn with_my_taskgroup<U>(blk: &fn(&Taskgroup) -> U) -> U {
fn with_my_taskgroup<U>(blk: |&Taskgroup| -> U) -> U {
assert!(in_green_task_context());
unsafe {
// Can't use safe borrow, because creating new hashmaps for the
@ -545,7 +547,7 @@ fn enlist_many(child: &KillHandle, child_arc: &TaskGroupArc,
};
if result {
// Unwinding function in case any ancestral enlisting fails
let bail: &fn(TaskGroupInner) = |tg| { leave_taskgroup(tg, child, false) };
let bail: |TaskGroupInner| = |tg| { leave_taskgroup(tg, child, false) };
// Attempt to join every ancestor group.
result = do each_ancestor(ancestors, bail) |ancestor_tg| {
// Enlist as a descendant, not as an actual member.

View File

@ -107,43 +107,43 @@ impl<T> TrieMap<T> {
/// Visit all key-value pairs in reverse order
#[inline]
pub fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
pub fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
self.root.each_reverse(f)
}
/// Visit all key-value pairs in order
#[inline]
pub fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
pub fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
self.root.each(f)
}
/// Visit all keys in order
#[inline]
pub fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
pub fn each_key(&self, f: |&uint| -> bool) -> bool {
self.each(|k, _| f(k))
}
/// Visit all values in order
#[inline]
pub fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool {
pub fn each_value<'a>(&'a self, f: |&'a T| -> bool) -> bool {
self.each(|_, v| f(v))
}
/// Iterate over the map and mutate the contained values
#[inline]
pub fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
pub fn mutate_values(&mut self, f: |&uint, &mut T| -> bool) -> bool {
self.root.mutate_values(f)
}
/// Visit all keys in reverse order
#[inline]
pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool {
pub fn each_key_reverse(&self, f: |&uint| -> bool) -> bool {
self.each_reverse(|k, _| f(k))
}
/// Visit all values in reverse order
#[inline]
pub fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool {
pub fn each_value_reverse(&self, f: |&T| -> bool) -> bool {
self.each_reverse(|_, v| f(v))
}
@ -266,11 +266,11 @@ impl TrieSet {
/// Visit all values in order
#[inline]
pub fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
pub fn each(&self, f: |&uint| -> bool) -> bool { self.map.each_key(f) }
/// Visit all values in reverse order
#[inline]
pub fn each_reverse(&self, f: &fn(&uint) -> bool) -> bool {
pub fn each_reverse(&self, f: |&uint| -> bool) -> bool {
self.map.each_key_reverse(f)
}
@ -328,7 +328,7 @@ impl<T> TrieNode<T> {
}
impl<T> TrieNode<T> {
fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
for elt in self.children.iter() {
match *elt {
Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false },
@ -339,7 +339,7 @@ impl<T> TrieNode<T> {
true
}
fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
for elt in self.children.rev_iter() {
match *elt {
Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
@ -350,7 +350,7 @@ impl<T> TrieNode<T> {
true
}
fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
fn mutate_values<'a>(&'a mut self, f: |&uint, &mut T| -> bool) -> bool {
for child in self.children.mut_iter() {
match *child {
Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) {

View File

@ -3619,15 +3619,15 @@ pub mod decompose {
('\U0001d185', '\U0001d189', 230), ('\U0001d18a', '\U0001d18b', 220),
('\U0001d1aa', '\U0001d1ad', 230), ('\U0001d242', '\U0001d244', 230)
];
pub fn canonical(c: char, i: &fn(char)) { d(c, i, false); }
pub fn canonical(c: char, i: |char|) { d(c, i, false); }
pub fn compatibility(c: char, i: &fn(char)) { d(c, i, true); }
pub fn compatibility(c: char, i: |char|) { d(c, i, true); }
pub fn canonical_combining_class(c: char) -> u8 {
bsearch_range_value_table(c, combining_class_table)
}
fn d(c: char, i: &fn(char), k: bool) {
fn d(c: char, i: |char|, k: bool) {
use iter::Iterator;
if c <= '\x7f' { i(c); return; }

View File

@ -153,10 +153,9 @@ pub mod dl {
dlopen(ptr::null(), Lazy as libc::c_int)
}
pub fn check_for_errors_in<T>(f: &fn()->T) -> Result<T, ~str> {
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, ~str> {
use unstable::mutex::{Mutex, MUTEX_INIT};
static mut lock: Mutex = MUTEX_INIT;
unsafe {
// dlerror isn't thread safe, so we need to lock around this entire
// sequence. `atomically` asserts that we don't do anything that
@ -225,7 +224,7 @@ pub mod dl {
handle
}
pub fn check_for_errors_in<T>(f: &fn()->T) -> Result<T, ~str> {
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, ~str> {
unsafe {
do atomically {
SetLastError(0);

View File

@ -28,13 +28,13 @@ use ops::Drop;
#[cfg(test)] use task::{failing, spawn};
pub trait Finally<T> {
fn finally(&self, dtor: &fn()) -> T;
fn finally(&self, dtor: ||) -> T;
}
macro_rules! finally_fn {
($fnty:ty) => {
impl<T> Finally<T> for $fnty {
fn finally(&self, dtor: &fn()) -> T {
fn finally(&self, dtor: ||) -> T {
let _d = Finallyalizer {
dtor: dtor
};
@ -45,7 +45,7 @@ macro_rules! finally_fn {
}
impl<'self,T> Finally<T> for &'self fn() -> T {
fn finally(&self, dtor: &fn()) -> T {
fn finally(&self, dtor: ||) -> T {
let _d = Finallyalizer {
dtor: dtor
};
@ -95,7 +95,7 @@ fn test_fail() {
#[test]
fn test_retval() {
let closure: &fn() -> int = || 10;
let closure: || -> int = || 10;
let i = do closure.finally { };
assert_eq!(i, 10);
}

View File

@ -73,7 +73,7 @@ mod tests {
fn synthesize_closure() {
unsafe {
let x = 10;
let f: &fn(int) -> int = |y| x + y;
let f: |int| -> int = |y| x + y;
assert_eq!(f(20), 30);
@ -87,7 +87,7 @@ mod tests {
env: environment
};
let new_f: &fn(int) -> int = cast::transmute(new_closure);
let new_f: |int| -> int = cast::transmute(new_closure);
assert_eq!(new_f(20), 30);
}
}

View File

@ -296,7 +296,7 @@ impl<T> Drop for UnsafeArc<T>{
* synchronization whatsoever. It only makes sense to use for CPU-local issues.
*/
// FIXME(#8140) should not be pub
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
pub unsafe fn atomically<U>(f: || -> U) -> U {
use rt::task::{Task, GreenTask, SchedTask};
use rt::local::Local;
@ -340,7 +340,7 @@ impl LittleLock {
}
}
pub unsafe fn lock<T>(&self, f: &fn() -> T) -> T {
pub unsafe fn lock<T>(&self, f: || -> T) -> T {
let this = cast::transmute_mut(self);
do atomically {
this.l.lock();
@ -352,7 +352,7 @@ impl LittleLock {
}
}
pub unsafe fn try_lock<T>(&self, f: &fn() -> T) -> Option<T> {
pub unsafe fn try_lock<T>(&self, f: || -> T) -> Option<T> {
let this = cast::transmute_mut(self);
do atomically {
if this.l.trylock() {
@ -372,7 +372,7 @@ impl LittleLock {
this.l.signal();
}
pub unsafe fn lock_and_wait(&self, f: &fn() -> bool) {
pub unsafe fn lock_and_wait(&self, f: || -> bool) {
let this = cast::transmute_mut(self);
do atomically {
this.l.lock();
@ -433,7 +433,7 @@ impl<T:Send> Exclusive<T> {
// accessing the provided condition variable) are prohibited while inside
// the Exclusive. Supporting that is a work in progress.
#[inline]
pub unsafe fn with<U>(&self, f: &fn(x: &mut T) -> U) -> U {
pub unsafe fn with<U>(&self, f: |x: &mut T| -> U) -> U {
let rec = self.x.get();
do (*rec).lock.lock {
if (*rec).failed {
@ -447,14 +447,14 @@ impl<T:Send> Exclusive<T> {
}
#[inline]
pub unsafe fn with_imm<U>(&self, f: &fn(x: &T) -> U) -> U {
pub unsafe fn with_imm<U>(&self, f: |x: &T| -> U) -> U {
do self.with |x| {
f(cast::transmute_immut(x))
}
}
#[inline]
pub unsafe fn hold_and_signal(&self, f: &fn(x: &mut T)) {
pub unsafe fn hold_and_signal(&self, f: |x: &mut T|) {
let rec = self.x.get();
do (*rec).lock.lock {
if (*rec).failed {
@ -468,7 +468,7 @@ impl<T:Send> Exclusive<T> {
}
#[inline]
pub unsafe fn hold_and_wait(&self, f: &fn(x: &T) -> bool) {
pub unsafe fn hold_and_wait(&self, f: |x: &T| -> bool) {
let rec = self.x.get();
do (*rec).lock.lock_and_wait {
if (*rec).failed {

View File

@ -132,7 +132,7 @@ use util;
* Creates an owned vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] {
pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> ~[T] {
unsafe {
let mut v = with_capacity(n_elts);
let p = raw::to_mut_ptr(v);
@ -211,7 +211,7 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
* onto the vector being constructed.
*/
#[inline]
pub fn build<A>(size: Option<uint>, builder: &fn(push: &fn(v: A))) -> ~[A] {
pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> ~[A] {
let mut vec = with_capacity(size.unwrap_or(4));
builder(|x| vec.push(x));
vec
@ -338,7 +338,7 @@ pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
* Apply a function to each element of a vector and return a concatenation
* of each result vector
*/
pub fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
pub fn flat_map<T, U>(v: &[T], f: |t: &T| -> ~[U]) -> ~[U] {
let mut result = ~[];
for elem in v.iter() { result.push_all_move(f(elem)); }
result
@ -946,7 +946,7 @@ pub trait ImmutableVector<'self, T> {
* Apply a function to each element of a vector and return a concatenation
* of each result vector
*/
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U];
/// Returns a pointer to the element at the given index, without doing
/// bounds checking.
unsafe fn unsafe_ref(&self, index: uint) -> *T;
@ -961,12 +961,12 @@ pub trait ImmutableVector<'self, T> {
* Returns the index where the comparator returned `Equal`, or `None` if
* not found.
*/
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>;
fn bsearch(&self, f: |&T| -> Ordering) -> Option<uint>;
/// Deprecated, use iterators where possible
/// (`self.iter().map(f)`). Apply a function to each element
/// of a vector and return the results.
fn map<U>(&self, &fn(t: &T) -> U) -> ~[U];
fn map<U>(&self, |t: &T| -> U) -> ~[U];
/**
* Work with the buffer of a vector.
@ -974,7 +974,7 @@ pub trait ImmutableVector<'self, T> {
* Allows for unsafe manipulation of vector contents, which is useful for
* foreign interop.
*/
fn as_imm_buf<U>(&self, f: &fn(*T, uint) -> U) -> U;
fn as_imm_buf<U>(&self, f: |*T, uint| -> U) -> U;
}
impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
@ -1104,7 +1104,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
}
#[inline]
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U] {
flat_map(*self, f)
}
@ -1113,7 +1113,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
self.repr().data.offset(index as int)
}
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint> {
fn bsearch(&self, f: |&T| -> Ordering) -> Option<uint> {
let mut base : uint = 0;
let mut lim : uint = self.len();
@ -1132,12 +1132,12 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
return None;
}
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] {
fn map<U>(&self, f: |t: &T| -> U) -> ~[U] {
self.iter().map(f).collect()
}
#[inline]
fn as_imm_buf<U>(&self, f: &fn(*T, uint) -> U) -> U {
fn as_imm_buf<U>(&self, f: |*T, uint| -> U) -> U {
let s = self.repr();
f(s.data, s.len)
}
@ -1212,7 +1212,7 @@ pub trait ImmutableCopyableVector<T> {
* Partitions the vector into those that satisfies the predicate, and
* those that do not.
*/
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]);
/// Returns the element at the given index, without doing bounds checking.
unsafe fn unsafe_get(&self, elem: uint) -> T;
@ -1223,7 +1223,7 @@ pub trait ImmutableCopyableVector<T> {
impl<'self,T:Clone> ImmutableCopyableVector<T> for &'self [T] {
#[inline]
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]) {
let mut lefts = ~[];
let mut rights = ~[];
@ -1370,12 +1370,12 @@ pub trait OwnedVector<T> {
/**
* Like `filter()`, but in place. Preserves order of `v`. Linear time.
*/
fn retain(&mut self, f: &fn(t: &T) -> bool);
fn retain(&mut self, f: |t: &T| -> bool);
/**
* Partitions the vector into those that satisfies the predicate, and
* those that do not.
*/
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
fn partition(self, f: |&T| -> bool) -> (~[T], ~[T]);
/**
* Expands a vector in place, initializing the new elements to the result of
@ -1389,7 +1389,7 @@ pub trait OwnedVector<T> {
* * init_op - A function to call to retreive each appended element's
* value
*/
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T);
fn grow_fn(&mut self, n: uint, op: |uint| -> T);
}
impl<T> OwnedVector<T> for ~[T] {
@ -1646,7 +1646,7 @@ impl<T> OwnedVector<T> for ~[T] {
unsafe { raw::set_len(self, newlen); }
}
fn retain(&mut self, f: &fn(t: &T) -> bool) {
fn retain(&mut self, f: |t: &T| -> bool) {
let len = self.len();
let mut deleted: uint = 0;
@ -1664,7 +1664,7 @@ impl<T> OwnedVector<T> for ~[T] {
}
#[inline]
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
fn partition(self, f: |&T| -> bool) -> (~[T], ~[T]) {
let mut lefts = ~[];
let mut rights = ~[];
@ -1678,7 +1678,7 @@ impl<T> OwnedVector<T> for ~[T] {
(lefts, rights)
}
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T) {
fn grow_fn(&mut self, n: uint, op: |uint| -> T) {
let new_len = self.len() + n;
self.reserve_at_least(new_len);
let mut i: uint = 0u;
@ -1919,7 +1919,7 @@ pub trait MutableVector<'self, T> {
unsafe fn unsafe_set(self, index: uint, val: T);
/// Similar to `as_imm_buf` but passing a `*mut T`
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U;
fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U;
}
impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
@ -2016,7 +2016,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
}
#[inline]
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U {
fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U {
let Slice{ data, len } = self.repr();
f(data as *mut T, len)
}
@ -2107,9 +2107,8 @@ pub mod raw {
* not bytes).
*/
#[inline]
pub unsafe fn buf_as_slice<T,U>(p: *T,
len: uint,
f: &fn(v: &[T]) -> U) -> U {
pub unsafe fn buf_as_slice<T,U>(p: *T, len: uint, f: |v: &[T]| -> U)
-> U {
f(cast::transmute(Slice {
data: p,
len: len
@ -2121,9 +2120,12 @@ pub mod raw {
* not bytes).
*/
#[inline]
pub unsafe fn mut_buf_as_slice<T,U>(p: *mut T,
len: uint,
f: &fn(v: &mut [T]) -> U) -> U {
pub unsafe fn mut_buf_as_slice<T,
U>(
p: *mut T,
len: uint,
f: |v: &mut [T]| -> U)
-> U {
f(cast::transmute(Slice {
data: p as *T,
len: len