diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index b3da9b4f16b..4660036a774 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -220,7 +220,7 @@ impl MutexArc { * blocked on the mutex) will also fail immediately. */ #[inline] - pub unsafe fn unsafe_access(&self, blk: &fn(x: &mut T) -> U) -> U { + pub unsafe fn unsafe_access(&self, blk: |x: &mut T| -> U) -> U { let state = self.x.get(); // Borrowck would complain about this if the function were // not already unsafe. See borrow_rwlock, far below. @@ -234,8 +234,7 @@ impl MutexArc { /// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond(). #[inline] pub unsafe fn unsafe_access_cond(&self, - blk: &fn(x: &mut T, - c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { let state = self.x.get(); do (&(*state).lock).lock_cond |cond| { @@ -284,15 +283,14 @@ impl MutexArc { * unsafe_access_cond. */ #[inline] - pub fn access(&self, blk: &fn(x: &mut T) -> U) -> U { + pub fn access(&self, blk: |x: &mut T| -> U) -> U { unsafe { self.unsafe_access(blk) } } /// As unsafe_access_cond but safe and Freeze. #[inline] pub fn access_cond(&self, - blk: &fn(x: &mut T, - c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { unsafe { self.unsafe_access_cond(blk) } } @@ -389,7 +387,7 @@ impl RWArc { * poison the Arc, so subsequent readers and writers will both also fail. */ #[inline] - pub fn write(&self, blk: &fn(x: &mut T) -> U) -> U { + pub fn write(&self, blk: |x: &mut T| -> U) -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write { @@ -403,7 +401,7 @@ impl RWArc { /// As write(), but with a condvar, as sync::rwlock.write_cond(). #[inline] pub fn write_cond(&self, - blk: &fn(x: &mut T, c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { unsafe { let state = self.x.get(); @@ -427,7 +425,7 @@ impl RWArc { * Failing will unlock the Arc while unwinding. However, unlike all other * access modes, this will not poison the Arc. */ - pub fn read(&self, blk: &fn(x: &T) -> U) -> U { + pub fn read(&self, blk: |x: &T| -> U) -> U { unsafe { let state = self.x.get(); do (*state).lock.read { @@ -457,7 +455,7 @@ impl RWArc { * } * ``` */ - pub fn write_downgrade(&self, blk: &fn(v: RWWriteMode) -> U) -> U { + pub fn write_downgrade(&self, blk: |v: RWWriteMode| -> U) -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write_downgrade |write_mode| { @@ -539,7 +537,7 @@ pub struct RWReadMode<'self, T> { impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { /// Access the pre-downgrade RWArc in write mode. - pub fn write(&mut self, blk: &fn(x: &mut T) -> U) -> U { + pub fn write(&mut self, blk: |x: &mut T| -> U) -> U { match *self { RWWriteMode { data: &ref mut data, @@ -555,7 +553,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { /// Access the pre-downgrade RWArc in write mode with a condvar. pub fn write_cond(&mut self, - blk: &fn(x: &mut T, c: &Condvar) -> U) + blk: |x: &mut T, c: &Condvar| -> U) -> U { match *self { RWWriteMode { @@ -580,7 +578,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { impl<'self, T:Freeze + Send> RWReadMode<'self, T> { /// Access the post-downgrade rwlock in read mode. - pub fn read(&self, blk: &fn(x: &T) -> U) -> U { + pub fn read(&self, blk: |x: &T| -> U) -> U { match *self { RWReadMode { data: data, diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index b684e0d429e..2bb36e25fcb 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -184,7 +184,7 @@ impl Arena { } #[inline] - fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { + fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T { unsafe { let tydesc = get_tydesc::(); let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align); @@ -241,7 +241,7 @@ impl Arena { } #[inline] - fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { + fn alloc_nonpod<'a, T>(&'a mut self, op: || -> T) -> &'a T { unsafe { let tydesc = get_tydesc::(); let (ty_ptr, ptr) = @@ -263,7 +263,7 @@ impl Arena { // The external interface #[inline] - pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T { + pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T { unsafe { // XXX: Borrow check let this = transmute_mut(self); diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 96123ad75b2..c68133dac10 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -40,7 +40,7 @@ impl SmallBitv { pub fn bits_op(&mut self, right_bits: uint, nbits: uint, - f: &fn(uint, uint) -> uint) + f: |uint, uint| -> uint) -> bool { let mask = small_mask(nbits); let old_b: uint = self.bits; @@ -140,7 +140,7 @@ impl BigBitv { pub fn process(&mut self, b: &BigBitv, nbits: uint, - op: &fn(uint, uint) -> uint) + op: |uint, uint| -> uint) -> bool { let len = b.storage.len(); assert_eq!(self.storage.len(), len); @@ -161,7 +161,7 @@ impl BigBitv { } #[inline] - pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool { + pub fn each_storage(&mut self, op: |v: &mut uint| -> bool) -> bool { self.storage.mut_iter().advance(|elt| op(elt)) } @@ -512,7 +512,7 @@ impl Bitv { true } - pub fn ones(&self, f: &fn(uint) -> bool) -> bool { + pub fn ones(&self, f: |uint| -> bool) -> bool { range(0u, self.nbits).advance(|i| !self.get(i) || f(i)) } @@ -542,7 +542,7 @@ pub fn from_bools(bools: &[bool]) -> Bitv { * Create a `Bitv` of the specified length where the value at each * index is `f(index)`. */ -pub fn from_fn(len: uint, f: &fn(index: uint) -> bool) -> Bitv { +pub fn from_fn(len: uint, f: |index: uint| -> bool) -> Bitv { let mut bitv = Bitv::new(len, false); for i in range(0u, len) { bitv.set(i, f(i)); @@ -557,7 +557,7 @@ impl ops::Index for Bitv { } #[inline] -fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool { +fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool { if bits == 0 { return true; } @@ -675,7 +675,7 @@ impl BitvSet { } #[inline] - fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) { + fn other_op(&mut self, other: &BitvSet, f: |uint, uint| -> uint) { fn nbits(mut w: uint) -> uint { let mut bits = 0; for _ in range(0u, uint::bits) { @@ -722,7 +722,7 @@ impl BitvSet { BitvSetIterator {set: self, next_idx: 0} } - pub fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool { + pub fn difference(&self, other: &BitvSet, f: |&uint| -> bool) -> bool { for (i, w1, w2) in self.common_iter(other) { if !iterate_bits(i, w1 & !w2, |b| f(&b)) { return false @@ -734,8 +734,8 @@ impl BitvSet { ) } - pub fn symmetric_difference(&self, other: &BitvSet, - f: &fn(&uint) -> bool) -> bool { + pub fn symmetric_difference(&self, other: &BitvSet, f: |&uint| -> bool) + -> bool { for (i, w1, w2) in self.common_iter(other) { if !iterate_bits(i, w1 ^ w2, |b| f(&b)) { return false @@ -744,11 +744,11 @@ impl BitvSet { self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b))) } - pub fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool { + pub fn intersection(&self, other: &BitvSet, f: |&uint| -> bool) -> bool { self.common_iter(other).advance(|(i, w1, w2)| iterate_bits(i, w1 & w2, |b| f(&b))) } - pub fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool { + pub fn union(&self, other: &BitvSet, f: |&uint| -> bool) -> bool { for (i, w1, w2) in self.common_iter(other) { if !iterate_bits(i, w1 | w2, |b| f(&b)) { return false diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index f29cbd6ee52..418b8256189 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -320,7 +320,7 @@ impl DList { /// or at the end. /// /// O(N) - pub fn insert_when(&mut self, elt: T, f: &fn(&T, &T) -> bool) { + pub fn insert_when(&mut self, elt: T, f: |&T, &T| -> bool) { { let mut it = self.mut_iter(); loop { @@ -339,7 +339,7 @@ impl DList { /// put `a` in the result if `f(a, b)` is true, else `b`. /// /// O(max(N, M)) - pub fn merge(&mut self, mut other: DList, f: &fn(&T, &T) -> bool) { + pub fn merge(&mut self, mut other: DList, f: |&T, &T| -> bool) { { let mut it = self.mut_iter(); loop { diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index c249a8c09f2..c82ee733a4c 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -216,7 +216,7 @@ pub mod reader { } } - pub fn docs(d: Doc, it: &fn(uint, Doc) -> bool) -> bool { + pub fn docs(d: Doc, it: |uint, Doc| -> bool) -> bool { let mut pos = d.start; while pos < d.end { let elt_tag = vuint_at(*d.data, pos); @@ -230,7 +230,7 @@ pub mod reader { return true; } - pub fn tagged_docs(d: Doc, tg: uint, it: &fn(Doc) -> bool) -> bool { + pub fn tagged_docs(d: Doc, tg: uint, it: |Doc| -> bool) -> bool { let mut pos = d.start; while pos < d.end { let elt_tag = vuint_at(*d.data, pos); @@ -247,7 +247,7 @@ pub mod reader { return true; } - pub fn with_doc_data(d: Doc, f: &fn(x: &[u8]) -> T) -> T { + pub fn with_doc_data(d: Doc, f: |x: &[u8]| -> T) -> T { f(d.data.slice(d.start, d.end)) } @@ -332,7 +332,7 @@ pub mod reader { } fn push_doc(&mut self, exp_tag: EbmlEncoderTag, - f: &fn(&mut Decoder) -> T) -> T { + f: |&mut Decoder| -> T) -> T { let d = self.next_doc(exp_tag); let old_parent = self.parent; let old_pos = self.pos; @@ -352,8 +352,7 @@ pub mod reader { } impl Decoder { - pub fn read_opaque(&mut self, op: &fn(&mut Decoder, Doc) -> R) - -> R { + pub fn read_opaque(&mut self, op: |&mut Decoder, Doc| -> R) -> R { let doc = self.next_doc(EsOpaque); let (old_parent, old_pos) = (self.parent, self.pos); @@ -424,10 +423,7 @@ pub mod reader { } // Compound types: - fn read_enum(&mut self, - name: &str, - f: &fn(&mut Decoder) -> T) - -> T { + fn read_enum(&mut self, name: &str, f: |&mut Decoder| -> T) -> T { debug!("read_enum({})", name); self._check_label(name); @@ -446,7 +442,7 @@ pub mod reader { fn read_enum_variant(&mut self, _: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_variant()"); let idx = self._next_uint(EsEnumVid); @@ -467,14 +463,14 @@ pub mod reader { fn read_enum_variant_arg(&mut self, idx: uint, - f: &fn(&mut Decoder) -> T) -> T { + f: |&mut Decoder| -> T) -> T { debug!("read_enum_variant_arg(idx={})", idx); f(self) } fn read_enum_struct_variant(&mut self, _: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_struct_variant()"); let idx = self._next_uint(EsEnumVid); @@ -496,7 +492,7 @@ pub mod reader { fn read_enum_struct_variant_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx); f(self) @@ -505,7 +501,7 @@ pub mod reader { fn read_struct(&mut self, name: &str, _: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct(name={})", name); f(self) @@ -514,19 +510,19 @@ pub mod reader { fn read_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct_field(name={}, idx={})", name, idx); self._check_label(name); f(self) } - fn read_tuple(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_tuple(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple()"); self.read_seq(f) } - fn read_tuple_arg(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) + fn read_tuple_arg(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_tuple_arg(idx={})", idx); self.read_seq_elt(idx, f) @@ -534,7 +530,7 @@ pub mod reader { fn read_tuple_struct(&mut self, name: &str, - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple_struct(name={})", name); self.read_tuple(f) @@ -542,13 +538,13 @@ pub mod reader { fn read_tuple_struct_arg(&mut self, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_tuple_struct_arg(idx={})", idx); self.read_tuple_arg(idx, f) } - fn read_option(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T { + fn read_option(&mut self, f: |&mut Decoder, bool| -> T) -> T { debug!("read_option()"); do self.read_enum("Option") |this| { do this.read_enum_variant(["None", "Some"]) |this, idx| { @@ -561,7 +557,7 @@ pub mod reader { } } - fn read_seq(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_seq(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_seq()"); do self.push_doc(EsVec) |d| { let len = d._next_uint(EsVecLen); @@ -570,13 +566,13 @@ pub mod reader { } } - fn read_seq_elt(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) + fn read_seq_elt(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_seq_elt(idx={})", idx); self.push_doc(EsVecElt, f) } - fn read_map(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_map(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_map()"); do self.push_doc(EsMap) |d| { let len = d._next_uint(EsMapLen); @@ -585,17 +581,13 @@ pub mod reader { } } - fn read_map_elt_key(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_map_elt_key(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_key(idx={})", idx); self.push_doc(EsMapKey, f) } - fn read_map_elt_val(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_map_elt_val(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_val(idx={})", idx); self.push_doc(EsMapVal, f) @@ -682,7 +674,7 @@ pub mod writer { debug!("End tag (size = {})", size); } - pub fn wr_tag(&mut self, tag_id: uint, blk: &fn()) { + pub fn wr_tag(&mut self, tag_id: uint, blk: ||) { self.start_tag(tag_id); blk(); self.end_tag(); @@ -779,7 +771,7 @@ pub mod writer { } impl Encoder { - pub fn emit_opaque(&mut self, f: &fn(&mut Encoder)) { + pub fn emit_opaque(&mut self, f: |&mut Encoder|) { self.start_tag(EsOpaque as uint); f(self); self.end_tag(); @@ -841,7 +833,7 @@ pub mod writer { self.wr_tagged_str(EsStr as uint, v) } - fn emit_enum(&mut self, name: &str, f: &fn(&mut Encoder)) { + fn emit_enum(&mut self, name: &str, f: |&mut Encoder|) { self._emit_label(name); self.start_tag(EsEnum as uint); f(self); @@ -852,14 +844,14 @@ pub mod writer { _: &str, v_id: uint, _: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self._emit_tagged_uint(EsEnumVid, v_id); self.start_tag(EsEnumBody as uint); f(self); self.end_tag(); } - fn emit_enum_variant_arg(&mut self, _: uint, f: &fn(&mut Encoder)) { + fn emit_enum_variant_arg(&mut self, _: uint, f: |&mut Encoder|) { f(self) } @@ -867,83 +859,83 @@ pub mod writer { v_name: &str, v_id: uint, cnt: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant(v_name, v_id, cnt, f) } fn emit_enum_struct_variant_field(&mut self, _: &str, idx: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant_arg(idx, f) } - fn emit_struct(&mut self, _: &str, _len: uint, f: &fn(&mut Encoder)) { + fn emit_struct(&mut self, _: &str, _len: uint, f: |&mut Encoder|) { f(self) } fn emit_struct_field(&mut self, name: &str, _: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self._emit_label(name); f(self) } - fn emit_tuple(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_tuple(&mut self, len: uint, f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } fn emit_tuple_struct(&mut self, _: &str, len: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_struct_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_struct_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } - fn emit_option(&mut self, f: &fn(&mut Encoder)) { + fn emit_option(&mut self, f: |&mut Encoder|) { self.emit_enum("Option", f); } fn emit_option_none(&mut self) { self.emit_enum_variant("None", 0, 0, |_| ()) } - fn emit_option_some(&mut self, f: &fn(&mut Encoder)) { + fn emit_option_some(&mut self, f: |&mut Encoder|) { self.emit_enum_variant("Some", 1, 1, f) } - fn emit_seq(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_seq(&mut self, len: uint, f: |&mut Encoder|) { self.start_tag(EsVec as uint); self._emit_tagged_uint(EsVecLen, len); f(self); self.end_tag(); } - fn emit_seq_elt(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_seq_elt(&mut self, _idx: uint, f: |&mut Encoder|) { self.start_tag(EsVecElt as uint); f(self); self.end_tag(); } - fn emit_map(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_map(&mut self, len: uint, f: |&mut Encoder|) { self.start_tag(EsMap as uint); self._emit_tagged_uint(EsMapLen, len); f(self); self.end_tag(); } - fn emit_map_elt_key(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_key(&mut self, _idx: uint, f: |&mut Encoder|) { self.start_tag(EsMapKey as uint); f(self); self.end_tag(); } - fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder|) { self.start_tag(EsMapVal as uint); f(self); self.end_tag(); diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index 918952132ab..d0df9dbe838 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -768,9 +768,8 @@ pub mod groups { /// /// Fails during iteration if the string contains a non-whitespace /// sequence longer than the limit. - fn each_split_within<'a>(ss: &'a str, - lim: uint, - it: &fn(&'a str) -> bool) -> bool { + fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool) + -> bool { // Just for fun, let's write this as a state machine: enum SplitWithinState { @@ -795,14 +794,14 @@ pub mod groups { let mut lim = lim; let mut cont = true; - let slice: &fn() = || { cont = it(ss.slice(slice_start, last_end)) }; + let slice: || = || { cont = it(ss.slice(slice_start, last_end)) }; // if the limit is larger than the string, lower it to save cycles if (lim >= fake_i) { lim = fake_i; } - let machine: &fn((uint, char)) -> bool = |(i, c)| { + let machine: |(uint, char)| -> bool = |(i, c)| { let whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr }; let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim }; diff --git a/src/libextra/json.rs b/src/libextra/json.rs index 7370dfafba9..64655ca2b70 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -129,13 +129,13 @@ impl serialize::Encoder for Encoder { write!(self.wr, "{}", escape_str(v)) } - fn emit_enum(&mut self, _name: &str, f: &fn(&mut Encoder)) { f(self) } + fn emit_enum(&mut self, _name: &str, f: |&mut Encoder|) { f(self) } fn emit_enum_variant(&mut self, name: &str, _id: uint, cnt: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { // enums are encoded as strings or objects // Bunny => "Bunny" // Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]} @@ -150,7 +150,7 @@ impl serialize::Encoder for Encoder { } } - fn emit_enum_variant_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_enum_variant_arg(&mut self, idx: uint, f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ","); } @@ -161,18 +161,18 @@ impl serialize::Encoder for Encoder { name: &str, id: uint, cnt: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant(name, id, cnt, f) } fn emit_enum_struct_variant_field(&mut self, _: &str, idx: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_enum_variant_arg(idx, f) } - fn emit_struct(&mut self, _: &str, _: uint, f: &fn(&mut Encoder)) { + fn emit_struct(&mut self, _: &str, _: uint, f: |&mut Encoder|) { write!(self.wr, r"\{"); f(self); write!(self.wr, r"\}"); @@ -181,58 +181,58 @@ impl serialize::Encoder for Encoder { fn emit_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ",") } write!(self.wr, "{}:", escape_str(name)); f(self); } - fn emit_tuple(&mut self, len: uint, f: &fn(&mut Encoder)) { + fn emit_tuple(&mut self, len: uint, f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } fn emit_tuple_struct(&mut self, _name: &str, len: uint, - f: &fn(&mut Encoder)) { + f: |&mut Encoder|) { self.emit_seq(len, f) } - fn emit_tuple_struct_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_tuple_struct_arg(&mut self, idx: uint, f: |&mut Encoder|) { self.emit_seq_elt(idx, f) } - fn emit_option(&mut self, f: &fn(&mut Encoder)) { f(self); } + fn emit_option(&mut self, f: |&mut Encoder|) { f(self); } fn emit_option_none(&mut self) { self.emit_nil(); } - fn emit_option_some(&mut self, f: &fn(&mut Encoder)) { f(self); } + fn emit_option_some(&mut self, f: |&mut Encoder|) { f(self); } - fn emit_seq(&mut self, _len: uint, f: &fn(&mut Encoder)) { + fn emit_seq(&mut self, _len: uint, f: |&mut Encoder|) { write!(self.wr, "["); f(self); write!(self.wr, "]"); } - fn emit_seq_elt(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_seq_elt(&mut self, idx: uint, f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ","); } f(self) } - fn emit_map(&mut self, _len: uint, f: &fn(&mut Encoder)) { + fn emit_map(&mut self, _len: uint, f: |&mut Encoder|) { write!(self.wr, r"\{"); f(self); write!(self.wr, r"\}"); } - fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Encoder|) { if idx != 0 { write!(self.wr, ",") } f(self) } - fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut Encoder)) { + fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder|) { write!(self.wr, ":"); f(self) } @@ -284,7 +284,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } fn emit_str(&mut self, v: &str) { write!(self.wr, "{}", escape_str(v)); } - fn emit_enum(&mut self, _name: &str, f: &fn(&mut PrettyEncoder)) { + fn emit_enum(&mut self, _name: &str, f: |&mut PrettyEncoder|) { f(self) } @@ -292,7 +292,7 @@ impl serialize::Encoder for PrettyEncoder { name: &str, _: uint, cnt: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if cnt == 0 { write!(self.wr, "{}", escape_str(name)); } else { @@ -306,7 +306,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_enum_variant_arg(&mut self, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if idx != 0 { write!(self.wr, ",\n"); } @@ -318,14 +318,14 @@ impl serialize::Encoder for PrettyEncoder { name: &str, id: uint, cnt: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_enum_variant(name, id, cnt, f) } fn emit_enum_struct_variant_field(&mut self, _: &str, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_enum_variant_arg(idx, f) } @@ -333,7 +333,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_struct(&mut self, _: &str, len: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if len == 0 { write!(self.wr, "\\{\\}"); } else { @@ -348,7 +348,7 @@ impl serialize::Encoder for PrettyEncoder { fn emit_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { if idx == 0 { write!(self.wr, "\n"); } else { @@ -358,30 +358,30 @@ impl serialize::Encoder for PrettyEncoder { f(self); } - fn emit_tuple(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_tuple(&mut self, len: uint, f: |&mut PrettyEncoder|) { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut PrettyEncoder|) { self.emit_seq_elt(idx, f) } fn emit_tuple_struct(&mut self, _: &str, len: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_seq(len, f) } fn emit_tuple_struct_arg(&mut self, idx: uint, - f: &fn(&mut PrettyEncoder)) { + f: |&mut PrettyEncoder|) { self.emit_seq_elt(idx, f) } - fn emit_option(&mut self, f: &fn(&mut PrettyEncoder)) { f(self); } + fn emit_option(&mut self, f: |&mut PrettyEncoder|) { f(self); } fn emit_option_none(&mut self) { self.emit_nil(); } - fn emit_option_some(&mut self, f: &fn(&mut PrettyEncoder)) { f(self); } + fn emit_option_some(&mut self, f: |&mut PrettyEncoder|) { f(self); } - fn emit_seq(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_seq(&mut self, len: uint, f: |&mut PrettyEncoder|) { if len == 0 { write!(self.wr, "[]"); } else { @@ -393,7 +393,7 @@ impl serialize::Encoder for PrettyEncoder { } } - fn emit_seq_elt(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_seq_elt(&mut self, idx: uint, f: |&mut PrettyEncoder|) { if idx == 0 { write!(self.wr, "\n"); } else { @@ -403,7 +403,7 @@ impl serialize::Encoder for PrettyEncoder { f(self) } - fn emit_map(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_map(&mut self, len: uint, f: |&mut PrettyEncoder|) { if len == 0 { write!(self.wr, "\\{\\}"); } else { @@ -415,7 +415,7 @@ impl serialize::Encoder for PrettyEncoder { } } - fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_map_elt_key(&mut self, idx: uint, f: |&mut PrettyEncoder|) { if idx == 0 { write!(self.wr, "\n"); } else { @@ -425,7 +425,7 @@ impl serialize::Encoder for PrettyEncoder { f(self); } - fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut PrettyEncoder)) { + fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut PrettyEncoder|) { write!(self.wr, ": "); f(self); } @@ -921,14 +921,14 @@ impl serialize::Decoder for Decoder { } } - fn read_enum(&mut self, name: &str, f: &fn(&mut Decoder) -> T) -> T { + fn read_enum(&mut self, name: &str, f: |&mut Decoder| -> T) -> T { debug!("read_enum({})", name); f(self) } fn read_enum_variant(&mut self, names: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_variant(names={:?})", names); let name = match self.stack.pop() { @@ -957,9 +957,7 @@ impl serialize::Decoder for Decoder { f(self, idx) } - fn read_enum_variant_arg(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_enum_variant_arg(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_enum_variant_arg(idx={})", idx); f(self) @@ -967,7 +965,7 @@ impl serialize::Decoder for Decoder { fn read_enum_struct_variant(&mut self, names: &[&str], - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_struct_variant(names={:?})", names); self.read_enum_variant(names, f) @@ -977,7 +975,7 @@ impl serialize::Decoder for Decoder { fn read_enum_struct_variant_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_enum_struct_variant_field(name={}, idx={})", name, idx); self.read_enum_variant_arg(idx, f) @@ -986,7 +984,7 @@ impl serialize::Decoder for Decoder { fn read_struct(&mut self, name: &str, len: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct(name={}, len={})", name, len); let value = f(self); @@ -997,7 +995,7 @@ impl serialize::Decoder for Decoder { fn read_struct_field(&mut self, name: &str, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_struct_field(name={}, idx={})", name, idx); match self.stack.pop() { @@ -1017,22 +1015,19 @@ impl serialize::Decoder for Decoder { } } - fn read_tuple(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_tuple(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple()"); self.read_seq(f) } - fn read_tuple_arg(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) - -> T { + fn read_tuple_arg(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_tuple_arg(idx={})", idx); self.read_seq_elt(idx, f) } fn read_tuple_struct(&mut self, name: &str, - f: &fn(&mut Decoder, uint) -> T) + f: |&mut Decoder, uint| -> T) -> T { debug!("read_tuple_struct(name={})", name); self.read_tuple(f) @@ -1040,20 +1035,20 @@ impl serialize::Decoder for Decoder { fn read_tuple_struct_arg(&mut self, idx: uint, - f: &fn(&mut Decoder) -> T) + f: |&mut Decoder| -> T) -> T { debug!("read_tuple_struct_arg(idx={})", idx); self.read_tuple_arg(idx, f) } - fn read_option(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T { + fn read_option(&mut self, f: |&mut Decoder, bool| -> T) -> T { match self.stack.pop() { Null => f(self, false), value => { self.stack.push(value); f(self, true) } } } - fn read_seq(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_seq(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_seq()"); let len = match self.stack.pop() { List(list) => { @@ -1068,12 +1063,12 @@ impl serialize::Decoder for Decoder { f(self, len) } - fn read_seq_elt(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) -> T { + fn read_seq_elt(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_seq_elt(idx={})", idx); f(self) } - fn read_map(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { + fn read_map(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_map()"); let len = match self.stack.pop() { Object(obj) => { @@ -1089,15 +1084,13 @@ impl serialize::Decoder for Decoder { f(self, len) } - fn read_map_elt_key(&mut self, - idx: uint, - f: &fn(&mut Decoder) -> T) + fn read_map_elt_key(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_key(idx={})", idx); f(self) } - fn read_map_elt_val(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) + fn read_map_elt_val(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T { debug!("read_map_elt_val(idx={})", idx); f(self) @@ -1482,7 +1475,7 @@ mod tests { assert_eq!(a.clone(), from_str(a.to_pretty_str()).unwrap()); } - fn with_str_writer(f: &fn(@mut io::Writer)) -> ~str { + fn with_str_writer(f: |@mut io::Writer|) -> ~str { use std::io::mem::MemWriter; use std::io::Decorator; use std::str; diff --git a/src/libextra/list.rs b/src/libextra/list.rs index 5eada3dfb1a..22d273e5747 100644 --- a/src/libextra/list.rs +++ b/src/libextra/list.rs @@ -44,7 +44,7 @@ pub fn from_vec(v: &[T]) -> @List { * * z - The initial value * * f - The function to apply */ -pub fn foldl(z: T, ls: @List, f: &fn(&T, &U) -> T) -> T { +pub fn foldl(z: T, ls: @List, f: |&T, &U| -> T) -> T { let mut accum: T = z; do iter(ls) |elt| { accum = f(&accum, elt);} accum @@ -57,7 +57,7 @@ pub fn foldl(z: T, ls: @List, f: &fn(&T, &U) -> T) -> T { * When function `f` returns true then an option containing the element * is returned. If `f` matches no elements then none is returned. */ -pub fn find(ls: @List, f: &fn(&T) -> bool) -> Option { +pub fn find(ls: @List, f: |&T| -> bool) -> Option { let mut ls = ls; loop { ls = match *ls { @@ -131,7 +131,7 @@ fn push(ll: &mut @list, vv: T) { */ /// Iterate over a list -pub fn iter(l: @List, f: &fn(&T)) { +pub fn iter(l: @List, f: |&T|) { let mut cur = l; loop { cur = match *cur { @@ -145,7 +145,7 @@ pub fn iter(l: @List, f: &fn(&T)) { } /// Iterate over a list -pub fn each(l: @List, f: &fn(&T) -> bool) -> bool { +pub fn each(l: @List, f: |&T| -> bool) -> bool { let mut cur = l; loop { cur = match *cur { @@ -160,7 +160,7 @@ pub fn each(l: @List, f: &fn(&T) -> bool) -> bool { impl MutList { /// Iterate over a mutable list - pub fn each(@mut self, f: &fn(&mut T) -> bool) -> bool { + pub fn each(@mut self, f: |&mut T| -> bool) -> bool { let mut cur = self; loop { let borrowed = &mut *cur; diff --git a/src/libextra/semver.rs b/src/libextra/semver.rs index 0ab38cdb5df..3de71c83c49 100644 --- a/src/libextra/semver.rs +++ b/src/libextra/semver.rs @@ -145,8 +145,8 @@ condition! { bad_parse: () -> (); } -fn take_nonempty_prefix>(rdr: &mut T, - pred: &fn(char) -> bool) -> (~str, Option) { +fn take_nonempty_prefix>(rdr: &mut T, pred: |char| -> bool) + -> (~str, Option) { let mut buf = ~""; let mut ch = rdr.next(); loop { diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index fb87414c8c3..8e75be651cf 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -47,48 +47,48 @@ pub trait Encoder { fn emit_str(&mut self, v: &str); // Compound types: - fn emit_enum(&mut self, name: &str, f: &fn(&mut Self)); + fn emit_enum(&mut self, name: &str, f: |&mut Self|); fn emit_enum_variant(&mut self, v_name: &str, v_id: uint, len: uint, - f: &fn(&mut Self)); - fn emit_enum_variant_arg(&mut self, a_idx: uint, f: &fn(&mut Self)); + f: |&mut Self|); + fn emit_enum_variant_arg(&mut self, a_idx: uint, f: |&mut Self|); fn emit_enum_struct_variant(&mut self, v_name: &str, v_id: uint, len: uint, - f: &fn(&mut Self)); + f: |&mut Self|); fn emit_enum_struct_variant_field(&mut self, f_name: &str, f_idx: uint, - f: &fn(&mut Self)); + f: |&mut Self|); - fn emit_struct(&mut self, name: &str, len: uint, f: &fn(&mut Self)); + fn emit_struct(&mut self, name: &str, len: uint, f: |&mut Self|); fn emit_struct_field(&mut self, f_name: &str, f_idx: uint, - f: &fn(&mut Self)); + f: |&mut Self|); - fn emit_tuple(&mut self, len: uint, f: &fn(&mut Self)); - fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Self)); + fn emit_tuple(&mut self, len: uint, f: |&mut Self|); + fn emit_tuple_arg(&mut self, idx: uint, f: |&mut Self|); - fn emit_tuple_struct(&mut self, name: &str, len: uint, f: &fn(&mut Self)); - fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: &fn(&mut Self)); + fn emit_tuple_struct(&mut self, name: &str, len: uint, f: |&mut Self|); + fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: |&mut Self|); // Specialized types: - fn emit_option(&mut self, f: &fn(&mut Self)); + fn emit_option(&mut self, f: |&mut Self|); fn emit_option_none(&mut self); - fn emit_option_some(&mut self, f: &fn(&mut Self)); + fn emit_option_some(&mut self, f: |&mut Self|); - fn emit_seq(&mut self, len: uint, f: &fn(this: &mut Self)); - fn emit_seq_elt(&mut self, idx: uint, f: &fn(this: &mut Self)); + fn emit_seq(&mut self, len: uint, f: |this: &mut Self|); + fn emit_seq_elt(&mut self, idx: uint, f: |this: &mut Self|); - fn emit_map(&mut self, len: uint, f: &fn(&mut Self)); - fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut Self)); - fn emit_map_elt_val(&mut self, idx: uint, f: &fn(&mut Self)); + fn emit_map(&mut self, len: uint, f: |&mut Self|); + fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Self|); + fn emit_map_elt_val(&mut self, idx: uint, f: |&mut Self|); } pub trait Decoder { @@ -111,59 +111,56 @@ pub trait Decoder { fn read_str(&mut self) -> ~str; // Compound types: - fn read_enum(&mut self, name: &str, f: &fn(&mut Self) -> T) -> T; + fn read_enum(&mut self, name: &str, f: |&mut Self| -> T) -> T; fn read_enum_variant(&mut self, names: &[&str], - f: &fn(&mut Self, uint) -> T) + f: |&mut Self, uint| -> T) -> T; fn read_enum_variant_arg(&mut self, a_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; fn read_enum_struct_variant(&mut self, names: &[&str], - f: &fn(&mut Self, uint) -> T) + f: |&mut Self, uint| -> T) -> T; fn read_enum_struct_variant_field(&mut self, &f_name: &str, f_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; - fn read_struct(&mut self, - s_name: &str, - len: uint, - f: &fn(&mut Self) -> T) + fn read_struct(&mut self, s_name: &str, len: uint, f: |&mut Self| -> T) -> T; fn read_struct_field(&mut self, f_name: &str, f_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; - fn read_tuple(&mut self, f: &fn(&mut Self, uint) -> T) -> T; - fn read_tuple_arg(&mut self, a_idx: uint, f: &fn(&mut Self) -> T) -> T; + fn read_tuple(&mut self, f: |&mut Self, uint| -> T) -> T; + fn read_tuple_arg(&mut self, a_idx: uint, f: |&mut Self| -> T) -> T; fn read_tuple_struct(&mut self, s_name: &str, - f: &fn(&mut Self, uint) -> T) + f: |&mut Self, uint| -> T) -> T; fn read_tuple_struct_arg(&mut self, a_idx: uint, - f: &fn(&mut Self) -> T) + f: |&mut Self| -> T) -> T; // Specialized types: - fn read_option(&mut self, f: &fn(&mut Self, bool) -> T) -> T; + fn read_option(&mut self, f: |&mut Self, bool| -> T) -> T; - fn read_seq(&mut self, f: &fn(&mut Self, uint) -> T) -> T; - fn read_seq_elt(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; + fn read_seq(&mut self, f: |&mut Self, uint| -> T) -> T; + fn read_seq_elt(&mut self, idx: uint, f: |&mut Self| -> T) -> T; - fn read_map(&mut self, f: &fn(&mut Self, uint) -> T) -> T; - fn read_map_elt_key(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; - fn read_map_elt_val(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; + fn read_map(&mut self, f: |&mut Self, uint| -> T) -> T; + fn read_map_elt_key(&mut self, idx: uint, f: |&mut Self| -> T) -> T; + fn read_map_elt_val(&mut self, idx: uint, f: |&mut Self| -> T) -> T; } pub trait Encodable { @@ -892,11 +889,11 @@ impl< // In some cases, these should eventually be coded as traits. pub trait EncoderHelpers { - fn emit_from_vec(&mut self, v: &[T], f: &fn(&mut Self, v: &T)); + fn emit_from_vec(&mut self, v: &[T], f: |&mut Self, v: &T|); } impl EncoderHelpers for S { - fn emit_from_vec(&mut self, v: &[T], f: &fn(&mut S, &T)) { + fn emit_from_vec(&mut self, v: &[T], f: |&mut S, &T|) { do self.emit_seq(v.len()) |this| { for (i, e) in v.iter().enumerate() { do this.emit_seq_elt(i) |this| { @@ -908,11 +905,11 @@ impl EncoderHelpers for S { } pub trait DecoderHelpers { - fn read_to_vec(&mut self, f: &fn(&mut Self) -> T) -> ~[T]; + fn read_to_vec(&mut self, f: |&mut Self| -> T) -> ~[T]; } impl DecoderHelpers for D { - fn read_to_vec(&mut self, f: &fn(&mut D) -> T) -> ~[T] { + fn read_to_vec(&mut self, f: |&mut D| -> T) -> ~[T] { do self.read_seq |this, len| { do vec::from_fn(len) |i| { this.read_seq_elt(i, |this| f(this)) diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 0ca0ff66039..119988735a7 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -164,8 +164,11 @@ impl SmallIntMap { } impl SmallIntMap { - pub fn update_with_key(&mut self, key: uint, val: V, - ff: &fn(uint, V, V) -> V) -> bool { + pub fn update_with_key(&mut self, + key: uint, + val: V, + ff: |uint, V, V| -> V) + -> bool { let new_val = match self.find(&key) { None => val, Some(orig) => ff(key, (*orig).clone(), val) @@ -173,8 +176,7 @@ impl SmallIntMap { self.insert(key, new_val) } - pub fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) - -> bool { + pub fn update(&mut self, key: uint, newval: V, ff: |V, V| -> V) -> bool { self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)) } } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 1988da2b0ba..f01eb7ef2af 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -133,7 +133,7 @@ impl Sem { } } - pub fn access(&self, blk: &fn() -> U) -> U { + pub fn access(&self, blk: || -> U) -> U { do task::unkillable { do (|| { self.acquire(); @@ -305,8 +305,12 @@ impl<'self> Condvar<'self> { // something else next on success. #[inline] #[doc(hidden)] -fn check_cvar_bounds(out_of_bounds: Option, id: uint, act: &str, - blk: &fn() -> U) -> U { +fn check_cvar_bounds( + out_of_bounds: Option, + id: uint, + act: &str, + blk: || -> U) + -> U { match out_of_bounds { Some(0) => fail!("{} with illegal ID {} - this lock has no condvars!", act, id), @@ -320,7 +324,7 @@ fn check_cvar_bounds(out_of_bounds: Option, id: uint, act: &str, impl Sem<~[WaitQueue]> { // The only other places that condvars get built are rwlock.write_cond() // and rwlock_write_mode. - pub fn access_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn access_cond(&self, blk: |c: &Condvar| -> U) -> U { do self.access { blk(&Condvar { sem: self, order: Nothing, token: NonCopyable::new() }) } @@ -361,7 +365,7 @@ impl Semaphore { pub fn release(&self) { (&self.sem).release() } /// Run a function with ownership of one of the semaphore's resources. - pub fn access(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) } + pub fn access(&self, blk: || -> U) -> U { (&self.sem).access(blk) } } /**************************************************************************** @@ -399,12 +403,12 @@ impl Mutex { /// Run a function with ownership of the mutex. - pub fn lock(&self, blk: &fn() -> U) -> U { + pub fn lock(&self, blk: || -> U) -> U { (&self.sem).access(blk) } /// Run a function with ownership of the mutex and a handle to a condvar. - pub fn lock_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn lock_cond(&self, blk: |c: &Condvar| -> U) -> U { (&self.sem).access_cond(blk) } } @@ -478,7 +482,7 @@ impl RWLock { * Run a function with the rwlock in read mode. Calls to 'read' from other * tasks may run concurrently with this one. */ - pub fn read(&self, blk: &fn() -> U) -> U { + pub fn read(&self, blk: || -> U) -> U { unsafe { do task::unkillable { do (&self.order_lock).access { @@ -513,7 +517,7 @@ impl RWLock { * Run a function with the rwlock in write mode. No calls to 'read' or * 'write' from other tasks will run concurrently with this one. */ - pub fn write(&self, blk: &fn() -> U) -> U { + pub fn write(&self, blk: || -> U) -> U { do task::unkillable { (&self.order_lock).acquire(); do (&self.access_lock).access { @@ -531,7 +535,7 @@ impl RWLock { * the waiting task is signalled. (Note: a writer that waited and then * was signalled might reacquire the lock before other waiting writers.) */ - pub fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn write_cond(&self, blk: |c: &Condvar| -> U) -> U { // It's important to thread our order lock into the condvar, so that // when a cond.wait() wakes up, it uses it while reacquiring the // access lock. If we permitted a waking-up writer to "cut in line", @@ -592,7 +596,7 @@ impl RWLock { * } * ``` */ - pub fn write_downgrade(&self, blk: &fn(v: RWLockWriteMode) -> U) -> U { + pub fn write_downgrade(&self, blk: |v: RWLockWriteMode| -> U) -> U { // Implementation slightly different from the slicker 'write's above. // The exit path is conditional on whether the caller downgrades. do task::unkillable { @@ -671,9 +675,9 @@ pub struct RWLockReadMode<'self> { priv lock: &'self RWLock, impl<'self> RWLockWriteMode<'self> { /// Access the pre-downgrade rwlock in write mode. - pub fn write(&self, blk: &fn() -> U) -> U { blk() } + pub fn write(&self, blk: || -> U) -> U { blk() } /// Access the pre-downgrade rwlock in write mode with a condvar. - pub fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn write_cond(&self, blk: |c: &Condvar| -> U) -> U { // Need to make the condvar use the order lock when reacquiring the // access lock. See comment in RWLock::write_cond for why. blk(&Condvar { sem: &self.lock.access_lock, @@ -684,7 +688,7 @@ impl<'self> RWLockWriteMode<'self> { impl<'self> RWLockReadMode<'self> { /// Access the post-downgrade rwlock in read mode. - pub fn read(&self, blk: &fn() -> U) -> U { blk() } + pub fn read(&self, blk: || -> U) -> U { blk() } } /**************************************************************************** @@ -1060,7 +1064,7 @@ mod tests { #[cfg(test)] pub enum RWLockMode { Read, Write, Downgrade, DowngradeRead } #[cfg(test)] - fn lock_rwlock_in_mode(x: &RWLock, mode: RWLockMode, blk: &fn()) { + fn lock_rwlock_in_mode(x: &RWLock, mode: RWLockMode, blk: ||) { match mode { Read => x.read(blk), Write => x.write(blk), @@ -1221,7 +1225,7 @@ mod tests { dg1: bool, dg2: bool) { // Much like the mutex broadcast test. Downgrade-enabled. - fn lock_cond(x: &RWLock, downgrade: bool, blk: &fn(c: &Condvar)) { + fn lock_cond(x: &RWLock, downgrade: bool, blk: |c: &Condvar|) { if downgrade { do x.write_downgrade |mode| { do mode.write_cond |c| { blk(c) } diff --git a/src/libextra/task_pool.rs b/src/libextra/task_pool.rs index 64fb954764a..37deba43e3a 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -49,7 +49,7 @@ impl TaskPool { /// local data to be kept around in that task. pub fn new(n_tasks: uint, opt_sched_mode: Option, - init_fn_factory: &fn() -> proc(uint) -> T) + init_fn_factory: || -> proc(uint) -> T) -> TaskPool { assert!(n_tasks >= 1); @@ -97,7 +97,7 @@ impl TaskPool { #[test] fn test_task_pool() { - let f: &fn() -> proc(uint) -> uint = || { + let f: || -> proc(uint) -> uint = || { let g: proc(uint) -> uint = |i| i; g }; diff --git a/src/libextra/test.rs b/src/libextra/test.rs index acb3d538c98..e9f38471d48 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -715,8 +715,7 @@ type MonitorMsg = (TestDesc, TestResult); fn run_tests(opts: &TestOpts, tests: ~[TestDescAndFn], - callback: &fn(e: TestEvent)) { - + callback: |e: TestEvent|) { let filtered_tests = filter_tests(opts, tests); let filtered_descs = filtered_tests.map(|t| t.desc.clone()); @@ -1058,7 +1057,7 @@ impl MetricMap { impl BenchHarness { /// Callback for benchmark functions to run in their body. - pub fn iter(&mut self, inner:&fn()) { + pub fn iter(&mut self, inner: ||) { self.ns_start = precise_time_ns(); let k = self.iterations; for _ in range(0u64, k) { @@ -1083,7 +1082,7 @@ impl BenchHarness { } } - pub fn bench_n(&mut self, n: u64, f: &fn(&mut BenchHarness)) { + pub fn bench_n(&mut self, n: u64, f: |&mut BenchHarness|) { self.iterations = n; debug!("running benchmark for {} iterations", n as uint); @@ -1091,7 +1090,7 @@ impl BenchHarness { } // This is a more statistics-driven benchmark algorithm - pub fn auto_bench(&mut self, f: &fn(&mut BenchHarness)) -> stats::Summary { + pub fn auto_bench(&mut self, f: |&mut BenchHarness|) -> stats::Summary { // Initial bench run to get ballpark figure. let mut n = 1_u64; @@ -1161,8 +1160,7 @@ impl BenchHarness { pub mod bench { use test::{BenchHarness, BenchSamples}; - pub fn benchmark(f: &fn(&mut BenchHarness)) -> BenchSamples { - + pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples { let mut bs = BenchHarness { iterations: 0, ns_start: 0, diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index db5b12f021e..a19f501010e 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -136,7 +136,7 @@ impl TreeMap { pub fn new() -> TreeMap { TreeMap{root: None, length: 0} } /// Iterate over the map and mutate the contained values - pub fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool) -> bool { + pub fn mutate_values(&mut self, f: |&K, &mut V| -> bool) -> bool { mutate_values(&mut self.root, f) } @@ -678,9 +678,12 @@ impl TreeNode { } } -fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, - f: &fn(&'r K, &'r mut V) -> bool) - -> bool { +fn mutate_values<'r, + K:TotalOrd, + V>( + node: &'r mut Option<~TreeNode>, + f: |&'r K, &'r mut V| -> bool) + -> bool { match *node { Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left, right: ref mut right, _}) => { @@ -1400,8 +1403,10 @@ mod test_set { } } - fn check(a: &[int], b: &[int], expected: &[int], - f: &fn(&TreeSet, &TreeSet, f: &fn(&int) -> bool) -> bool) { + fn check(a: &[int], + b: &[int], + expected: &[int], + f: |&TreeSet, &TreeSet, f: |&int| -> bool| -> bool) { let mut set_a = TreeSet::new(); let mut set_b = TreeSet::new(); diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 7ea7b513f4b..09f95800b3d 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -295,7 +295,12 @@ impl Context { Prep::new(self, fn_name) } - pub fn with_prep<'a, T>(&'a self, fn_name: &'a str, blk: &fn(p: &mut Prep) -> T) -> T { + pub fn with_prep<'a, + T>( + &'a self, + fn_name: &'a str, + blk: |p: &mut Prep| -> T) + -> T { let mut p = self.prep(fn_name); blk(&mut p) }