libextra: Convert uses of &fn(A)->B
to |A|->B
.
This commit is contained in:
parent
1946265e1a
commit
18a30aff45
16 changed files with 224 additions and 231 deletions
|
@ -220,7 +220,7 @@ impl<T:Send> MutexArc<T> {
|
|||
* blocked on the mutex) will also fail immediately.
|
||||
*/
|
||||
#[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();
|
||||
// Borrowck would complain about this if the function were
|
||||
// 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().
|
||||
#[inline]
|
||||
pub unsafe fn unsafe_access_cond<U>(&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<T:Freeze + Send> MutexArc<T> {
|
|||
* unsafe_access_cond.
|
||||
*/
|
||||
#[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) }
|
||||
}
|
||||
|
||||
/// As unsafe_access_cond but safe and Freeze.
|
||||
#[inline]
|
||||
pub fn access_cond<U>(&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<T:Freeze + Send> RWArc<T> {
|
|||
* poison the Arc, so subsequent readers and writers will both also fail.
|
||||
*/
|
||||
#[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 {
|
||||
let state = self.x.get();
|
||||
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().
|
||||
#[inline]
|
||||
pub fn write_cond<U>(&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<T:Freeze + Send> RWArc<T> {
|
|||
* Failing will unlock the Arc while unwinding. However, unlike all other
|
||||
* 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 {
|
||||
let state = self.x.get();
|
||||
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 {
|
||||
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<U>(&mut self, blk: &fn(x: &mut T) -> U) -> U {
|
||||
pub fn write<U>(&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<U>(&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<U>(&self, blk: &fn(x: &T) -> U) -> U {
|
||||
pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
|
||||
match *self {
|
||||
RWReadMode {
|
||||
data: data,
|
||||
|
|
|
@ -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::<T>();
|
||||
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::<T>();
|
||||
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);
|
||||
|
|
|
@ -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<uint,bool> 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
|
||||
|
|
|
@ -320,7 +320,7 @@ impl<T> DList<T> {
|
|||
/// 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<T> DList<T> {
|
|||
/// 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<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();
|
||||
loop {
|
||||
|
|
|
@ -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<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))
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ pub mod reader {
|
|||
}
|
||||
|
||||
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 old_parent = self.parent;
|
||||
let old_pos = self.pos;
|
||||
|
@ -352,8 +352,7 @@ pub mod reader {
|
|||
}
|
||||
|
||||
impl Decoder {
|
||||
pub fn read_opaque<R>(&mut self, op: &fn(&mut Decoder, Doc) -> R)
|
||||
-> R {
|
||||
pub fn read_opaque<R>(&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<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);
|
||||
self._check_label(name);
|
||||
|
||||
|
@ -446,7 +442,7 @@ pub mod reader {
|
|||
|
||||
fn read_enum_variant<T>(&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<T>(&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<T>(&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<T>(&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<T>(&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<T>(&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<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()");
|
||||
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 {
|
||||
debug!("read_tuple_arg(idx={})", idx);
|
||||
self.read_seq_elt(idx, f)
|
||||
|
@ -534,7 +530,7 @@ pub mod reader {
|
|||
|
||||
fn read_tuple_struct<T>(&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<T>(&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<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()");
|
||||
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<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()");
|
||||
do self.push_doc(EsVec) |d| {
|
||||
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 {
|
||||
debug!("read_seq_elt(idx={})", idx);
|
||||
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()");
|
||||
do self.push_doc(EsMap) |d| {
|
||||
let len = d._next_uint(EsMapLen);
|
||||
|
@ -585,17 +581,13 @@ pub mod reader {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_map_elt_key<T>(&mut self,
|
||||
idx: uint,
|
||||
f: &fn(&mut Decoder) -> T)
|
||||
fn read_map_elt_key<T>(&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<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 {
|
||||
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();
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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<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);
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_enum_variant<T>(&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<T>(&mut self,
|
||||
idx: uint,
|
||||
f: &fn(&mut Decoder) -> T)
|
||||
fn read_enum_variant_arg<T>(&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<T>(&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<T>(&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<T>(&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<T>(&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<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()");
|
||||
self.read_seq(f)
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T>(&mut self,
|
||||
idx: uint,
|
||||
f: &fn(&mut Decoder) -> T)
|
||||
-> T {
|
||||
fn read_tuple_arg<T>(&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<T>(&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<T>(&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<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() {
|
||||
Null => f(self, false),
|
||||
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()");
|
||||
let len = match self.stack.pop() {
|
||||
List(list) => {
|
||||
|
@ -1068,12 +1063,12 @@ impl serialize::Decoder for Decoder {
|
|||
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);
|
||||
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()");
|
||||
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<T>(&mut self,
|
||||
idx: uint,
|
||||
f: &fn(&mut Decoder) -> T)
|
||||
fn read_map_elt_key<T>(&mut self, idx: uint, f: |&mut Decoder| -> T)
|
||||
-> T {
|
||||
debug!("read_map_elt_key(idx={})", idx);
|
||||
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 {
|
||||
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;
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn from_vec<T:Clone + 'static>(v: &[T]) -> @List<T> {
|
|||
* * z - The initial value
|
||||
* * 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;
|
||||
do iter(ls) |elt| { accum = f(&accum, elt);}
|
||||
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
|
||||
* 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;
|
||||
loop {
|
||||
ls = match *ls {
|
||||
|
@ -131,7 +131,7 @@ fn push<T:Clone>(ll: &mut @list<T>, vv: T) {
|
|||
*/
|
||||
|
||||
/// 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;
|
||||
loop {
|
||||
cur = match *cur {
|
||||
|
@ -145,7 +145,7 @@ pub fn iter<T>(l: @List<T>, f: &fn(&T)) {
|
|||
}
|
||||
|
||||
/// 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;
|
||||
loop {
|
||||
cur = match *cur {
|
||||
|
@ -160,7 +160,7 @@ pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) -> bool {
|
|||
|
||||
impl<T> MutList<T> {
|
||||
/// 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;
|
||||
|
|
|
@ -145,8 +145,8 @@ condition! {
|
|||
bad_parse: () -> ();
|
||||
}
|
||||
|
||||
fn take_nonempty_prefix<T: Iterator<char>>(rdr: &mut T,
|
||||
pred: &fn(char) -> bool) -> (~str, Option<char>) {
|
||||
fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
|
||||
-> (~str, Option<char>) {
|
||||
let mut buf = ~"";
|
||||
let mut ch = rdr.next();
|
||||
loop {
|
||||
|
|
|
@ -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<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,
|
||||
names: &[&str],
|
||||
f: &fn(&mut Self, uint) -> T)
|
||||
f: |&mut Self, uint| -> T)
|
||||
-> T;
|
||||
fn read_enum_variant_arg<T>(&mut self,
|
||||
a_idx: uint,
|
||||
f: &fn(&mut Self) -> T)
|
||||
f: |&mut Self| -> T)
|
||||
-> T;
|
||||
|
||||
fn read_enum_struct_variant<T>(&mut self,
|
||||
names: &[&str],
|
||||
f: &fn(&mut Self, uint) -> T)
|
||||
f: |&mut Self, uint| -> T)
|
||||
-> T;
|
||||
fn read_enum_struct_variant_field<T>(&mut self,
|
||||
&f_name: &str,
|
||||
f_idx: uint,
|
||||
f: &fn(&mut Self) -> T)
|
||||
f: |&mut Self| -> T)
|
||||
-> T;
|
||||
|
||||
fn read_struct<T>(&mut self,
|
||||
s_name: &str,
|
||||
len: uint,
|
||||
f: &fn(&mut Self) -> T)
|
||||
fn read_struct<T>(&mut self, s_name: &str, len: uint, f: |&mut Self| -> T)
|
||||
-> T;
|
||||
fn read_struct_field<T>(&mut self,
|
||||
f_name: &str,
|
||||
f_idx: uint,
|
||||
f: &fn(&mut Self) -> T)
|
||||
f: |&mut Self| -> T)
|
||||
-> T;
|
||||
|
||||
fn read_tuple<T>(&mut self, f: &fn(&mut Self, uint) -> T) -> T;
|
||||
fn read_tuple_arg<T>(&mut self, a_idx: uint, f: &fn(&mut Self) -> 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: |&mut Self| -> T) -> T;
|
||||
|
||||
fn read_tuple_struct<T>(&mut self,
|
||||
s_name: &str,
|
||||
f: &fn(&mut Self, uint) -> T)
|
||||
f: |&mut Self, uint| -> T)
|
||||
-> T;
|
||||
fn read_tuple_struct_arg<T>(&mut self,
|
||||
a_idx: uint,
|
||||
f: &fn(&mut Self) -> T)
|
||||
f: |&mut Self| -> T)
|
||||
-> T;
|
||||
|
||||
// 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_elt<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T;
|
||||
fn read_seq<T>(&mut self, f: |&mut Self, uint| -> 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_elt_key<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T;
|
||||
fn read_map_elt_val<T>(&mut self, idx: uint, f: &fn(&mut Self) -> 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: |&mut Self| -> T) -> T;
|
||||
fn read_map_elt_val<T>(&mut self, idx: uint, f: |&mut Self| -> T) -> T;
|
||||
}
|
||||
|
||||
pub trait Encodable<S:Encoder> {
|
||||
|
@ -892,11 +889,11 @@ impl<
|
|||
// In some cases, these should eventually be coded as traits.
|
||||
|
||||
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 {
|
||||
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| {
|
||||
for (i, e) in v.iter().enumerate() {
|
||||
do this.emit_seq_elt(i) |this| {
|
||||
|
@ -908,11 +905,11 @@ impl<S:Encoder> EncoderHelpers for S {
|
|||
}
|
||||
|
||||
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 {
|
||||
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 vec::from_fn(len) |i| {
|
||||
this.read_seq_elt(i, |this| f(this))
|
||||
|
|
|
@ -164,8 +164,11 @@ impl<V> SmallIntMap<V> {
|
|||
}
|
||||
|
||||
impl<V:Clone> SmallIntMap<V> {
|
||||
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<V:Clone> SmallIntMap<V> {
|
|||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 (|| {
|
||||
self.acquire();
|
||||
|
@ -305,8 +305,12 @@ impl<'self> Condvar<'self> {
|
|||
// something else next on success.
|
||||
#[inline]
|
||||
#[doc(hidden)]
|
||||
fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str,
|
||||
blk: &fn() -> U) -> U {
|
||||
fn check_cvar_bounds<U>(
|
||||
out_of_bounds: Option<uint>,
|
||||
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<U>(out_of_bounds: Option<uint>, 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<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
pub fn access_cond<U>(&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<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.
|
||||
pub fn lock<U>(&self, blk: &fn() -> U) -> U {
|
||||
pub fn lock<U>(&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<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
pub fn lock_cond<U>(&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<U>(&self, blk: &fn() -> U) -> U {
|
||||
pub fn read<U>(&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<U>(&self, blk: &fn() -> U) -> U {
|
||||
pub fn write<U>(&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<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
|
||||
// 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<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.
|
||||
// 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<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.
|
||||
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
|
||||
// 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<U>(&self, blk: &fn() -> U) -> U { blk() }
|
||||
pub fn read<U>(&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) }
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<T> TaskPool<T> {
|
|||
/// local data to be kept around in that task.
|
||||
pub fn new(n_tasks: uint,
|
||||
opt_sched_mode: Option<SchedMode>,
|
||||
init_fn_factory: &fn() -> proc(uint) -> T)
|
||||
init_fn_factory: || -> proc(uint) -> T)
|
||||
-> TaskPool<T> {
|
||||
assert!(n_tasks >= 1);
|
||||
|
||||
|
@ -97,7 +97,7 @@ impl<T> TaskPool<T> {
|
|||
|
||||
#[test]
|
||||
fn test_task_pool() {
|
||||
let f: &fn() -> proc(uint) -> uint = || {
|
||||
let f: || -> proc(uint) -> uint = || {
|
||||
let g: proc(uint) -> uint = |i| i;
|
||||
g
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -136,7 +136,7 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
|
|||
pub fn new() -> TreeMap<K, V> { 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,8 +678,11 @@ impl<K: TotalOrd, V> TreeNode<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
|
||||
f: &fn(&'r K, &'r mut V) -> bool)
|
||||
fn mutate_values<'r,
|
||||
K:TotalOrd,
|
||||
V>(
|
||||
node: &'r mut Option<~TreeNode<K,V>>,
|
||||
f: |&'r K, &'r mut V| -> bool)
|
||||
-> bool {
|
||||
match *node {
|
||||
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],
|
||||
f: &fn(&TreeSet<int>, &TreeSet<int>, f: &fn(&int) -> bool) -> bool) {
|
||||
fn check(a: &[int],
|
||||
b: &[int],
|
||||
expected: &[int],
|
||||
f: |&TreeSet<int>, &TreeSet<int>, f: |&int| -> bool| -> bool) {
|
||||
let mut set_a = TreeSet::new();
|
||||
let mut set_b = TreeSet::new();
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue