1
Fork 0

libextra: Convert uses of &fn(A)->B to |A|->B.

This commit is contained in:
Patrick Walton 2013-11-18 21:54:13 -08:00
parent 1946265e1a
commit 18a30aff45
16 changed files with 224 additions and 231 deletions

View file

@ -220,7 +220,7 @@ impl<T:Send> MutexArc<T> {
* blocked on the mutex) will also fail immediately. * blocked on the mutex) will also fail immediately.
*/ */
#[inline] #[inline]
pub unsafe fn unsafe_access<U>(&self, blk: &fn(x: &mut T) -> U) -> U { pub unsafe fn unsafe_access<U>(&self, blk: |x: &mut T| -> U) -> U {
let state = self.x.get(); let state = self.x.get();
// Borrowck would complain about this if the function were // Borrowck would complain about this if the function were
// not already unsafe. See borrow_rwlock, far below. // not already unsafe. See borrow_rwlock, far below.
@ -234,8 +234,7 @@ impl<T:Send> MutexArc<T> {
/// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond(). /// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond().
#[inline] #[inline]
pub unsafe fn unsafe_access_cond<U>(&self, pub unsafe fn unsafe_access_cond<U>(&self,
blk: &fn(x: &mut T, blk: |x: &mut T, c: &Condvar| -> U)
c: &Condvar) -> U)
-> U { -> U {
let state = self.x.get(); let state = self.x.get();
do (&(*state).lock).lock_cond |cond| { do (&(*state).lock).lock_cond |cond| {
@ -284,15 +283,14 @@ impl<T:Freeze + Send> MutexArc<T> {
* unsafe_access_cond. * unsafe_access_cond.
*/ */
#[inline] #[inline]
pub fn access<U>(&self, blk: &fn(x: &mut T) -> U) -> U { pub fn access<U>(&self, blk: |x: &mut T| -> U) -> U {
unsafe { self.unsafe_access(blk) } unsafe { self.unsafe_access(blk) }
} }
/// As unsafe_access_cond but safe and Freeze. /// As unsafe_access_cond but safe and Freeze.
#[inline] #[inline]
pub fn access_cond<U>(&self, pub fn access_cond<U>(&self,
blk: &fn(x: &mut T, blk: |x: &mut T, c: &Condvar| -> U)
c: &Condvar) -> U)
-> U { -> U {
unsafe { self.unsafe_access_cond(blk) } unsafe { self.unsafe_access_cond(blk) }
} }
@ -389,7 +387,7 @@ impl<T:Freeze + Send> RWArc<T> {
* poison the Arc, so subsequent readers and writers will both also fail. * poison the Arc, so subsequent readers and writers will both also fail.
*/ */
#[inline] #[inline]
pub fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U { pub fn write<U>(&self, blk: |x: &mut T| -> U) -> U {
unsafe { unsafe {
let state = self.x.get(); let state = self.x.get();
do (*borrow_rwlock(state)).write { do (*borrow_rwlock(state)).write {
@ -403,7 +401,7 @@ impl<T:Freeze + Send> RWArc<T> {
/// As write(), but with a condvar, as sync::rwlock.write_cond(). /// As write(), but with a condvar, as sync::rwlock.write_cond().
#[inline] #[inline]
pub fn write_cond<U>(&self, pub fn write_cond<U>(&self,
blk: &fn(x: &mut T, c: &Condvar) -> U) blk: |x: &mut T, c: &Condvar| -> U)
-> U { -> U {
unsafe { unsafe {
let state = self.x.get(); let state = self.x.get();
@ -427,7 +425,7 @@ impl<T:Freeze + Send> RWArc<T> {
* Failing will unlock the Arc while unwinding. However, unlike all other * Failing will unlock the Arc while unwinding. However, unlike all other
* access modes, this will not poison the Arc. * access modes, this will not poison the Arc.
*/ */
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U { pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
unsafe { unsafe {
let state = self.x.get(); let state = self.x.get();
do (*state).lock.read { do (*state).lock.read {
@ -457,7 +455,7 @@ impl<T:Freeze + Send> RWArc<T> {
* } * }
* ``` * ```
*/ */
pub fn write_downgrade<U>(&self, blk: &fn(v: RWWriteMode<T>) -> U) -> U { pub fn write_downgrade<U>(&self, blk: |v: RWWriteMode<T>| -> U) -> U {
unsafe { unsafe {
let state = self.x.get(); let state = self.x.get();
do (*borrow_rwlock(state)).write_downgrade |write_mode| { 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> { impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
/// Access the pre-downgrade RWArc in write mode. /// Access the pre-downgrade RWArc in write mode.
pub fn write<U>(&mut self, blk: &fn(x: &mut T) -> U) -> U { pub fn write<U>(&mut self, blk: |x: &mut T| -> U) -> U {
match *self { match *self {
RWWriteMode { RWWriteMode {
data: &ref mut data, 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. /// Access the pre-downgrade RWArc in write mode with a condvar.
pub fn write_cond<U>(&mut self, pub fn write_cond<U>(&mut self,
blk: &fn(x: &mut T, c: &Condvar) -> U) blk: |x: &mut T, c: &Condvar| -> U)
-> U { -> U {
match *self { match *self {
RWWriteMode { RWWriteMode {
@ -580,7 +578,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
impl<'self, T:Freeze + Send> RWReadMode<'self, T> { impl<'self, T:Freeze + Send> RWReadMode<'self, T> {
/// Access the post-downgrade rwlock in read mode. /// Access the post-downgrade rwlock in read mode.
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U { pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
match *self { match *self {
RWReadMode { RWReadMode {
data: data, data: data,

View file

@ -184,7 +184,7 @@ impl Arena {
} }
#[inline] #[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 { unsafe {
let tydesc = get_tydesc::<T>(); let tydesc = get_tydesc::<T>();
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align); let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
@ -241,7 +241,7 @@ impl Arena {
} }
#[inline] #[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 { unsafe {
let tydesc = get_tydesc::<T>(); let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) = let (ty_ptr, ptr) =
@ -263,7 +263,7 @@ impl Arena {
// The external interface // The external interface
#[inline] #[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 { unsafe {
// XXX: Borrow check // XXX: Borrow check
let this = transmute_mut(self); let this = transmute_mut(self);

View file

@ -40,7 +40,7 @@ impl SmallBitv {
pub fn bits_op(&mut self, pub fn bits_op(&mut self,
right_bits: uint, right_bits: uint,
nbits: uint, nbits: uint,
f: &fn(uint, uint) -> uint) f: |uint, uint| -> uint)
-> bool { -> bool {
let mask = small_mask(nbits); let mask = small_mask(nbits);
let old_b: uint = self.bits; let old_b: uint = self.bits;
@ -140,7 +140,7 @@ impl BigBitv {
pub fn process(&mut self, pub fn process(&mut self,
b: &BigBitv, b: &BigBitv,
nbits: uint, nbits: uint,
op: &fn(uint, uint) -> uint) op: |uint, uint| -> uint)
-> bool { -> bool {
let len = b.storage.len(); let len = b.storage.len();
assert_eq!(self.storage.len(), len); assert_eq!(self.storage.len(), len);
@ -161,7 +161,7 @@ impl BigBitv {
} }
#[inline] #[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)) self.storage.mut_iter().advance(|elt| op(elt))
} }
@ -512,7 +512,7 @@ impl Bitv {
true 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)) 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 * Create a `Bitv` of the specified length where the value at each
* index is `f(index)`. * 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); let mut bitv = Bitv::new(len, false);
for i in range(0u, len) { for i in range(0u, len) {
bitv.set(i, f(i)); bitv.set(i, f(i));
@ -557,7 +557,7 @@ impl ops::Index<uint,bool> for Bitv {
} }
#[inline] #[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 { if bits == 0 {
return true; return true;
} }
@ -675,7 +675,7 @@ impl BitvSet {
} }
#[inline] #[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 { fn nbits(mut w: uint) -> uint {
let mut bits = 0; let mut bits = 0;
for _ in range(0u, uint::bits) { for _ in range(0u, uint::bits) {
@ -722,7 +722,7 @@ impl BitvSet {
BitvSetIterator {set: self, next_idx: 0} 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) { for (i, w1, w2) in self.common_iter(other) {
if !iterate_bits(i, w1 & !w2, |b| f(&b)) { if !iterate_bits(i, w1 & !w2, |b| f(&b)) {
return false return false
@ -734,8 +734,8 @@ impl BitvSet {
) )
} }
pub fn symmetric_difference(&self, other: &BitvSet, pub fn symmetric_difference(&self, other: &BitvSet, f: |&uint| -> bool)
f: &fn(&uint) -> bool) -> bool { -> bool {
for (i, w1, w2) in self.common_iter(other) { for (i, w1, w2) in self.common_iter(other) {
if !iterate_bits(i, w1 ^ w2, |b| f(&b)) { if !iterate_bits(i, w1 ^ w2, |b| f(&b)) {
return false return false
@ -744,11 +744,11 @@ impl BitvSet {
self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b))) 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))) 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) { for (i, w1, w2) in self.common_iter(other) {
if !iterate_bits(i, w1 | w2, |b| f(&b)) { if !iterate_bits(i, w1 | w2, |b| f(&b)) {
return false return false

View file

@ -320,7 +320,7 @@ impl<T> DList<T> {
/// or at the end. /// or at the end.
/// ///
/// O(N) /// 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(); let mut it = self.mut_iter();
loop { loop {
@ -339,7 +339,7 @@ impl<T> DList<T> {
/// put `a` in the result if `f(a, b)` is true, else `b`. /// put `a` in the result if `f(a, b)` is true, else `b`.
/// ///
/// O(max(N, M)) /// O(max(N, M))
pub fn merge(&mut self, mut other: DList<T>, f: &fn(&T, &T) -> bool) { pub fn merge(&mut self, mut other: DList<T>, f: |&T, &T| -> bool) {
{ {
let mut it = self.mut_iter(); let mut it = self.mut_iter();
loop { loop {

View file

@ -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; let mut pos = d.start;
while pos < d.end { while pos < d.end {
let elt_tag = vuint_at(*d.data, pos); let elt_tag = vuint_at(*d.data, pos);
@ -230,7 +230,7 @@ pub mod reader {
return true; 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; let mut pos = d.start;
while pos < d.end { while pos < d.end {
let elt_tag = vuint_at(*d.data, pos); let elt_tag = vuint_at(*d.data, pos);
@ -247,7 +247,7 @@ pub mod reader {
return true; return true;
} }
pub fn with_doc_data<T>(d: Doc, f: &fn(x: &[u8]) -> T) -> T { pub fn with_doc_data<T>(d: Doc, f: |x: &[u8]| -> T) -> T {
f(d.data.slice(d.start, d.end)) f(d.data.slice(d.start, d.end))
} }
@ -332,7 +332,7 @@ pub mod reader {
} }
fn push_doc<T>(&mut self, exp_tag: EbmlEncoderTag, fn push_doc<T>(&mut self, exp_tag: EbmlEncoderTag,
f: &fn(&mut Decoder) -> T) -> T { f: |&mut Decoder| -> T) -> T {
let d = self.next_doc(exp_tag); let d = self.next_doc(exp_tag);
let old_parent = self.parent; let old_parent = self.parent;
let old_pos = self.pos; let old_pos = self.pos;
@ -352,8 +352,7 @@ pub mod reader {
} }
impl Decoder { impl Decoder {
pub fn read_opaque<R>(&mut self, op: &fn(&mut Decoder, Doc) -> R) pub fn read_opaque<R>(&mut self, op: |&mut Decoder, Doc| -> R) -> R {
-> R {
let doc = self.next_doc(EsOpaque); let doc = self.next_doc(EsOpaque);
let (old_parent, old_pos) = (self.parent, self.pos); let (old_parent, old_pos) = (self.parent, self.pos);
@ -424,10 +423,7 @@ pub mod reader {
} }
// Compound types: // Compound types:
fn read_enum<T>(&mut self, fn read_enum<T>(&mut self, name: &str, f: |&mut Decoder| -> T) -> T {
name: &str,
f: &fn(&mut Decoder) -> T)
-> T {
debug!("read_enum({})", name); debug!("read_enum({})", name);
self._check_label(name); self._check_label(name);
@ -446,7 +442,7 @@ pub mod reader {
fn read_enum_variant<T>(&mut self, fn read_enum_variant<T>(&mut self,
_: &[&str], _: &[&str],
f: &fn(&mut Decoder, uint) -> T) f: |&mut Decoder, uint| -> T)
-> T { -> T {
debug!("read_enum_variant()"); debug!("read_enum_variant()");
let idx = self._next_uint(EsEnumVid); let idx = self._next_uint(EsEnumVid);
@ -467,14 +463,14 @@ pub mod reader {
fn read_enum_variant_arg<T>(&mut self, fn read_enum_variant_arg<T>(&mut self,
idx: uint, idx: uint,
f: &fn(&mut Decoder) -> T) -> T { f: |&mut Decoder| -> T) -> T {
debug!("read_enum_variant_arg(idx={})", idx); debug!("read_enum_variant_arg(idx={})", idx);
f(self) f(self)
} }
fn read_enum_struct_variant<T>(&mut self, fn read_enum_struct_variant<T>(&mut self,
_: &[&str], _: &[&str],
f: &fn(&mut Decoder, uint) -> T) f: |&mut Decoder, uint| -> T)
-> T { -> T {
debug!("read_enum_struct_variant()"); debug!("read_enum_struct_variant()");
let idx = self._next_uint(EsEnumVid); let idx = self._next_uint(EsEnumVid);
@ -496,7 +492,7 @@ pub mod reader {
fn read_enum_struct_variant_field<T>(&mut self, fn read_enum_struct_variant_field<T>(&mut self,
name: &str, name: &str,
idx: uint, idx: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx); debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx);
f(self) f(self)
@ -505,7 +501,7 @@ pub mod reader {
fn read_struct<T>(&mut self, fn read_struct<T>(&mut self,
name: &str, name: &str,
_: uint, _: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_struct(name={})", name); debug!("read_struct(name={})", name);
f(self) f(self)
@ -514,19 +510,19 @@ pub mod reader {
fn read_struct_field<T>(&mut self, fn read_struct_field<T>(&mut self,
name: &str, name: &str,
idx: uint, idx: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_struct_field(name={}, idx={})", name, idx); debug!("read_struct_field(name={}, idx={})", name, idx);
self._check_label(name); self._check_label(name);
f(self) f(self)
} }
fn read_tuple<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { fn read_tuple<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
debug!("read_tuple()"); debug!("read_tuple()");
self.read_seq(f) self.read_seq(f)
} }
fn read_tuple_arg<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) fn read_tuple_arg<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_tuple_arg(idx={})", idx); debug!("read_tuple_arg(idx={})", idx);
self.read_seq_elt(idx, f) self.read_seq_elt(idx, f)
@ -534,7 +530,7 @@ pub mod reader {
fn read_tuple_struct<T>(&mut self, fn read_tuple_struct<T>(&mut self,
name: &str, name: &str,
f: &fn(&mut Decoder, uint) -> T) f: |&mut Decoder, uint| -> T)
-> T { -> T {
debug!("read_tuple_struct(name={})", name); debug!("read_tuple_struct(name={})", name);
self.read_tuple(f) self.read_tuple(f)
@ -542,13 +538,13 @@ pub mod reader {
fn read_tuple_struct_arg<T>(&mut self, fn read_tuple_struct_arg<T>(&mut self,
idx: uint, idx: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_tuple_struct_arg(idx={})", idx); debug!("read_tuple_struct_arg(idx={})", idx);
self.read_tuple_arg(idx, f) self.read_tuple_arg(idx, f)
} }
fn read_option<T>(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T { fn read_option<T>(&mut self, f: |&mut Decoder, bool| -> T) -> T {
debug!("read_option()"); debug!("read_option()");
do self.read_enum("Option") |this| { do self.read_enum("Option") |this| {
do this.read_enum_variant(["None", "Some"]) |this, idx| { do this.read_enum_variant(["None", "Some"]) |this, idx| {
@ -561,7 +557,7 @@ pub mod reader {
} }
} }
fn read_seq<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { fn read_seq<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
debug!("read_seq()"); debug!("read_seq()");
do self.push_doc(EsVec) |d| { do self.push_doc(EsVec) |d| {
let len = d._next_uint(EsVecLen); let len = d._next_uint(EsVecLen);
@ -570,13 +566,13 @@ pub mod reader {
} }
} }
fn read_seq_elt<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_seq_elt(idx={})", idx); debug!("read_seq_elt(idx={})", idx);
self.push_doc(EsVecElt, f) self.push_doc(EsVecElt, f)
} }
fn read_map<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { fn read_map<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
debug!("read_map()"); debug!("read_map()");
do self.push_doc(EsMap) |d| { do self.push_doc(EsMap) |d| {
let len = d._next_uint(EsMapLen); let len = d._next_uint(EsMapLen);
@ -585,17 +581,13 @@ pub mod reader {
} }
} }
fn read_map_elt_key<T>(&mut self, fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
idx: uint,
f: &fn(&mut Decoder) -> T)
-> T { -> T {
debug!("read_map_elt_key(idx={})", idx); debug!("read_map_elt_key(idx={})", idx);
self.push_doc(EsMapKey, f) self.push_doc(EsMapKey, f)
} }
fn read_map_elt_val<T>(&mut self, fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
idx: uint,
f: &fn(&mut Decoder) -> T)
-> T { -> T {
debug!("read_map_elt_val(idx={})", idx); debug!("read_map_elt_val(idx={})", idx);
self.push_doc(EsMapVal, f) self.push_doc(EsMapVal, f)
@ -682,7 +674,7 @@ pub mod writer {
debug!("End tag (size = {})", size); 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); self.start_tag(tag_id);
blk(); blk();
self.end_tag(); self.end_tag();
@ -779,7 +771,7 @@ pub mod writer {
} }
impl Encoder { 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); self.start_tag(EsOpaque as uint);
f(self); f(self);
self.end_tag(); self.end_tag();
@ -841,7 +833,7 @@ pub mod writer {
self.wr_tagged_str(EsStr as uint, v) 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._emit_label(name);
self.start_tag(EsEnum as uint); self.start_tag(EsEnum as uint);
f(self); f(self);
@ -852,14 +844,14 @@ pub mod writer {
_: &str, _: &str,
v_id: uint, v_id: uint,
_: uint, _: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self._emit_tagged_uint(EsEnumVid, v_id); self._emit_tagged_uint(EsEnumVid, v_id);
self.start_tag(EsEnumBody as uint); self.start_tag(EsEnumBody as uint);
f(self); f(self);
self.end_tag(); 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) f(self)
} }
@ -867,83 +859,83 @@ pub mod writer {
v_name: &str, v_name: &str,
v_id: uint, v_id: uint,
cnt: uint, cnt: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self.emit_enum_variant(v_name, v_id, cnt, f) self.emit_enum_variant(v_name, v_id, cnt, f)
} }
fn emit_enum_struct_variant_field(&mut self, fn emit_enum_struct_variant_field(&mut self,
_: &str, _: &str,
idx: uint, idx: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self.emit_enum_variant_arg(idx, f) 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) f(self)
} }
fn emit_struct_field(&mut self, fn emit_struct_field(&mut self,
name: &str, name: &str,
_: uint, _: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self._emit_label(name); self._emit_label(name);
f(self) 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) 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) self.emit_seq_elt(idx, f)
} }
fn emit_tuple_struct(&mut self, fn emit_tuple_struct(&mut self,
_: &str, _: &str,
len: uint, len: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self.emit_seq(len, f) 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) 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); self.emit_enum("Option", f);
} }
fn emit_option_none(&mut self) { fn emit_option_none(&mut self) {
self.emit_enum_variant("None", 0, 0, |_| ()) 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) 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.start_tag(EsVec as uint);
self._emit_tagged_uint(EsVecLen, len); self._emit_tagged_uint(EsVecLen, len);
f(self); f(self);
self.end_tag(); 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); self.start_tag(EsVecElt as uint);
f(self); f(self);
self.end_tag(); 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.start_tag(EsMap as uint);
self._emit_tagged_uint(EsMapLen, len); self._emit_tagged_uint(EsMapLen, len);
f(self); f(self);
self.end_tag(); 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); self.start_tag(EsMapKey as uint);
f(self); f(self);
self.end_tag(); 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); self.start_tag(EsMapVal as uint);
f(self); f(self);
self.end_tag(); self.end_tag();

View file

@ -768,9 +768,8 @@ pub mod groups {
/// ///
/// Fails during iteration if the string contains a non-whitespace /// Fails during iteration if the string contains a non-whitespace
/// sequence longer than the limit. /// sequence longer than the limit.
fn each_split_within<'a>(ss: &'a str, fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
lim: uint, -> bool {
it: &fn(&'a str) -> bool) -> bool {
// Just for fun, let's write this as a state machine: // Just for fun, let's write this as a state machine:
enum SplitWithinState { enum SplitWithinState {
@ -795,14 +794,14 @@ pub mod groups {
let mut lim = lim; let mut lim = lim;
let mut cont = true; 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 the limit is larger than the string, lower it to save cycles
if (lim >= fake_i) { if (lim >= fake_i) {
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 whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr };
let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim }; let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim };

View file

@ -129,13 +129,13 @@ impl serialize::Encoder for Encoder {
write!(self.wr, "{}", escape_str(v)) 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, fn emit_enum_variant(&mut self,
name: &str, name: &str,
_id: uint, _id: uint,
cnt: uint, cnt: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
// enums are encoded as strings or objects // enums are encoded as strings or objects
// Bunny => "Bunny" // Bunny => "Bunny"
// Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]} // 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 { if idx != 0 {
write!(self.wr, ","); write!(self.wr, ",");
} }
@ -161,18 +161,18 @@ impl serialize::Encoder for Encoder {
name: &str, name: &str,
id: uint, id: uint,
cnt: uint, cnt: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self.emit_enum_variant(name, id, cnt, f) self.emit_enum_variant(name, id, cnt, f)
} }
fn emit_enum_struct_variant_field(&mut self, fn emit_enum_struct_variant_field(&mut self,
_: &str, _: &str,
idx: uint, idx: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self.emit_enum_variant_arg(idx, f) 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"\{"); write!(self.wr, r"\{");
f(self); f(self);
write!(self.wr, r"\}"); write!(self.wr, r"\}");
@ -181,58 +181,58 @@ impl serialize::Encoder for Encoder {
fn emit_struct_field(&mut self, fn emit_struct_field(&mut self,
name: &str, name: &str,
idx: uint, idx: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
if idx != 0 { write!(self.wr, ",") } if idx != 0 { write!(self.wr, ",") }
write!(self.wr, "{}:", escape_str(name)); write!(self.wr, "{}:", escape_str(name));
f(self); 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) 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) self.emit_seq_elt(idx, f)
} }
fn emit_tuple_struct(&mut self, fn emit_tuple_struct(&mut self,
_name: &str, _name: &str,
len: uint, len: uint,
f: &fn(&mut Encoder)) { f: |&mut Encoder|) {
self.emit_seq(len, f) 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) 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_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, "["); write!(self.wr, "[");
f(self); f(self);
write!(self.wr, "]"); 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 { if idx != 0 {
write!(self.wr, ","); write!(self.wr, ",");
} }
f(self) 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"\{"); write!(self.wr, r"\{");
f(self); f(self);
write!(self.wr, r"\}"); 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, ",") } if idx != 0 { write!(self.wr, ",") }
f(self) 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, ":"); write!(self.wr, ":");
f(self) 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_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_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) f(self)
} }
@ -292,7 +292,7 @@ impl serialize::Encoder for PrettyEncoder {
name: &str, name: &str,
_: uint, _: uint,
cnt: uint, cnt: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
if cnt == 0 { if cnt == 0 {
write!(self.wr, "{}", escape_str(name)); write!(self.wr, "{}", escape_str(name));
} else { } else {
@ -306,7 +306,7 @@ impl serialize::Encoder for PrettyEncoder {
fn emit_enum_variant_arg(&mut self, fn emit_enum_variant_arg(&mut self,
idx: uint, idx: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
if idx != 0 { if idx != 0 {
write!(self.wr, ",\n"); write!(self.wr, ",\n");
} }
@ -318,14 +318,14 @@ impl serialize::Encoder for PrettyEncoder {
name: &str, name: &str,
id: uint, id: uint,
cnt: uint, cnt: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
self.emit_enum_variant(name, id, cnt, f) self.emit_enum_variant(name, id, cnt, f)
} }
fn emit_enum_struct_variant_field(&mut self, fn emit_enum_struct_variant_field(&mut self,
_: &str, _: &str,
idx: uint, idx: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
self.emit_enum_variant_arg(idx, f) self.emit_enum_variant_arg(idx, f)
} }
@ -333,7 +333,7 @@ impl serialize::Encoder for PrettyEncoder {
fn emit_struct(&mut self, fn emit_struct(&mut self,
_: &str, _: &str,
len: uint, len: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
if len == 0 { if len == 0 {
write!(self.wr, "\\{\\}"); write!(self.wr, "\\{\\}");
} else { } else {
@ -348,7 +348,7 @@ impl serialize::Encoder for PrettyEncoder {
fn emit_struct_field(&mut self, fn emit_struct_field(&mut self,
name: &str, name: &str,
idx: uint, idx: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
if idx == 0 { if idx == 0 {
write!(self.wr, "\n"); write!(self.wr, "\n");
} else { } else {
@ -358,30 +358,30 @@ impl serialize::Encoder for PrettyEncoder {
f(self); 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) 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) self.emit_seq_elt(idx, f)
} }
fn emit_tuple_struct(&mut self, fn emit_tuple_struct(&mut self,
_: &str, _: &str,
len: uint, len: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
self.emit_seq(len, f) self.emit_seq(len, f)
} }
fn emit_tuple_struct_arg(&mut self, fn emit_tuple_struct_arg(&mut self,
idx: uint, idx: uint,
f: &fn(&mut PrettyEncoder)) { f: |&mut PrettyEncoder|) {
self.emit_seq_elt(idx, f) 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_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 { if len == 0 {
write!(self.wr, "[]"); write!(self.wr, "[]");
} else { } 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 { if idx == 0 {
write!(self.wr, "\n"); write!(self.wr, "\n");
} else { } else {
@ -403,7 +403,7 @@ impl serialize::Encoder for PrettyEncoder {
f(self) 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 { if len == 0 {
write!(self.wr, "\\{\\}"); write!(self.wr, "\\{\\}");
} else { } 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 { if idx == 0 {
write!(self.wr, "\n"); write!(self.wr, "\n");
} else { } else {
@ -425,7 +425,7 @@ impl serialize::Encoder for PrettyEncoder {
f(self); 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, ": "); write!(self.wr, ": ");
f(self); f(self);
} }
@ -921,14 +921,14 @@ impl serialize::Decoder for Decoder {
} }
} }
fn read_enum<T>(&mut self, name: &str, f: &fn(&mut Decoder) -> T) -> T { fn read_enum<T>(&mut self, name: &str, f: |&mut Decoder| -> T) -> T {
debug!("read_enum({})", name); debug!("read_enum({})", name);
f(self) f(self)
} }
fn read_enum_variant<T>(&mut self, fn read_enum_variant<T>(&mut self,
names: &[&str], names: &[&str],
f: &fn(&mut Decoder, uint) -> T) f: |&mut Decoder, uint| -> T)
-> T { -> T {
debug!("read_enum_variant(names={:?})", names); debug!("read_enum_variant(names={:?})", names);
let name = match self.stack.pop() { let name = match self.stack.pop() {
@ -957,9 +957,7 @@ impl serialize::Decoder for Decoder {
f(self, idx) f(self, idx)
} }
fn read_enum_variant_arg<T>(&mut self, fn read_enum_variant_arg<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
idx: uint,
f: &fn(&mut Decoder) -> T)
-> T { -> T {
debug!("read_enum_variant_arg(idx={})", idx); debug!("read_enum_variant_arg(idx={})", idx);
f(self) f(self)
@ -967,7 +965,7 @@ impl serialize::Decoder for Decoder {
fn read_enum_struct_variant<T>(&mut self, fn read_enum_struct_variant<T>(&mut self,
names: &[&str], names: &[&str],
f: &fn(&mut Decoder, uint) -> T) f: |&mut Decoder, uint| -> T)
-> T { -> T {
debug!("read_enum_struct_variant(names={:?})", names); debug!("read_enum_struct_variant(names={:?})", names);
self.read_enum_variant(names, f) self.read_enum_variant(names, f)
@ -977,7 +975,7 @@ impl serialize::Decoder for Decoder {
fn read_enum_struct_variant_field<T>(&mut self, fn read_enum_struct_variant_field<T>(&mut self,
name: &str, name: &str,
idx: uint, idx: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_enum_struct_variant_field(name={}, idx={})", name, idx); debug!("read_enum_struct_variant_field(name={}, idx={})", name, idx);
self.read_enum_variant_arg(idx, f) self.read_enum_variant_arg(idx, f)
@ -986,7 +984,7 @@ impl serialize::Decoder for Decoder {
fn read_struct<T>(&mut self, fn read_struct<T>(&mut self,
name: &str, name: &str,
len: uint, len: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_struct(name={}, len={})", name, len); debug!("read_struct(name={}, len={})", name, len);
let value = f(self); let value = f(self);
@ -997,7 +995,7 @@ impl serialize::Decoder for Decoder {
fn read_struct_field<T>(&mut self, fn read_struct_field<T>(&mut self,
name: &str, name: &str,
idx: uint, idx: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_struct_field(name={}, idx={})", name, idx); debug!("read_struct_field(name={}, idx={})", name, idx);
match self.stack.pop() { match self.stack.pop() {
@ -1017,22 +1015,19 @@ impl serialize::Decoder for Decoder {
} }
} }
fn read_tuple<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { fn read_tuple<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
debug!("read_tuple()"); debug!("read_tuple()");
self.read_seq(f) self.read_seq(f)
} }
fn read_tuple_arg<T>(&mut self, fn read_tuple_arg<T>(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T {
idx: uint,
f: &fn(&mut Decoder) -> T)
-> T {
debug!("read_tuple_arg(idx={})", idx); debug!("read_tuple_arg(idx={})", idx);
self.read_seq_elt(idx, f) self.read_seq_elt(idx, f)
} }
fn read_tuple_struct<T>(&mut self, fn read_tuple_struct<T>(&mut self,
name: &str, name: &str,
f: &fn(&mut Decoder, uint) -> T) f: |&mut Decoder, uint| -> T)
-> T { -> T {
debug!("read_tuple_struct(name={})", name); debug!("read_tuple_struct(name={})", name);
self.read_tuple(f) self.read_tuple(f)
@ -1040,20 +1035,20 @@ impl serialize::Decoder for Decoder {
fn read_tuple_struct_arg<T>(&mut self, fn read_tuple_struct_arg<T>(&mut self,
idx: uint, idx: uint,
f: &fn(&mut Decoder) -> T) f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_tuple_struct_arg(idx={})", idx); debug!("read_tuple_struct_arg(idx={})", idx);
self.read_tuple_arg(idx, f) self.read_tuple_arg(idx, f)
} }
fn read_option<T>(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T { fn read_option<T>(&mut self, f: |&mut Decoder, bool| -> T) -> T {
match self.stack.pop() { match self.stack.pop() {
Null => f(self, false), Null => f(self, false),
value => { self.stack.push(value); f(self, true) } value => { self.stack.push(value); f(self, true) }
} }
} }
fn read_seq<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { fn read_seq<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
debug!("read_seq()"); debug!("read_seq()");
let len = match self.stack.pop() { let len = match self.stack.pop() {
List(list) => { List(list) => {
@ -1068,12 +1063,12 @@ impl serialize::Decoder for Decoder {
f(self, len) f(self, len)
} }
fn read_seq_elt<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) -> T { fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Decoder| -> T) -> T {
debug!("read_seq_elt(idx={})", idx); debug!("read_seq_elt(idx={})", idx);
f(self) f(self)
} }
fn read_map<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T { fn read_map<T>(&mut self, f: |&mut Decoder, uint| -> T) -> T {
debug!("read_map()"); debug!("read_map()");
let len = match self.stack.pop() { let len = match self.stack.pop() {
Object(obj) => { Object(obj) => {
@ -1089,15 +1084,13 @@ impl serialize::Decoder for Decoder {
f(self, len) f(self, len)
} }
fn read_map_elt_key<T>(&mut self, fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
idx: uint,
f: &fn(&mut Decoder) -> T)
-> T { -> T {
debug!("read_map_elt_key(idx={})", idx); debug!("read_map_elt_key(idx={})", idx);
f(self) f(self)
} }
fn read_map_elt_val<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
-> T { -> T {
debug!("read_map_elt_val(idx={})", idx); debug!("read_map_elt_val(idx={})", idx);
f(self) f(self)
@ -1482,7 +1475,7 @@ mod tests {
assert_eq!(a.clone(), from_str(a.to_pretty_str()).unwrap()); 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::mem::MemWriter;
use std::io::Decorator; use std::io::Decorator;
use std::str; use std::str;

View file

@ -44,7 +44,7 @@ pub fn from_vec<T:Clone + 'static>(v: &[T]) -> @List<T> {
* * z - The initial value * * z - The initial value
* * f - The function to apply * * f - The function to apply
*/ */
pub fn foldl<T:Clone,U>(z: T, ls: @List<U>, f: &fn(&T, &U) -> T) -> T { pub fn foldl<T:Clone,U>(z: T, ls: @List<U>, f: |&T, &U| -> T) -> T {
let mut accum: T = z; let mut accum: T = z;
do iter(ls) |elt| { accum = f(&accum, elt);} do iter(ls) |elt| { accum = f(&accum, elt);}
accum accum
@ -57,7 +57,7 @@ pub fn foldl<T:Clone,U>(z: T, ls: @List<U>, f: &fn(&T, &U) -> T) -> T {
* When function `f` returns true then an option containing the element * When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned. * is returned. If `f` matches no elements then none is returned.
*/ */
pub fn find<T:Clone>(ls: @List<T>, f: &fn(&T) -> bool) -> Option<T> { pub fn find<T:Clone>(ls: @List<T>, f: |&T| -> bool) -> Option<T> {
let mut ls = ls; let mut ls = ls;
loop { loop {
ls = match *ls { ls = match *ls {
@ -131,7 +131,7 @@ fn push<T:Clone>(ll: &mut @list<T>, vv: T) {
*/ */
/// Iterate over a list /// Iterate over a list
pub fn iter<T>(l: @List<T>, f: &fn(&T)) { pub fn iter<T>(l: @List<T>, f: |&T|) {
let mut cur = l; let mut cur = l;
loop { loop {
cur = match *cur { cur = match *cur {
@ -145,7 +145,7 @@ pub fn iter<T>(l: @List<T>, f: &fn(&T)) {
} }
/// Iterate over a list /// Iterate over a list
pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) -> bool { pub fn each<T>(l: @List<T>, f: |&T| -> bool) -> bool {
let mut cur = l; let mut cur = l;
loop { loop {
cur = match *cur { cur = match *cur {
@ -160,7 +160,7 @@ pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) -> bool {
impl<T> MutList<T> { impl<T> MutList<T> {
/// Iterate over a mutable list /// 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; let mut cur = self;
loop { loop {
let borrowed = &mut *cur; let borrowed = &mut *cur;

View file

@ -145,8 +145,8 @@ condition! {
bad_parse: () -> (); bad_parse: () -> ();
} }
fn take_nonempty_prefix<T: Iterator<char>>(rdr: &mut T, fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
pred: &fn(char) -> bool) -> (~str, Option<char>) { -> (~str, Option<char>) {
let mut buf = ~""; let mut buf = ~"";
let mut ch = rdr.next(); let mut ch = rdr.next();
loop { loop {

View file

@ -47,48 +47,48 @@ pub trait Encoder {
fn emit_str(&mut self, v: &str); fn emit_str(&mut self, v: &str);
// Compound types: // 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, fn emit_enum_variant(&mut self,
v_name: &str, v_name: &str,
v_id: uint, v_id: uint,
len: uint, len: uint,
f: &fn(&mut Self)); f: |&mut Self|);
fn emit_enum_variant_arg(&mut self, a_idx: uint, f: &fn(&mut Self)); fn emit_enum_variant_arg(&mut self, a_idx: uint, f: |&mut Self|);
fn emit_enum_struct_variant(&mut self, fn emit_enum_struct_variant(&mut self,
v_name: &str, v_name: &str,
v_id: uint, v_id: uint,
len: uint, len: uint,
f: &fn(&mut Self)); f: |&mut Self|);
fn emit_enum_struct_variant_field(&mut self, fn emit_enum_struct_variant_field(&mut self,
f_name: &str, f_name: &str,
f_idx: uint, 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, fn emit_struct_field(&mut self,
f_name: &str, f_name: &str,
f_idx: uint, f_idx: uint,
f: &fn(&mut Self)); f: |&mut Self|);
fn emit_tuple(&mut self, len: uint, f: &fn(&mut Self)); fn emit_tuple(&mut self, len: uint, f: |&mut Self|);
fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&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(&mut self, name: &str, len: uint, f: |&mut Self|);
fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: &fn(&mut Self)); fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: |&mut Self|);
// Specialized types: // 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_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(&mut self, len: uint, f: |this: &mut Self|);
fn emit_seq_elt(&mut self, idx: uint, f: &fn(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(&mut self, len: uint, f: |&mut Self|);
fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut Self)); fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Self|);
fn emit_map_elt_val(&mut self, idx: uint, f: &fn(&mut Self)); fn emit_map_elt_val(&mut self, idx: uint, f: |&mut Self|);
} }
pub trait Decoder { pub trait Decoder {
@ -111,59 +111,56 @@ pub trait Decoder {
fn read_str(&mut self) -> ~str; fn read_str(&mut self) -> ~str;
// Compound types: // Compound types:
fn read_enum<T>(&mut self, name: &str, f: &fn(&mut Self) -> T) -> T; fn read_enum<T>(&mut self, name: &str, f: |&mut Self| -> T) -> T;
fn read_enum_variant<T>(&mut self, fn read_enum_variant<T>(&mut self,
names: &[&str], names: &[&str],
f: &fn(&mut Self, uint) -> T) f: |&mut Self, uint| -> T)
-> T; -> T;
fn read_enum_variant_arg<T>(&mut self, fn read_enum_variant_arg<T>(&mut self,
a_idx: uint, a_idx: uint,
f: &fn(&mut Self) -> T) f: |&mut Self| -> T)
-> T; -> T;
fn read_enum_struct_variant<T>(&mut self, fn read_enum_struct_variant<T>(&mut self,
names: &[&str], names: &[&str],
f: &fn(&mut Self, uint) -> T) f: |&mut Self, uint| -> T)
-> T; -> T;
fn read_enum_struct_variant_field<T>(&mut self, fn read_enum_struct_variant_field<T>(&mut self,
&f_name: &str, &f_name: &str,
f_idx: uint, f_idx: uint,
f: &fn(&mut Self) -> T) f: |&mut Self| -> T)
-> T; -> T;
fn read_struct<T>(&mut self, fn read_struct<T>(&mut self, s_name: &str, len: uint, f: |&mut Self| -> T)
s_name: &str,
len: uint,
f: &fn(&mut Self) -> T)
-> T; -> T;
fn read_struct_field<T>(&mut self, fn read_struct_field<T>(&mut self,
f_name: &str, f_name: &str,
f_idx: uint, f_idx: uint,
f: &fn(&mut Self) -> T) f: |&mut Self| -> T)
-> T; -> T;
fn read_tuple<T>(&mut self, f: &fn(&mut Self, uint) -> T) -> T; fn read_tuple<T>(&mut self, f: |&mut Self, uint| -> T) -> T;
fn read_tuple_arg<T>(&mut self, a_idx: uint, f: &fn(&mut Self) -> T) -> T; fn read_tuple_arg<T>(&mut self, a_idx: uint, f: |&mut Self| -> T) -> T;
fn read_tuple_struct<T>(&mut self, fn read_tuple_struct<T>(&mut self,
s_name: &str, s_name: &str,
f: &fn(&mut Self, uint) -> T) f: |&mut Self, uint| -> T)
-> T; -> T;
fn read_tuple_struct_arg<T>(&mut self, fn read_tuple_struct_arg<T>(&mut self,
a_idx: uint, a_idx: uint,
f: &fn(&mut Self) -> T) f: |&mut Self| -> T)
-> T; -> T;
// Specialized types: // Specialized types:
fn read_option<T>(&mut self, f: &fn(&mut Self, bool) -> T) -> T; fn read_option<T>(&mut self, f: |&mut Self, bool| -> T) -> T;
fn read_seq<T>(&mut self, f: &fn(&mut Self, uint) -> T) -> T; fn read_seq<T>(&mut self, f: |&mut Self, uint| -> T) -> T;
fn read_seq_elt<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; fn read_seq_elt<T>(&mut self, idx: uint, f: |&mut Self| -> T) -> T;
fn read_map<T>(&mut self, f: &fn(&mut Self, uint) -> T) -> T; fn read_map<T>(&mut self, f: |&mut Self, uint| -> T) -> T;
fn read_map_elt_key<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Self| -> T) -> T;
fn read_map_elt_val<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Self| -> T) -> T;
} }
pub trait Encodable<S:Encoder> { pub trait Encodable<S:Encoder> {
@ -892,11 +889,11 @@ impl<
// In some cases, these should eventually be coded as traits. // In some cases, these should eventually be coded as traits.
pub trait EncoderHelpers { pub trait EncoderHelpers {
fn emit_from_vec<T>(&mut self, v: &[T], f: &fn(&mut Self, v: &T)); fn emit_from_vec<T>(&mut self, v: &[T], f: |&mut Self, v: &T|);
} }
impl<S:Encoder> EncoderHelpers for S { impl<S:Encoder> EncoderHelpers for S {
fn emit_from_vec<T>(&mut self, v: &[T], f: &fn(&mut S, &T)) { fn emit_from_vec<T>(&mut self, v: &[T], f: |&mut S, &T|) {
do self.emit_seq(v.len()) |this| { do self.emit_seq(v.len()) |this| {
for (i, e) in v.iter().enumerate() { for (i, e) in v.iter().enumerate() {
do this.emit_seq_elt(i) |this| { do this.emit_seq_elt(i) |this| {
@ -908,11 +905,11 @@ impl<S:Encoder> EncoderHelpers for S {
} }
pub trait DecoderHelpers { pub trait DecoderHelpers {
fn read_to_vec<T>(&mut self, f: &fn(&mut Self) -> T) -> ~[T]; fn read_to_vec<T>(&mut self, f: |&mut Self| -> T) -> ~[T];
} }
impl<D:Decoder> DecoderHelpers for D { impl<D:Decoder> DecoderHelpers for D {
fn read_to_vec<T>(&mut self, f: &fn(&mut D) -> T) -> ~[T] { fn read_to_vec<T>(&mut self, f: |&mut D| -> T) -> ~[T] {
do self.read_seq |this, len| { do self.read_seq |this, len| {
do vec::from_fn(len) |i| { do vec::from_fn(len) |i| {
this.read_seq_elt(i, |this| f(this)) this.read_seq_elt(i, |this| f(this))

View file

@ -164,8 +164,11 @@ impl<V> SmallIntMap<V> {
} }
impl<V:Clone> SmallIntMap<V> { impl<V:Clone> SmallIntMap<V> {
pub fn update_with_key(&mut self, key: uint, val: V, pub fn update_with_key(&mut self,
ff: &fn(uint, V, V) -> V) -> bool { key: uint,
val: V,
ff: |uint, V, V| -> V)
-> bool {
let new_val = match self.find(&key) { let new_val = match self.find(&key) {
None => val, None => val,
Some(orig) => ff(key, (*orig).clone(), val) Some(orig) => ff(key, (*orig).clone(), val)
@ -173,8 +176,7 @@ impl<V:Clone> SmallIntMap<V> {
self.insert(key, new_val) self.insert(key, new_val)
} }
pub fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) pub fn update(&mut self, key: uint, newval: V, ff: |V, V| -> V) -> bool {
-> bool {
self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)) self.update_with_key(key, newval, |_k, v, v1| ff(v,v1))
} }
} }

View file

@ -133,7 +133,7 @@ impl<Q:Send> Sem<Q> {
} }
} }
pub fn access<U>(&self, blk: &fn() -> U) -> U { pub fn access<U>(&self, blk: || -> U) -> U {
do task::unkillable { do task::unkillable {
do (|| { do (|| {
self.acquire(); self.acquire();
@ -305,8 +305,12 @@ impl<'self> Condvar<'self> {
// something else next on success. // something else next on success.
#[inline] #[inline]
#[doc(hidden)] #[doc(hidden)]
fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str, fn check_cvar_bounds<U>(
blk: &fn() -> U) -> U { out_of_bounds: Option<uint>,
id: uint,
act: &str,
blk: || -> U)
-> U {
match out_of_bounds { match out_of_bounds {
Some(0) => Some(0) =>
fail!("{} with illegal ID {} - this lock has no condvars!", act, id), fail!("{} with illegal ID {} - this lock has no condvars!", act, id),
@ -320,7 +324,7 @@ fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str,
impl Sem<~[WaitQueue]> { impl Sem<~[WaitQueue]> {
// The only other places that condvars get built are rwlock.write_cond() // The only other places that condvars get built are rwlock.write_cond()
// and rwlock_write_mode. // and rwlock_write_mode.
pub fn access_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U { pub fn access_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
do self.access { do self.access {
blk(&Condvar { sem: self, order: Nothing, token: NonCopyable::new() }) blk(&Condvar { sem: self, order: Nothing, token: NonCopyable::new() })
} }
@ -361,7 +365,7 @@ impl Semaphore {
pub fn release(&self) { (&self.sem).release() } pub fn release(&self) { (&self.sem).release() }
/// Run a function with ownership of one of the semaphore's resources. /// Run a function with ownership of one of the semaphore's resources.
pub fn access<U>(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) } pub fn access<U>(&self, blk: || -> U) -> U { (&self.sem).access(blk) }
} }
/**************************************************************************** /****************************************************************************
@ -399,12 +403,12 @@ impl Mutex {
/// Run a function with ownership of the mutex. /// Run a function with ownership of the mutex.
pub fn lock<U>(&self, blk: &fn() -> U) -> U { pub fn lock<U>(&self, blk: || -> U) -> U {
(&self.sem).access(blk) (&self.sem).access(blk)
} }
/// Run a function with ownership of the mutex and a handle to a condvar. /// Run a function with ownership of the mutex and a handle to a condvar.
pub fn lock_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U { pub fn lock_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
(&self.sem).access_cond(blk) (&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 * Run a function with the rwlock in read mode. Calls to 'read' from other
* tasks may run concurrently with this one. * tasks may run concurrently with this one.
*/ */
pub fn read<U>(&self, blk: &fn() -> U) -> U { pub fn read<U>(&self, blk: || -> U) -> U {
unsafe { unsafe {
do task::unkillable { do task::unkillable {
do (&self.order_lock).access { 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 * Run a function with the rwlock in write mode. No calls to 'read' or
* 'write' from other tasks will run concurrently with this one. * 'write' from other tasks will run concurrently with this one.
*/ */
pub fn write<U>(&self, blk: &fn() -> U) -> U { pub fn write<U>(&self, blk: || -> U) -> U {
do task::unkillable { do task::unkillable {
(&self.order_lock).acquire(); (&self.order_lock).acquire();
do (&self.access_lock).access { do (&self.access_lock).access {
@ -531,7 +535,7 @@ impl RWLock {
* the waiting task is signalled. (Note: a writer that waited and then * the waiting task is signalled. (Note: a writer that waited and then
* was signalled might reacquire the lock before other waiting writers.) * was signalled might reacquire the lock before other waiting writers.)
*/ */
pub fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U { pub fn write_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
// It's important to thread our order lock into the condvar, so that // 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 // 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", // access lock. If we permitted a waking-up writer to "cut in line",
@ -592,7 +596,7 @@ impl RWLock {
* } * }
* ``` * ```
*/ */
pub fn write_downgrade<U>(&self, blk: &fn(v: RWLockWriteMode) -> U) -> U { pub fn write_downgrade<U>(&self, blk: |v: RWLockWriteMode| -> U) -> U {
// Implementation slightly different from the slicker 'write's above. // Implementation slightly different from the slicker 'write's above.
// The exit path is conditional on whether the caller downgrades. // The exit path is conditional on whether the caller downgrades.
do task::unkillable { do task::unkillable {
@ -671,9 +675,9 @@ pub struct RWLockReadMode<'self> { priv lock: &'self RWLock,
impl<'self> RWLockWriteMode<'self> { impl<'self> RWLockWriteMode<'self> {
/// Access the pre-downgrade rwlock in write mode. /// Access the pre-downgrade rwlock in write mode.
pub fn write<U>(&self, blk: &fn() -> U) -> U { blk() } pub fn write<U>(&self, blk: || -> U) -> U { blk() }
/// Access the pre-downgrade rwlock in write mode with a condvar. /// Access the pre-downgrade rwlock in write mode with a condvar.
pub fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U { pub fn write_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
// Need to make the condvar use the order lock when reacquiring the // Need to make the condvar use the order lock when reacquiring the
// access lock. See comment in RWLock::write_cond for why. // access lock. See comment in RWLock::write_cond for why.
blk(&Condvar { sem: &self.lock.access_lock, blk(&Condvar { sem: &self.lock.access_lock,
@ -684,7 +688,7 @@ impl<'self> RWLockWriteMode<'self> {
impl<'self> RWLockReadMode<'self> { impl<'self> RWLockReadMode<'self> {
/// Access the post-downgrade rwlock in read mode. /// Access the post-downgrade rwlock in read mode.
pub fn read<U>(&self, blk: &fn() -> U) -> U { blk() } pub fn read<U>(&self, blk: || -> U) -> U { blk() }
} }
/**************************************************************************** /****************************************************************************
@ -1060,7 +1064,7 @@ mod tests {
#[cfg(test)] #[cfg(test)]
pub enum RWLockMode { Read, Write, Downgrade, DowngradeRead } pub enum RWLockMode { Read, Write, Downgrade, DowngradeRead }
#[cfg(test)] #[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 { match mode {
Read => x.read(blk), Read => x.read(blk),
Write => x.write(blk), Write => x.write(blk),
@ -1221,7 +1225,7 @@ mod tests {
dg1: bool, dg1: bool,
dg2: bool) { dg2: bool) {
// Much like the mutex broadcast test. Downgrade-enabled. // 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 { if downgrade {
do x.write_downgrade |mode| { do x.write_downgrade |mode| {
do mode.write_cond |c| { blk(c) } do mode.write_cond |c| { blk(c) }

View file

@ -49,7 +49,7 @@ impl<T> TaskPool<T> {
/// local data to be kept around in that task. /// local data to be kept around in that task.
pub fn new(n_tasks: uint, pub fn new(n_tasks: uint,
opt_sched_mode: Option<SchedMode>, opt_sched_mode: Option<SchedMode>,
init_fn_factory: &fn() -> proc(uint) -> T) init_fn_factory: || -> proc(uint) -> T)
-> TaskPool<T> { -> TaskPool<T> {
assert!(n_tasks >= 1); assert!(n_tasks >= 1);
@ -97,7 +97,7 @@ impl<T> TaskPool<T> {
#[test] #[test]
fn test_task_pool() { fn test_task_pool() {
let f: &fn() -> proc(uint) -> uint = || { let f: || -> proc(uint) -> uint = || {
let g: proc(uint) -> uint = |i| i; let g: proc(uint) -> uint = |i| i;
g g
}; };

View file

@ -715,8 +715,7 @@ type MonitorMsg = (TestDesc, TestResult);
fn run_tests(opts: &TestOpts, fn run_tests(opts: &TestOpts,
tests: ~[TestDescAndFn], tests: ~[TestDescAndFn],
callback: &fn(e: TestEvent)) { callback: |e: TestEvent|) {
let filtered_tests = filter_tests(opts, tests); let filtered_tests = filter_tests(opts, tests);
let filtered_descs = filtered_tests.map(|t| t.desc.clone()); let filtered_descs = filtered_tests.map(|t| t.desc.clone());
@ -1058,7 +1057,7 @@ impl MetricMap {
impl BenchHarness { impl BenchHarness {
/// Callback for benchmark functions to run in their body. /// 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(); self.ns_start = precise_time_ns();
let k = self.iterations; let k = self.iterations;
for _ in range(0u64, k) { 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; self.iterations = n;
debug!("running benchmark for {} iterations", debug!("running benchmark for {} iterations",
n as uint); n as uint);
@ -1091,7 +1090,7 @@ impl BenchHarness {
} }
// This is a more statistics-driven benchmark algorithm // 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. // Initial bench run to get ballpark figure.
let mut n = 1_u64; let mut n = 1_u64;
@ -1161,8 +1160,7 @@ impl BenchHarness {
pub mod bench { pub mod bench {
use test::{BenchHarness, BenchSamples}; use test::{BenchHarness, BenchSamples};
pub fn benchmark(f: &fn(&mut BenchHarness)) -> BenchSamples { pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
let mut bs = BenchHarness { let mut bs = BenchHarness {
iterations: 0, iterations: 0,
ns_start: 0, ns_start: 0,

View file

@ -136,7 +136,7 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} } pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
/// Iterate over the map and mutate the contained values /// 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) mutate_values(&mut self.root, f)
} }
@ -678,8 +678,11 @@ impl<K: TotalOrd, V> TreeNode<K, V> {
} }
} }
fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>, fn mutate_values<'r,
f: &fn(&'r K, &'r mut V) -> bool) K:TotalOrd,
V>(
node: &'r mut Option<~TreeNode<K,V>>,
f: |&'r K, &'r mut V| -> bool)
-> bool { -> bool {
match *node { match *node {
Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left, Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left,
@ -1400,8 +1403,10 @@ mod test_set {
} }
} }
fn check(a: &[int], b: &[int], expected: &[int], fn check(a: &[int],
f: &fn(&TreeSet<int>, &TreeSet<int>, f: &fn(&int) -> bool) -> bool) { b: &[int],
expected: &[int],
f: |&TreeSet<int>, &TreeSet<int>, f: |&int| -> bool| -> bool) {
let mut set_a = TreeSet::new(); let mut set_a = TreeSet::new();
let mut set_b = TreeSet::new(); let mut set_b = TreeSet::new();

View file

@ -295,7 +295,12 @@ impl Context {
Prep::new(self, fn_name) 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); let mut p = self.prep(fn_name);
blk(&mut p) blk(&mut p)
} }