* 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.
/// 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| {
* 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) }
}
* 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 {
/// 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();
* 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 {
* }
* ```
*/
- 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| {
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,
/// 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 {
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,
}
#[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);
}
#[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) =
// 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);
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;
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);
}
#[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))
}
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))
}
* 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));
}
#[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;
}
}
#[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) {
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
)
}
- 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
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
/// 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 {
/// 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 {
}
}
- 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);
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);
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))
}
}
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;
}
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);
}
// 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);
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);
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);
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)
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)
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)
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)
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| {
}
}
- 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);
}
}
- 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);
}
}
- 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)
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();
}
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();
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);
_: &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)
}
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();
///
/// 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 {
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 };
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"]}
}
}
- 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, ",");
}
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"\}");
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)
}
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)
}
name: &str,
_: uint,
cnt: uint,
- f: &fn(&mut PrettyEncoder)) {
+ f: |&mut PrettyEncoder|) {
if cnt == 0 {
write!(self.wr, "{}", escape_str(name));
} else {
fn emit_enum_variant_arg(&mut self,
idx: uint,
- f: &fn(&mut PrettyEncoder)) {
+ f: |&mut PrettyEncoder|) {
if idx != 0 {
write!(self.wr, ",\n");
}
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)
}
fn emit_struct(&mut self,
_: &str,
len: uint,
- f: &fn(&mut PrettyEncoder)) {
+ f: |&mut PrettyEncoder|) {
if len == 0 {
write!(self.wr, "\\{\\}");
} else {
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 {
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 {
}
}
- 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 {
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 {
}
}
- 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 {
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);
}
}
}
- 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() {
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)
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)
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)
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);
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() {
}
}
- 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)
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) => {
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) => {
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)
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;
* * 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
* 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 {
*/
/// 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 {
}
/// 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 {
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;
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 {
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 {
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> {
// 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| {
}
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))
}
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)
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))
}
}
}
}
- pub fn access<U>(&self, blk: &fn() -> U) -> U {
+ pub fn access<U>(&self, blk: || -> U) -> U {
do task::unkillable {
do (|| {
self.acquire();
// 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),
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() })
}
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) }
}
/****************************************************************************
/// 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)
}
}
* 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 {
* 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 {
* 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",
* }
* ```
*/
- 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 {
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,
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() }
}
/****************************************************************************
#[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),
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) }
/// 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);
#[test]
fn test_task_pool() {
- let f: &fn() -> proc(uint) -> uint = || {
+ let f: || -> proc(uint) -> uint = || {
let g: proc(uint) -> uint = |i| i;
g
};
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());
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) {
}
}
- 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);
}
// 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;
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,
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)
}
}
}
-fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
- f: &fn(&'r K, &'r mut V) -> bool)
- -> 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,
right: ref mut right, _}) => {
}
}
- 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();
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)
}