Skip to content

Commit 1946265

Browse files
committed
libstd: Change all uses of &fn(A)->B over to |A|->B in libstd
1 parent eef913b commit 1946265

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+270
-236
lines changed

src/libstd/ascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl ToStrConsume for ~[Ascii] {
235235

236236
impl IterBytes for Ascii {
237237
#[inline]
238-
fn iter_bytes(&self, _lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool {
238+
fn iter_bytes(&self, _lsb0: bool, f: |buf: &[u8]| -> bool) -> bool {
239239
f([self.to_byte()])
240240
}
241241
}

src/libstd/at_vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn capacity<T>(v: @[T]) -> uint {
4343
* onto the vector being constructed.
4444
*/
4545
#[inline]
46-
pub fn build<A>(size: Option<uint>, builder: &fn(push: &fn(v: A))) -> @[A] {
46+
pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> @[A] {
4747
let mut vec = @[];
4848
unsafe { raw::reserve(&mut vec, size.unwrap_or(4)); }
4949
builder(|x| unsafe { raw::push(&mut vec, x) });
@@ -68,7 +68,7 @@ pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] {
6868

6969

7070
/// Apply a function to each element of a vector and return the results
71-
pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
71+
pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] {
7272
do build(Some(v.len())) |push| {
7373
for elem in v.iter() {
7474
push(f(elem));
@@ -82,7 +82,7 @@ pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
8282
* Creates an immutable vector of size `n_elts` and initializes the elements
8383
* to the value returned by the function `op`.
8484
*/
85-
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> @[T] {
85+
pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] {
8686
do build(Some(n_elts)) |push| {
8787
let mut i: uint = 0u;
8888
while i < n_elts { push(op(i)); i += 1u; }

src/libstd/bool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use num::FromPrimitive;
5858
/// }
5959
/// ```
6060
#[inline]
61-
pub fn all_values(blk: &fn(v: bool)) {
61+
pub fn all_values(blk: |v: bool|) {
6262
blk(true);
6363
blk(false);
6464
}

src/libstd/c_str.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl CString {
117117
/// # Failure
118118
///
119119
/// Fails if the CString is null.
120-
pub fn with_ref<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
120+
pub fn with_ref<T>(&self, f: |*libc::c_char| -> T) -> T {
121121
if self.buf.is_null() { fail!("CString is null!"); }
122122
f(self.buf)
123123
}
@@ -127,7 +127,7 @@ impl CString {
127127
/// # Failure
128128
///
129129
/// Fails if the CString is null.
130-
pub fn with_mut_ref<T>(&mut self, f: &fn(*mut libc::c_char) -> T) -> T {
130+
pub fn with_mut_ref<T>(&mut self, f: |*mut libc::c_char| -> T) -> T {
131131
if self.buf.is_null() { fail!("CString is null!"); }
132132
f(unsafe { cast::transmute_mut_unsafe(self.buf) })
133133
}
@@ -223,13 +223,13 @@ pub trait ToCStr {
223223
///
224224
/// Raises the `null_byte` condition if the receiver has an interior null.
225225
#[inline]
226-
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
226+
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
227227
self.to_c_str().with_ref(f)
228228
}
229229

230230
/// Unsafe variant of `with_c_str()` that doesn't check for nulls.
231231
#[inline]
232-
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
232+
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
233233
self.to_c_str_unchecked().with_ref(f)
234234
}
235235
}
@@ -246,12 +246,12 @@ impl<'self> ToCStr for &'self str {
246246
}
247247

248248
#[inline]
249-
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
249+
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
250250
self.as_bytes().with_c_str(f)
251251
}
252252

253253
#[inline]
254-
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
254+
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
255255
self.as_bytes().with_c_str_unchecked(f)
256256
}
257257
}
@@ -282,17 +282,17 @@ impl<'self> ToCStr for &'self [u8] {
282282
}
283283
}
284284

285-
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
285+
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
286286
unsafe { with_c_str(*self, true, f) }
287287
}
288288

289-
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
289+
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
290290
with_c_str(*self, false, f)
291291
}
292292
}
293293

294294
// Unsafe function that handles possibly copying the &[u8] into a stack array.
295-
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: &fn(*libc::c_char) -> T) -> T {
295+
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T {
296296
if v.len() < BUF_LEN {
297297
let mut buf: [u8, .. BUF_LEN] = intrinsics::uninit();
298298
vec::bytes::copy_memory(buf, v, v.len());
@@ -357,7 +357,7 @@ impl<'self> Iterator<libc::c_char> for CStringIterator<'self> {
357357
/// is found, and the number of strings found is returned.
358358
pub unsafe fn from_c_multistring(buf: *libc::c_char,
359359
count: Option<uint>,
360-
f: &fn(&CString)) -> uint {
360+
f: |&CString|) -> uint {
361361

362362
let mut curr_ptr: uint = buf as uint;
363363
let mut ctr = 0;

src/libstd/cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ impl<T> Cell<T> {
7171
}
7272

7373
/// Calls a closure with a reference to the value.
74-
pub fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
74+
pub fn with_ref<R>(&self, op: |v: &T| -> R) -> R {
7575
do self.with_mut_ref |ptr| { op(ptr) }
7676
}
7777

7878
/// Calls a closure with a mutable reference to the value.
79-
pub fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
79+
pub fn with_mut_ref<R>(&self, op: |v: &mut T| -> R) -> R {
8080
let mut v = Some(self.take());
8181
do (|| {
8282
op(v.get_mut_ref())

src/libstd/char.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static N_COUNT: uint = (V_COUNT * T_COUNT);
241241
static S_COUNT: uint = (L_COUNT * N_COUNT);
242242

243243
// Decompose a precomposed Hangul syllable
244-
fn decompose_hangul(s: char, f: &fn(char)) {
244+
fn decompose_hangul(s: char, f: |char|) {
245245
let si = s as uint - S_BASE;
246246

247247
let li = si / N_COUNT;
@@ -259,7 +259,7 @@ fn decompose_hangul(s: char, f: &fn(char)) {
259259
}
260260

261261
/// Returns the canonical decompostion of a character
262-
pub fn decompose_canonical(c: char, f: &fn(char)) {
262+
pub fn decompose_canonical(c: char, f: |char|) {
263263
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
264264
decompose::canonical(c, f);
265265
} else {
@@ -268,7 +268,7 @@ pub fn decompose_canonical(c: char, f: &fn(char)) {
268268
}
269269

270270
/// Returns the compatibility decompostion of a character
271-
pub fn decompose_compatible(c: char, f: &fn(char)) {
271+
pub fn decompose_compatible(c: char, f: |char|) {
272272
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
273273
decompose::compatibility(c, f);
274274
} else {
@@ -285,7 +285,7 @@ pub fn decompose_compatible(c: char, f: &fn(char)) {
285285
/// - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
286286
/// - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
287287
///
288-
pub fn escape_unicode(c: char, f: &fn(char)) {
288+
pub fn escape_unicode(c: char, f: |char|) {
289289
// avoid calling str::to_str_radix because we don't really need to allocate
290290
// here.
291291
f('\\');
@@ -316,7 +316,7 @@ pub fn escape_unicode(c: char, f: &fn(char)) {
316316
/// - Any other chars in the range [0x20,0x7e] are not escaped.
317317
/// - Any other chars are given hex unicode escapes; see `escape_unicode`.
318318
///
319-
pub fn escape_default(c: char, f: &fn(char)) {
319+
pub fn escape_default(c: char, f: |char|) {
320320
match c {
321321
'\t' => { f('\\'); f('t'); }
322322
'\r' => { f('\\'); f('r'); }
@@ -367,8 +367,8 @@ pub trait Char {
367367
fn is_digit_radix(&self, radix: uint) -> bool;
368368
fn to_digit(&self, radix: uint) -> Option<uint>;
369369
fn from_digit(num: uint, radix: uint) -> Option<char>;
370-
fn escape_unicode(&self, f: &fn(char));
371-
fn escape_default(&self, f: &fn(char));
370+
fn escape_unicode(&self, f: |char|);
371+
fn escape_default(&self, f: |char|);
372372
fn len_utf8_bytes(&self) -> uint;
373373

374374
/// Encodes this character as utf-8 into the provided byte-buffer. The
@@ -403,9 +403,9 @@ impl Char for char {
403403

404404
fn from_digit(num: uint, radix: uint) -> Option<char> { from_digit(num, radix) }
405405

406-
fn escape_unicode(&self, f: &fn(char)) { escape_unicode(*self, f) }
406+
fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) }
407407

408-
fn escape_default(&self, f: &fn(char)) { escape_default(*self, f) }
408+
fn escape_default(&self, f: |char|) { escape_default(*self, f) }
409409

410410
fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) }
411411

src/libstd/cleanup.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ struct AnnihilateStats {
3030
}
3131

3232
unsafe fn each_live_alloc(read_next_before: bool,
33-
f: &fn(box: *mut raw::Box<()>, uniq: bool) -> bool) -> bool {
33+
f: |box: *mut raw::Box<()>, uniq: bool| -> bool)
34+
-> bool {
3435
//! Walks the internal list of allocations
3536
3637
use managed;

src/libstd/condition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<T, U> Condition<T, U> {
133133

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

src/libstd/either.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<L, R> Either<L, R> {
3838
/// `value` is `Right(R)` then `f_right` is applied to its contents, and the
3939
/// result is returned.
4040
#[inline]
41-
pub fn either<T>(&self, f_left: &fn(&L) -> T, f_right: &fn(&R) -> T) -> T {
41+
pub fn either<T>(&self, f_left: |&L| -> T, f_right: |&R| -> T) -> T {
4242
match *self {
4343
Left(ref l) => f_left(l),
4444
Right(ref r) => f_right(r)

src/libstd/fmt/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,10 @@ impl<'self> Formatter<'self> {
931931
}
932932
}
933933

934-
fn with_padding(&mut self, padding: uint,
935-
default: parse::Alignment, f: &fn(&mut Formatter)) {
934+
fn with_padding(&mut self,
935+
padding: uint,
936+
default: parse::Alignment,
937+
f: |&mut Formatter|) {
936938
let align = match self.align {
937939
parse::AlignUnknown => default,
938940
parse::AlignLeft | parse::AlignRight => self.align

src/libstd/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ mod tests {
408408
// Hash just the bytes of the slice, without length prefix
409409
struct Bytes<'self>(&'self [u8]);
410410
impl<'self> IterBytes for Bytes<'self> {
411-
fn iter_bytes(&self, _lsb0: bool, f: &fn(&[u8]) -> bool) -> bool {
411+
fn iter_bytes(&self, _lsb0: bool, f: |&[u8]| -> bool) -> bool {
412412
f(**self)
413413
}
414414
}

src/libstd/hashmap.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
8080
}
8181

8282
#[inline]
83-
fn bucket_sequence(&self, hash: uint,
84-
op: &fn(uint) -> bool) -> bool {
83+
fn bucket_sequence(&self, hash: uint, op: |uint| -> bool) -> bool {
8584
let start_idx = self.to_bucket(hash);
8685
let len_buckets = self.buckets.len();
8786
let mut idx = start_idx;
@@ -360,8 +359,14 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
360359

361360
/// Modify and return the value corresponding to the key in the map, or
362361
/// insert and return a new value if it doesn't exist.
363-
pub fn mangle<'a,A>(&'a mut self, k: K, a: A, not_found: &fn(&K, A) -> V,
364-
found: &fn(&K, &mut V, A)) -> &'a mut V {
362+
pub fn mangle<'a,
363+
A>(
364+
&'a mut self,
365+
k: K,
366+
a: A,
367+
not_found: |&K, A| -> V,
368+
found: |&K, &mut V, A|)
369+
-> &'a mut V {
365370
if self.size >= self.resize_at {
366371
// n.b.: We could also do this after searching, so
367372
// that we do not resize if this call to insert is
@@ -395,16 +400,20 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
395400

396401
/// Return the value corresponding to the key in the map, or create,
397402
/// insert, and return a new value if it doesn't exist.
398-
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V)
403+
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: |&K| -> V)
399404
-> &'a mut V {
400405
self.mangle(k, (), |k,_a| f(k), |_k,_v,_a| ())
401406
}
402407

403408
/// Insert a key-value pair into the map if the key is not already present.
404409
/// Otherwise, modify the existing value for the key.
405410
/// Returns the new or modified value for the key.
406-
pub fn insert_or_update_with<'a>(&'a mut self, k: K, v: V,
407-
f: &fn(&K, &mut V)) -> &'a mut V {
411+
pub fn insert_or_update_with<'a>(
412+
&'a mut self,
413+
k: K,
414+
v: V,
415+
f: |&K, &mut V|)
416+
-> &'a mut V {
408417
self.mangle(k, v, |_k,a| a, |k,v,_a| f(k,v))
409418
}
410419

@@ -446,12 +455,12 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
446455
}
447456

448457
/// Visit all keys
449-
pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
458+
pub fn each_key(&self, blk: |k: &K| -> bool) -> bool {
450459
self.iter().advance(|(k, _)| blk(k))
451460
}
452461

453462
/// Visit all values
454-
pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
463+
pub fn each_value<'a>(&'a self, blk: |v: &'a V| -> bool) -> bool {
455464
self.iter().advance(|(_, v)| blk(v))
456465
}
457466

src/libstd/io/extensions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ impl<'self, R: Reader> Iterator<u8> for ByteIterator<R> {
5454
}
5555
}
5656

57-
pub fn u64_to_le_bytes<T>(n: u64, size: uint,
58-
f: &fn(v: &[u8]) -> T) -> T {
57+
pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
5958
assert!(size <= 8u);
6059
match size {
6160
1u => f(&[n as u8]),
@@ -88,8 +87,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
8887
}
8988
}
9089

91-
pub fn u64_to_be_bytes<T>(n: u64, size: uint,
92-
f: &fn(v: &[u8]) -> T) -> T {
90+
pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
9391
assert!(size <= 8u);
9492
match size {
9593
1u => f(&[n as u8]),

src/libstd/io/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct File {
7575
priv last_nread: int,
7676
}
7777

78-
fn io_raise<T>(f: &fn(io: &mut IoFactory) -> Result<T, IoError>) -> Option<T> {
78+
fn io_raise<T>(f: |io: &mut IoFactory| -> Result<T, IoError>) -> Option<T> {
7979
do with_local_io |io| {
8080
match f(io) {
8181
Ok(t) => Some(t),
@@ -499,7 +499,7 @@ pub fn rmdir(path: &Path) {
499499
/// use std::io::fs;
500500
///
501501
/// // one possible implementation of fs::walk_dir only visiting files
502-
/// fn visit_dirs(dir: &Path, cb: &fn(&Path)) {
502+
/// fn visit_dirs(dir: &Path, cb: |&Path|) {
503503
/// if dir.is_dir() {
504504
/// let contents = fs::readdir(dir).unwrap();
505505
/// for entry in contents.iter() {

src/libstd/io/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<'self> Buffer for BufReader<'self> {
240240

241241
///Calls a function with a MemWriter and returns
242242
///the writer's stored vector.
243-
pub fn with_mem_writer(writeFn:&fn(&mut MemWriter)) -> ~[u8] {
243+
pub fn with_mem_writer(writeFn: |&mut MemWriter|) -> ~[u8] {
244244
let mut writer = MemWriter::new();
245245
writeFn(&mut writer);
246246
writer.inner()

src/libstd/io/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ condition! {
394394

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

0 commit comments

Comments
 (0)