mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 16:15:03 +00:00
libstd: Change all uses of &fn(A)->B
over to |A|->B
in libstd
This commit is contained in:
parent
eef913b290
commit
1946265e1a
@ -235,7 +235,7 @@ impl ToStrConsume for ~[Ascii] {
|
|||||||
|
|
||||||
impl IterBytes for Ascii {
|
impl IterBytes for Ascii {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter_bytes(&self, _lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool {
|
fn iter_bytes(&self, _lsb0: bool, f: |buf: &[u8]| -> bool) -> bool {
|
||||||
f([self.to_byte()])
|
f([self.to_byte()])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ pub fn capacity<T>(v: @[T]) -> uint {
|
|||||||
* onto the vector being constructed.
|
* onto the vector being constructed.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn build<A>(size: Option<uint>, builder: &fn(push: &fn(v: A))) -> @[A] {
|
pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> @[A] {
|
||||||
let mut vec = @[];
|
let mut vec = @[];
|
||||||
unsafe { raw::reserve(&mut vec, size.unwrap_or(4)); }
|
unsafe { raw::reserve(&mut vec, size.unwrap_or(4)); }
|
||||||
builder(|x| unsafe { raw::push(&mut vec, x) });
|
builder(|x| unsafe { raw::push(&mut vec, x) });
|
||||||
@ -68,7 +68,7 @@ pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] {
|
|||||||
|
|
||||||
|
|
||||||
/// Apply a function to each element of a vector and return the results
|
/// Apply a function to each element of a vector and return the results
|
||||||
pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
|
pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] {
|
||||||
do build(Some(v.len())) |push| {
|
do build(Some(v.len())) |push| {
|
||||||
for elem in v.iter() {
|
for elem in v.iter() {
|
||||||
push(f(elem));
|
push(f(elem));
|
||||||
@ -82,7 +82,7 @@ pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
|
|||||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||||
* to the value returned by the function `op`.
|
* to the value returned by the function `op`.
|
||||||
*/
|
*/
|
||||||
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> @[T] {
|
pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] {
|
||||||
do build(Some(n_elts)) |push| {
|
do build(Some(n_elts)) |push| {
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
while i < n_elts { push(op(i)); i += 1u; }
|
while i < n_elts { push(op(i)); i += 1u; }
|
||||||
|
@ -58,7 +58,7 @@ use num::FromPrimitive;
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn all_values(blk: &fn(v: bool)) {
|
pub fn all_values(blk: |v: bool|) {
|
||||||
blk(true);
|
blk(true);
|
||||||
blk(false);
|
blk(false);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ impl CString {
|
|||||||
/// # Failure
|
/// # Failure
|
||||||
///
|
///
|
||||||
/// Fails if the CString is null.
|
/// Fails if the CString is null.
|
||||||
pub fn with_ref<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
|
pub fn with_ref<T>(&self, f: |*libc::c_char| -> T) -> T {
|
||||||
if self.buf.is_null() { fail!("CString is null!"); }
|
if self.buf.is_null() { fail!("CString is null!"); }
|
||||||
f(self.buf)
|
f(self.buf)
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ impl CString {
|
|||||||
/// # Failure
|
/// # Failure
|
||||||
///
|
///
|
||||||
/// Fails if the CString is null.
|
/// Fails if the CString is null.
|
||||||
pub fn with_mut_ref<T>(&mut self, f: &fn(*mut libc::c_char) -> T) -> T {
|
pub fn with_mut_ref<T>(&mut self, f: |*mut libc::c_char| -> T) -> T {
|
||||||
if self.buf.is_null() { fail!("CString is null!"); }
|
if self.buf.is_null() { fail!("CString is null!"); }
|
||||||
f(unsafe { cast::transmute_mut_unsafe(self.buf) })
|
f(unsafe { cast::transmute_mut_unsafe(self.buf) })
|
||||||
}
|
}
|
||||||
@ -223,13 +223,13 @@ pub trait ToCStr {
|
|||||||
///
|
///
|
||||||
/// Raises the `null_byte` condition if the receiver has an interior null.
|
/// Raises the `null_byte` condition if the receiver has an interior null.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
|
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
|
||||||
self.to_c_str().with_ref(f)
|
self.to_c_str().with_ref(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unsafe variant of `with_c_str()` that doesn't check for nulls.
|
/// Unsafe variant of `with_c_str()` that doesn't check for nulls.
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
|
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
|
||||||
self.to_c_str_unchecked().with_ref(f)
|
self.to_c_str_unchecked().with_ref(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,12 +246,12 @@ impl<'self> ToCStr for &'self str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
|
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
|
||||||
self.as_bytes().with_c_str(f)
|
self.as_bytes().with_c_str(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
|
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
|
||||||
self.as_bytes().with_c_str_unchecked(f)
|
self.as_bytes().with_c_str_unchecked(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,17 +282,17 @@ impl<'self> ToCStr for &'self [u8] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
|
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
|
||||||
unsafe { with_c_str(*self, true, f) }
|
unsafe { with_c_str(*self, true, f) }
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
|
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
|
||||||
with_c_str(*self, false, f)
|
with_c_str(*self, false, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsafe function that handles possibly copying the &[u8] into a stack array.
|
// Unsafe function that handles possibly copying the &[u8] into a stack array.
|
||||||
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: &fn(*libc::c_char) -> T) -> T {
|
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T {
|
||||||
if v.len() < BUF_LEN {
|
if v.len() < BUF_LEN {
|
||||||
let mut buf: [u8, .. BUF_LEN] = intrinsics::uninit();
|
let mut buf: [u8, .. BUF_LEN] = intrinsics::uninit();
|
||||||
vec::bytes::copy_memory(buf, v, v.len());
|
vec::bytes::copy_memory(buf, v, v.len());
|
||||||
@ -357,7 +357,7 @@ impl<'self> Iterator<libc::c_char> for CStringIterator<'self> {
|
|||||||
/// is found, and the number of strings found is returned.
|
/// is found, and the number of strings found is returned.
|
||||||
pub unsafe fn from_c_multistring(buf: *libc::c_char,
|
pub unsafe fn from_c_multistring(buf: *libc::c_char,
|
||||||
count: Option<uint>,
|
count: Option<uint>,
|
||||||
f: &fn(&CString)) -> uint {
|
f: |&CString|) -> uint {
|
||||||
|
|
||||||
let mut curr_ptr: uint = buf as uint;
|
let mut curr_ptr: uint = buf as uint;
|
||||||
let mut ctr = 0;
|
let mut ctr = 0;
|
||||||
|
@ -71,12 +71,12 @@ impl<T> Cell<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Calls a closure with a reference to the value.
|
/// Calls a closure with a reference to the value.
|
||||||
pub fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
|
pub fn with_ref<R>(&self, op: |v: &T| -> R) -> R {
|
||||||
do self.with_mut_ref |ptr| { op(ptr) }
|
do self.with_mut_ref |ptr| { op(ptr) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls a closure with a mutable reference to the value.
|
/// Calls a closure with a mutable reference to the value.
|
||||||
pub fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
|
pub fn with_mut_ref<R>(&self, op: |v: &mut T| -> R) -> R {
|
||||||
let mut v = Some(self.take());
|
let mut v = Some(self.take());
|
||||||
do (|| {
|
do (|| {
|
||||||
op(v.get_mut_ref())
|
op(v.get_mut_ref())
|
||||||
|
@ -241,7 +241,7 @@ static N_COUNT: uint = (V_COUNT * T_COUNT);
|
|||||||
static S_COUNT: uint = (L_COUNT * N_COUNT);
|
static S_COUNT: uint = (L_COUNT * N_COUNT);
|
||||||
|
|
||||||
// Decompose a precomposed Hangul syllable
|
// Decompose a precomposed Hangul syllable
|
||||||
fn decompose_hangul(s: char, f: &fn(char)) {
|
fn decompose_hangul(s: char, f: |char|) {
|
||||||
let si = s as uint - S_BASE;
|
let si = s as uint - S_BASE;
|
||||||
|
|
||||||
let li = si / N_COUNT;
|
let li = si / N_COUNT;
|
||||||
@ -259,7 +259,7 @@ fn decompose_hangul(s: char, f: &fn(char)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the canonical decompostion of a character
|
/// Returns the canonical decompostion of a character
|
||||||
pub fn decompose_canonical(c: char, f: &fn(char)) {
|
pub fn decompose_canonical(c: char, f: |char|) {
|
||||||
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
|
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
|
||||||
decompose::canonical(c, f);
|
decompose::canonical(c, f);
|
||||||
} else {
|
} else {
|
||||||
@ -268,7 +268,7 @@ pub fn decompose_canonical(c: char, f: &fn(char)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the compatibility decompostion of a character
|
/// Returns the compatibility decompostion of a character
|
||||||
pub fn decompose_compatible(c: char, f: &fn(char)) {
|
pub fn decompose_compatible(c: char, f: |char|) {
|
||||||
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
|
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
|
||||||
decompose::compatibility(c, f);
|
decompose::compatibility(c, f);
|
||||||
} else {
|
} else {
|
||||||
@ -285,7 +285,7 @@ pub fn decompose_compatible(c: char, f: &fn(char)) {
|
|||||||
/// - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
|
/// - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
|
||||||
/// - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
|
/// - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
|
||||||
///
|
///
|
||||||
pub fn escape_unicode(c: char, f: &fn(char)) {
|
pub fn escape_unicode(c: char, f: |char|) {
|
||||||
// avoid calling str::to_str_radix because we don't really need to allocate
|
// avoid calling str::to_str_radix because we don't really need to allocate
|
||||||
// here.
|
// here.
|
||||||
f('\\');
|
f('\\');
|
||||||
@ -316,7 +316,7 @@ pub fn escape_unicode(c: char, f: &fn(char)) {
|
|||||||
/// - Any other chars in the range [0x20,0x7e] are not escaped.
|
/// - Any other chars in the range [0x20,0x7e] are not escaped.
|
||||||
/// - Any other chars are given hex unicode escapes; see `escape_unicode`.
|
/// - Any other chars are given hex unicode escapes; see `escape_unicode`.
|
||||||
///
|
///
|
||||||
pub fn escape_default(c: char, f: &fn(char)) {
|
pub fn escape_default(c: char, f: |char|) {
|
||||||
match c {
|
match c {
|
||||||
'\t' => { f('\\'); f('t'); }
|
'\t' => { f('\\'); f('t'); }
|
||||||
'\r' => { f('\\'); f('r'); }
|
'\r' => { f('\\'); f('r'); }
|
||||||
@ -367,8 +367,8 @@ pub trait Char {
|
|||||||
fn is_digit_radix(&self, radix: uint) -> bool;
|
fn is_digit_radix(&self, radix: uint) -> bool;
|
||||||
fn to_digit(&self, radix: uint) -> Option<uint>;
|
fn to_digit(&self, radix: uint) -> Option<uint>;
|
||||||
fn from_digit(num: uint, radix: uint) -> Option<char>;
|
fn from_digit(num: uint, radix: uint) -> Option<char>;
|
||||||
fn escape_unicode(&self, f: &fn(char));
|
fn escape_unicode(&self, f: |char|);
|
||||||
fn escape_default(&self, f: &fn(char));
|
fn escape_default(&self, f: |char|);
|
||||||
fn len_utf8_bytes(&self) -> uint;
|
fn len_utf8_bytes(&self) -> uint;
|
||||||
|
|
||||||
/// Encodes this character as utf-8 into the provided byte-buffer. The
|
/// Encodes this character as utf-8 into the provided byte-buffer. The
|
||||||
@ -403,9 +403,9 @@ impl Char for char {
|
|||||||
|
|
||||||
fn from_digit(num: uint, radix: uint) -> Option<char> { from_digit(num, radix) }
|
fn from_digit(num: uint, radix: uint) -> Option<char> { from_digit(num, radix) }
|
||||||
|
|
||||||
fn escape_unicode(&self, f: &fn(char)) { escape_unicode(*self, f) }
|
fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) }
|
||||||
|
|
||||||
fn escape_default(&self, f: &fn(char)) { escape_default(*self, f) }
|
fn escape_default(&self, f: |char|) { escape_default(*self, f) }
|
||||||
|
|
||||||
fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) }
|
fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) }
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ struct AnnihilateStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn each_live_alloc(read_next_before: bool,
|
unsafe fn each_live_alloc(read_next_before: bool,
|
||||||
f: &fn(box: *mut raw::Box<()>, uniq: bool) -> bool) -> bool {
|
f: |box: *mut raw::Box<()>, uniq: bool| -> bool)
|
||||||
|
-> bool {
|
||||||
//! Walks the internal list of allocations
|
//! Walks the internal list of allocations
|
||||||
|
|
||||||
use managed;
|
use managed;
|
||||||
|
@ -133,7 +133,7 @@ impl<T, U> Condition<T, U> {
|
|||||||
|
|
||||||
/// Performs the same functionality as `raise`, except that when no handler
|
/// Performs the same functionality as `raise`, except that when no handler
|
||||||
/// is found the `default` argument is called instead of failing the task.
|
/// is found the `default` argument is called instead of failing the task.
|
||||||
pub fn raise_default(&self, t: T, default: &fn() -> U) -> U {
|
pub fn raise_default(&self, t: T, default: || -> U) -> U {
|
||||||
match local_data::pop(self.key) {
|
match local_data::pop(self.key) {
|
||||||
None => {
|
None => {
|
||||||
debug!("Condition.raise: found no handler");
|
debug!("Condition.raise: found no handler");
|
||||||
@ -145,7 +145,7 @@ impl<T, U> Condition<T, U> {
|
|||||||
None => {}
|
None => {}
|
||||||
Some(hp) => local_data::set(self.key, hp)
|
Some(hp) => local_data::set(self.key, hp)
|
||||||
}
|
}
|
||||||
let handle : &fn(T) -> U = unsafe {
|
let handle : |T| -> U = unsafe {
|
||||||
::cast::transmute(handler.handle)
|
::cast::transmute(handler.handle)
|
||||||
};
|
};
|
||||||
let u = handle(t);
|
let u = handle(t);
|
||||||
|
@ -38,7 +38,7 @@ impl<L, R> Either<L, R> {
|
|||||||
/// `value` is `Right(R)` then `f_right` is applied to its contents, and the
|
/// `value` is `Right(R)` then `f_right` is applied to its contents, and the
|
||||||
/// result is returned.
|
/// result is returned.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn either<T>(&self, f_left: &fn(&L) -> T, f_right: &fn(&R) -> T) -> T {
|
pub fn either<T>(&self, f_left: |&L| -> T, f_right: |&R| -> T) -> T {
|
||||||
match *self {
|
match *self {
|
||||||
Left(ref l) => f_left(l),
|
Left(ref l) => f_left(l),
|
||||||
Right(ref r) => f_right(r)
|
Right(ref r) => f_right(r)
|
||||||
|
@ -931,8 +931,10 @@ impl<'self> Formatter<'self> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_padding(&mut self, padding: uint,
|
fn with_padding(&mut self,
|
||||||
default: parse::Alignment, f: &fn(&mut Formatter)) {
|
padding: uint,
|
||||||
|
default: parse::Alignment,
|
||||||
|
f: |&mut Formatter|) {
|
||||||
let align = match self.align {
|
let align = match self.align {
|
||||||
parse::AlignUnknown => default,
|
parse::AlignUnknown => default,
|
||||||
parse::AlignLeft | parse::AlignRight => self.align
|
parse::AlignLeft | parse::AlignRight => self.align
|
||||||
|
@ -408,7 +408,7 @@ mod tests {
|
|||||||
// Hash just the bytes of the slice, without length prefix
|
// Hash just the bytes of the slice, without length prefix
|
||||||
struct Bytes<'self>(&'self [u8]);
|
struct Bytes<'self>(&'self [u8]);
|
||||||
impl<'self> IterBytes for Bytes<'self> {
|
impl<'self> IterBytes for Bytes<'self> {
|
||||||
fn iter_bytes(&self, _lsb0: bool, f: &fn(&[u8]) -> bool) -> bool {
|
fn iter_bytes(&self, _lsb0: bool, f: |&[u8]| -> bool) -> bool {
|
||||||
f(**self)
|
f(**self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,7 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bucket_sequence(&self, hash: uint,
|
fn bucket_sequence(&self, hash: uint, op: |uint| -> bool) -> bool {
|
||||||
op: &fn(uint) -> bool) -> bool {
|
|
||||||
let start_idx = self.to_bucket(hash);
|
let start_idx = self.to_bucket(hash);
|
||||||
let len_buckets = self.buckets.len();
|
let len_buckets = self.buckets.len();
|
||||||
let mut idx = start_idx;
|
let mut idx = start_idx;
|
||||||
@ -360,8 +359,14 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
|
|||||||
|
|
||||||
/// Modify and return the value corresponding to the key in the map, or
|
/// Modify and return the value corresponding to the key in the map, or
|
||||||
/// insert and return a new value if it doesn't exist.
|
/// insert and return a new value if it doesn't exist.
|
||||||
pub fn mangle<'a,A>(&'a mut self, k: K, a: A, not_found: &fn(&K, A) -> V,
|
pub fn mangle<'a,
|
||||||
found: &fn(&K, &mut V, A)) -> &'a mut V {
|
A>(
|
||||||
|
&'a mut self,
|
||||||
|
k: K,
|
||||||
|
a: A,
|
||||||
|
not_found: |&K, A| -> V,
|
||||||
|
found: |&K, &mut V, A|)
|
||||||
|
-> &'a mut V {
|
||||||
if self.size >= self.resize_at {
|
if self.size >= self.resize_at {
|
||||||
// n.b.: We could also do this after searching, so
|
// n.b.: We could also do this after searching, so
|
||||||
// that we do not resize if this call to insert is
|
// that we do not resize if this call to insert is
|
||||||
@ -395,7 +400,7 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
|
|||||||
|
|
||||||
/// Return the value corresponding to the key in the map, or create,
|
/// Return the value corresponding to the key in the map, or create,
|
||||||
/// insert, and return a new value if it doesn't exist.
|
/// insert, and return a new value if it doesn't exist.
|
||||||
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V)
|
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: |&K| -> V)
|
||||||
-> &'a mut V {
|
-> &'a mut V {
|
||||||
self.mangle(k, (), |k,_a| f(k), |_k,_v,_a| ())
|
self.mangle(k, (), |k,_a| f(k), |_k,_v,_a| ())
|
||||||
}
|
}
|
||||||
@ -403,8 +408,12 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
|
|||||||
/// Insert a key-value pair into the map if the key is not already present.
|
/// Insert a key-value pair into the map if the key is not already present.
|
||||||
/// Otherwise, modify the existing value for the key.
|
/// Otherwise, modify the existing value for the key.
|
||||||
/// Returns the new or modified value for the key.
|
/// Returns the new or modified value for the key.
|
||||||
pub fn insert_or_update_with<'a>(&'a mut self, k: K, v: V,
|
pub fn insert_or_update_with<'a>(
|
||||||
f: &fn(&K, &mut V)) -> &'a mut V {
|
&'a mut self,
|
||||||
|
k: K,
|
||||||
|
v: V,
|
||||||
|
f: |&K, &mut V|)
|
||||||
|
-> &'a mut V {
|
||||||
self.mangle(k, v, |_k,a| a, |k,v,_a| f(k,v))
|
self.mangle(k, v, |_k,a| a, |k,v,_a| f(k,v))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,12 +455,12 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all keys
|
/// Visit all keys
|
||||||
pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool {
|
pub fn each_key(&self, blk: |k: &K| -> bool) -> bool {
|
||||||
self.iter().advance(|(k, _)| blk(k))
|
self.iter().advance(|(k, _)| blk(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all values
|
/// Visit all values
|
||||||
pub fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) -> bool {
|
pub fn each_value<'a>(&'a self, blk: |v: &'a V| -> bool) -> bool {
|
||||||
self.iter().advance(|(_, v)| blk(v))
|
self.iter().advance(|(_, v)| blk(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,7 @@ impl<'self, R: Reader> Iterator<u8> for ByteIterator<R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn u64_to_le_bytes<T>(n: u64, size: uint,
|
pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
||||||
f: &fn(v: &[u8]) -> T) -> T {
|
|
||||||
assert!(size <= 8u);
|
assert!(size <= 8u);
|
||||||
match size {
|
match size {
|
||||||
1u => f(&[n as u8]),
|
1u => f(&[n as u8]),
|
||||||
@ -88,8 +87,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn u64_to_be_bytes<T>(n: u64, size: uint,
|
pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
||||||
f: &fn(v: &[u8]) -> T) -> T {
|
|
||||||
assert!(size <= 8u);
|
assert!(size <= 8u);
|
||||||
match size {
|
match size {
|
||||||
1u => f(&[n as u8]),
|
1u => f(&[n as u8]),
|
||||||
|
@ -75,7 +75,7 @@ pub struct File {
|
|||||||
priv last_nread: int,
|
priv last_nread: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn io_raise<T>(f: &fn(io: &mut IoFactory) -> Result<T, IoError>) -> Option<T> {
|
fn io_raise<T>(f: |io: &mut IoFactory| -> Result<T, IoError>) -> Option<T> {
|
||||||
do with_local_io |io| {
|
do with_local_io |io| {
|
||||||
match f(io) {
|
match f(io) {
|
||||||
Ok(t) => Some(t),
|
Ok(t) => Some(t),
|
||||||
@ -499,7 +499,7 @@ pub fn rmdir(path: &Path) {
|
|||||||
/// use std::io::fs;
|
/// use std::io::fs;
|
||||||
///
|
///
|
||||||
/// // one possible implementation of fs::walk_dir only visiting files
|
/// // one possible implementation of fs::walk_dir only visiting files
|
||||||
/// fn visit_dirs(dir: &Path, cb: &fn(&Path)) {
|
/// fn visit_dirs(dir: &Path, cb: |&Path|) {
|
||||||
/// if dir.is_dir() {
|
/// if dir.is_dir() {
|
||||||
/// let contents = fs::readdir(dir).unwrap();
|
/// let contents = fs::readdir(dir).unwrap();
|
||||||
/// for entry in contents.iter() {
|
/// for entry in contents.iter() {
|
||||||
|
@ -240,7 +240,7 @@ impl<'self> Buffer for BufReader<'self> {
|
|||||||
|
|
||||||
///Calls a function with a MemWriter and returns
|
///Calls a function with a MemWriter and returns
|
||||||
///the writer's stored vector.
|
///the writer's stored vector.
|
||||||
pub fn with_mem_writer(writeFn:&fn(&mut MemWriter)) -> ~[u8] {
|
pub fn with_mem_writer(writeFn: |&mut MemWriter|) -> ~[u8] {
|
||||||
let mut writer = MemWriter::new();
|
let mut writer = MemWriter::new();
|
||||||
writeFn(&mut writer);
|
writeFn(&mut writer);
|
||||||
writer.inner()
|
writer.inner()
|
||||||
|
@ -394,7 +394,7 @@ condition! {
|
|||||||
|
|
||||||
/// Helper for wrapper calls where you want to
|
/// Helper for wrapper calls where you want to
|
||||||
/// ignore any io_errors that might be raised
|
/// ignore any io_errors that might be raised
|
||||||
pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
|
pub fn ignore_io_error<T>(cb: || -> T) -> T {
|
||||||
do io_error::cond.trap(|_| {
|
do io_error::cond.trap(|_| {
|
||||||
// just swallow the error.. downstream users
|
// just swallow the error.. downstream users
|
||||||
// who can make a decision based on a None result
|
// who can make a decision based on a None result
|
||||||
@ -407,7 +407,7 @@ pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
|
|||||||
/// Helper for catching an I/O error and wrapping it in a Result object. The
|
/// Helper for catching an I/O error and wrapping it in a Result object. The
|
||||||
/// return result will be the last I/O error that happened or the result of the
|
/// return result will be the last I/O error that happened or the result of the
|
||||||
/// closure if no error occurred.
|
/// closure if no error occurred.
|
||||||
pub fn result<T>(cb: &fn() -> T) -> Result<T, IoError> {
|
pub fn result<T>(cb: || -> T) -> Result<T, IoError> {
|
||||||
let mut err = None;
|
let mut err = None;
|
||||||
let ret = io_error::cond.trap(|e| {
|
let ret = io_error::cond.trap(|e| {
|
||||||
if err.is_none() {
|
if err.is_none() {
|
||||||
|
@ -33,7 +33,7 @@ use vec;
|
|||||||
#[cfg(windows)] use ptr;
|
#[cfg(windows)] use ptr;
|
||||||
#[cfg(windows)] use str;
|
#[cfg(windows)] use str;
|
||||||
|
|
||||||
fn keep_going(data: &[u8], f: &fn(*u8, uint) -> i64) -> i64 {
|
fn keep_going(data: &[u8], f: |*u8, uint| -> i64) -> i64 {
|
||||||
#[cfg(windows)] static eintr: int = 0; // doesn't matter
|
#[cfg(windows)] static eintr: int = 0; // doesn't matter
|
||||||
#[cfg(not(windows))] static eintr: int = libc::EINTR as int;
|
#[cfg(not(windows))] static eintr: int = libc::EINTR as int;
|
||||||
|
|
||||||
|
@ -432,7 +432,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn with_argv<T>(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T {
|
fn with_argv<T>(prog: &str, args: &[~str], cb: |**libc::c_char| -> T) -> T {
|
||||||
use vec;
|
use vec;
|
||||||
|
|
||||||
// We can't directly convert `str`s into `*char`s, as someone needs to hold
|
// We can't directly convert `str`s into `*char`s, as someone needs to hold
|
||||||
@ -460,7 +460,7 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
|
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*c_void| -> T) -> T {
|
||||||
use vec;
|
use vec;
|
||||||
|
|
||||||
// On posixy systems we can pass a char** for envp, which is a
|
// On posixy systems we can pass a char** for envp, which is a
|
||||||
@ -490,7 +490,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
|
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T {
|
||||||
// On win32 we pass an "environment block" which is not a char**, but
|
// On win32 we pass an "environment block" which is not a char**, but
|
||||||
// rather a concatenation of null-terminated k=v\0 sequences, with a final
|
// rather a concatenation of null-terminated k=v\0 sequences, with a final
|
||||||
// \0 to terminate.
|
// \0 to terminate.
|
||||||
@ -514,7 +514,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_dirp<T>(d: Option<&Path>, cb: &fn(*libc::c_char) -> T) -> T {
|
fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T {
|
||||||
match d {
|
match d {
|
||||||
Some(dir) => dir.with_c_str(|buf| cb(buf)),
|
Some(dir) => dir.with_c_str(|buf| cb(buf)),
|
||||||
None => cb(ptr::null())
|
None => cb(ptr::null())
|
||||||
|
@ -81,7 +81,8 @@ impl<'self> Parser<'self> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Commit only if parser returns Some
|
// Commit only if parser returns Some
|
||||||
fn read_atomically<T>(&mut self, cb: &fn(&mut Parser) -> Option<T>) -> Option<T> {
|
fn read_atomically<T>(&mut self, cb: |&mut Parser| -> Option<T>)
|
||||||
|
-> Option<T> {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
let r = cb(self);
|
let r = cb(self);
|
||||||
if r.is_none() {
|
if r.is_none() {
|
||||||
@ -91,14 +92,16 @@ impl<'self> Parser<'self> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Commit only if parser read till EOF
|
// Commit only if parser read till EOF
|
||||||
fn read_till_eof<T>(&mut self, cb: &fn(&mut Parser) -> Option<T>) -> Option<T> {
|
fn read_till_eof<T>(&mut self, cb: |&mut Parser| -> Option<T>)
|
||||||
|
-> Option<T> {
|
||||||
do self.read_atomically |p| {
|
do self.read_atomically |p| {
|
||||||
cb(p).filtered(|_| p.is_eof())
|
cb(p).filtered(|_| p.is_eof())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return result of first successful parser
|
// Return result of first successful parser
|
||||||
fn read_or<T>(&mut self, parsers: &[&fn(&mut Parser) -> Option<T>]) -> Option<T> {
|
fn read_or<T>(&mut self, parsers: &[|&mut Parser| -> Option<T>])
|
||||||
|
-> Option<T> {
|
||||||
for pf in parsers.iter() {
|
for pf in parsers.iter() {
|
||||||
match self.read_atomically(|p: &mut Parser| (*pf)(p)) {
|
match self.read_atomically(|p: &mut Parser| (*pf)(p)) {
|
||||||
Some(r) => return Some(r),
|
Some(r) => return Some(r),
|
||||||
@ -109,12 +112,14 @@ impl<'self> Parser<'self> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply 3 parsers sequentially
|
// Apply 3 parsers sequentially
|
||||||
fn read_seq_3<A, B, C>(&mut self,
|
fn read_seq_3<A,
|
||||||
pa: &fn(&mut Parser) -> Option<A>,
|
B,
|
||||||
pb: &fn(&mut Parser) -> Option<B>,
|
C>(
|
||||||
pc: &fn(&mut Parser) -> Option<C>
|
&mut self,
|
||||||
) -> Option<(A, B, C)>
|
pa: |&mut Parser| -> Option<A>,
|
||||||
{
|
pb: |&mut Parser| -> Option<B>,
|
||||||
|
pc: |&mut Parser| -> Option<C>)
|
||||||
|
-> Option<(A, B, C)> {
|
||||||
do self.read_atomically |p| {
|
do self.read_atomically |p| {
|
||||||
let a = pa(p);
|
let a = pa(p);
|
||||||
let b = if a.is_some() { pb(p) } else { None };
|
let b = if a.is_some() { pb(p) } else { None };
|
||||||
|
@ -74,7 +74,9 @@ pub struct UdpStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl UdpStream {
|
impl UdpStream {
|
||||||
pub fn as_socket<T>(&mut self, f: &fn(&mut UdpSocket) -> T) -> T { f(&mut self.socket) }
|
pub fn as_socket<T>(&mut self, f: |&mut UdpSocket| -> T) -> T {
|
||||||
|
f(&mut self.socket)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn disconnect(self) -> UdpSocket { self.socket }
|
pub fn disconnect(self) -> UdpSocket { self.socket }
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ enum StdSource {
|
|||||||
File(~RtioFileStream),
|
File(~RtioFileStream),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn src<T>(fd: libc::c_int, readable: bool, f: &fn(StdSource) -> T) -> T {
|
fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {
|
||||||
do with_local_io |io| {
|
do with_local_io |io| {
|
||||||
let fd = unsafe { libc::dup(fd) };
|
let fd = unsafe { libc::dup(fd) };
|
||||||
match io.tty_open(fd, readable) {
|
match io.tty_open(fd, readable) {
|
||||||
@ -121,7 +121,7 @@ pub fn stderr() -> StdWriter {
|
|||||||
// // io1 aliases io2
|
// // io1 aliases io2
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
fn with_task_stdout(f: &fn(&mut Writer)) {
|
fn with_task_stdout(f: |&mut Writer|) {
|
||||||
use rt::local::Local;
|
use rt::local::Local;
|
||||||
use rt::task::Task;
|
use rt::task::Task;
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ pub trait Iterator<A> {
|
|||||||
/// range(0, 5).advance(|x| {print!("{} ", x); true});
|
/// range(0, 5).advance(|x| {print!("{} ", x); true});
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
fn advance(&mut self, f: &fn(A) -> bool) -> bool {
|
fn advance(&mut self, f: |A| -> bool) -> bool {
|
||||||
loop {
|
loop {
|
||||||
match self.next() {
|
match self.next() {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
@ -522,7 +522,7 @@ pub trait Iterator<A> {
|
|||||||
/// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
|
/// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fold<B>(&mut self, init: B, f: &fn(B, A) -> B) -> B {
|
fn fold<B>(&mut self, init: B, f: |B, A| -> B) -> B {
|
||||||
let mut accum = init;
|
let mut accum = init;
|
||||||
loop {
|
loop {
|
||||||
match self.next() {
|
match self.next() {
|
||||||
@ -558,7 +558,7 @@ pub trait Iterator<A> {
|
|||||||
/// assert!(!a.iter().all(|&x| *x > 2));
|
/// assert!(!a.iter().all(|&x| *x > 2));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
fn all(&mut self, f: &fn(A) -> bool) -> bool {
|
fn all(&mut self, f: |A| -> bool) -> bool {
|
||||||
for x in *self { if !f(x) { return false; } }
|
for x in *self { if !f(x) { return false; } }
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -575,14 +575,14 @@ pub trait Iterator<A> {
|
|||||||
/// assert!(!it.any(|&x| *x == 3));
|
/// assert!(!it.any(|&x| *x == 3));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
fn any(&mut self, f: &fn(A) -> bool) -> bool {
|
fn any(&mut self, f: |A| -> bool) -> bool {
|
||||||
for x in *self { if f(x) { return true; } }
|
for x in *self { if f(x) { return true; } }
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the first element satisfying the specified predicate
|
/// Return the first element satisfying the specified predicate
|
||||||
#[inline]
|
#[inline]
|
||||||
fn find(&mut self, predicate: &fn(&A) -> bool) -> Option<A> {
|
fn find(&mut self, predicate: |&A| -> bool) -> Option<A> {
|
||||||
for x in *self {
|
for x in *self {
|
||||||
if predicate(&x) { return Some(x) }
|
if predicate(&x) { return Some(x) }
|
||||||
}
|
}
|
||||||
@ -591,7 +591,7 @@ pub trait Iterator<A> {
|
|||||||
|
|
||||||
/// Return the index of the first element satisfying the specified predicate
|
/// Return the index of the first element satisfying the specified predicate
|
||||||
#[inline]
|
#[inline]
|
||||||
fn position(&mut self, predicate: &fn(A) -> bool) -> Option<uint> {
|
fn position(&mut self, predicate: |A| -> bool) -> Option<uint> {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for x in *self {
|
for x in *self {
|
||||||
if predicate(x) {
|
if predicate(x) {
|
||||||
@ -604,7 +604,7 @@ pub trait Iterator<A> {
|
|||||||
|
|
||||||
/// Count the number of elements satisfying the specified predicate
|
/// Count the number of elements satisfying the specified predicate
|
||||||
#[inline]
|
#[inline]
|
||||||
fn count(&mut self, predicate: &fn(A) -> bool) -> uint {
|
fn count(&mut self, predicate: |A| -> bool) -> uint {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for x in *self {
|
for x in *self {
|
||||||
if predicate(x) { i += 1 }
|
if predicate(x) { i += 1 }
|
||||||
@ -622,7 +622,7 @@ pub trait Iterator<A> {
|
|||||||
/// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10);
|
/// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
fn max_by<B: Ord>(&mut self, f: &fn(&A) -> B) -> Option<A> {
|
fn max_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A> {
|
||||||
self.fold(None, |max: Option<(A, B)>, x| {
|
self.fold(None, |max: Option<(A, B)>, x| {
|
||||||
let x_val = f(&x);
|
let x_val = f(&x);
|
||||||
match max {
|
match max {
|
||||||
@ -646,7 +646,7 @@ pub trait Iterator<A> {
|
|||||||
/// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0);
|
/// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
fn min_by<B: Ord>(&mut self, f: &fn(&A) -> B) -> Option<A> {
|
fn min_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A> {
|
||||||
self.fold(None, |min: Option<(A, B)>, x| {
|
self.fold(None, |min: Option<(A, B)>, x| {
|
||||||
let x_val = f(&x);
|
let x_val = f(&x);
|
||||||
match min {
|
match min {
|
||||||
@ -729,7 +729,7 @@ pub trait ExactSize<A> : DoubleEndedIterator<A> {
|
|||||||
///
|
///
|
||||||
/// If no element matches, None is returned.
|
/// If no element matches, None is returned.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rposition(&mut self, predicate: &fn(A) -> bool) -> Option<uint> {
|
fn rposition(&mut self, predicate: |A| -> bool) -> Option<uint> {
|
||||||
let (lower, upper) = self.size_hint();
|
let (lower, upper) = self.size_hint();
|
||||||
assert!(upper == Some(lower));
|
assert!(upper == Some(lower));
|
||||||
let mut i = lower;
|
let mut i = lower;
|
||||||
|
@ -177,7 +177,7 @@ pub fn pop<T: 'static>(key: Key<T>) -> Option<T> {
|
|||||||
///
|
///
|
||||||
/// It is considered a runtime error to attempt to get a value which is already
|
/// It is considered a runtime error to attempt to get a value which is already
|
||||||
/// on loan via the `get_mut` method provided.
|
/// on loan via the `get_mut` method provided.
|
||||||
pub fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U {
|
pub fn get<T: 'static, U>(key: Key<T>, f: |Option<&T>| -> U) -> U {
|
||||||
get_with(key, ImmLoan, f)
|
get_with(key, ImmLoan, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ pub fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U {
|
|||||||
/// It is considered a runtime error to attempt to get a value which is already
|
/// It is considered a runtime error to attempt to get a value which is already
|
||||||
/// on loan via this or the `get` methods. This is similar to how it's a runtime
|
/// on loan via this or the `get` methods. This is similar to how it's a runtime
|
||||||
/// error to take two mutable loans on an `@mut` box.
|
/// error to take two mutable loans on an `@mut` box.
|
||||||
pub fn get_mut<T: 'static, U>(key: Key<T>, f: &fn(Option<&mut T>) -> U) -> U {
|
pub fn get_mut<T: 'static, U>(key: Key<T>, f: |Option<&mut T>| -> U) -> U {
|
||||||
do get_with(key, MutLoan) |x| {
|
do get_with(key, MutLoan) |x| {
|
||||||
match x {
|
match x {
|
||||||
None => f(None),
|
None => f(None),
|
||||||
@ -202,9 +202,12 @@ pub fn get_mut<T: 'static, U>(key: Key<T>, f: &fn(Option<&mut T>) -> U) -> U {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_with<T: 'static, U>(key: Key<T>,
|
fn get_with<T:'static,
|
||||||
state: LoanState,
|
U>(
|
||||||
f: &fn(Option<&T>) -> U) -> U {
|
key: Key<T>,
|
||||||
|
state: LoanState,
|
||||||
|
f: |Option<&T>| -> U)
|
||||||
|
-> U {
|
||||||
// This function must be extremely careful. Because TLS can store owned
|
// This function must be extremely careful. Because TLS can store owned
|
||||||
// values, and we must have some form of `get` function other than `pop`,
|
// values, and we must have some form of `get` function other than `pop`,
|
||||||
// this function has to give a `&` reference back to the caller.
|
// this function has to give a `&` reference back to the caller.
|
||||||
@ -335,7 +338,7 @@ pub fn set<T: 'static>(key: Key<T>, data: T) {
|
|||||||
///
|
///
|
||||||
/// This function will have the same runtime errors as generated from `pop` and
|
/// This function will have the same runtime errors as generated from `pop` and
|
||||||
/// `set` (the key must not currently be on loan
|
/// `set` (the key must not currently be on loan
|
||||||
pub fn modify<T: 'static>(key: Key<T>, f: &fn(Option<T>) -> Option<T>) {
|
pub fn modify<T: 'static>(key: Key<T>, f: |Option<T>| -> Option<T>) {
|
||||||
match f(pop(key)) {
|
match f(pop(key)) {
|
||||||
Some(next) => { set(key, next); }
|
Some(next) => { set(key, next); }
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -415,7 +415,7 @@ impl FromStrRadix for $T {
|
|||||||
|
|
||||||
/// Convert to a string as a byte slice in a given base.
|
/// Convert to a string as a byte slice in a given base.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_str_bytes<U>(n: $T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
|
||||||
// The radix can be as low as 2, so we need at least 64 characters for a
|
// The radix can be as low as 2, so we need at least 64 characters for a
|
||||||
// base 2 number, and then we need another for a possible '-' character.
|
// base 2 number, and then we need another for a possible '-' character.
|
||||||
let mut buf = [0u8, ..65];
|
let mut buf = [0u8, ..65];
|
||||||
|
@ -108,7 +108,7 @@ pub trait Unsigned: Num {}
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
pub trait Times {
|
pub trait Times {
|
||||||
fn times(&self, it: &fn());
|
fn times(&self, it: ||);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Integer: Num
|
pub trait Integer: Num
|
||||||
|
@ -132,9 +132,19 @@ static NAN_BUF: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8];
|
|||||||
* # Failure
|
* # Failure
|
||||||
* - Fails if `radix` < 2 or `radix` > 36.
|
* - Fails if `radix` < 2 or `radix` > 36.
|
||||||
*/
|
*/
|
||||||
pub fn int_to_str_bytes_common<T:NumCast+Zero+Eq+Ord+Integer+
|
pub fn int_to_str_bytes_common<T:NumCast
|
||||||
Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>(
|
+Zero
|
||||||
num: T, radix: uint, sign: SignFormat, f: &fn(u8)) {
|
+Eq
|
||||||
|
+Ord
|
||||||
|
+Integer
|
||||||
|
+Div<T,T>
|
||||||
|
+Neg<T>
|
||||||
|
+Rem<T,T>
|
||||||
|
+Mul<T,T>>(
|
||||||
|
num: T,
|
||||||
|
radix: uint,
|
||||||
|
sign: SignFormat,
|
||||||
|
f: |u8|) {
|
||||||
assert!(2 <= radix && radix <= 36);
|
assert!(2 <= radix && radix <= 36);
|
||||||
|
|
||||||
let _0: T = Zero::zero();
|
let _0: T = Zero::zero();
|
||||||
|
@ -85,7 +85,7 @@ impl num::Times for uint {
|
|||||||
/// use with integer literals of inferred integer-type as
|
/// use with integer literals of inferred integer-type as
|
||||||
/// the self-value (eg. `do 100.times { ... }`).
|
/// the self-value (eg. `do 100.times { ... }`).
|
||||||
///
|
///
|
||||||
fn times(&self, it: &fn()) {
|
fn times(&self, it: ||) {
|
||||||
let mut i = *self;
|
let mut i = *self;
|
||||||
while i > 0 {
|
while i > 0 {
|
||||||
it();
|
it();
|
||||||
|
@ -266,7 +266,7 @@ impl FromStrRadix for $T {
|
|||||||
|
|
||||||
/// Convert to a string as a byte slice in a given base.
|
/// Convert to a string as a byte slice in a given base.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_str_bytes<U>(n: $T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
|
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
|
||||||
// The radix can be as low as 2, so we need at least 64 characters for a
|
// The radix can be as low as 2, so we need at least 64 characters for a
|
||||||
// base 2 number.
|
// base 2 number.
|
||||||
let mut buf = [0u8, ..64];
|
let mut buf = [0u8, ..64];
|
||||||
|
@ -147,7 +147,7 @@ impl<T> Option<T> {
|
|||||||
|
|
||||||
/// Returns the contained value or computes it from a closure
|
/// Returns the contained value or computes it from a closure
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unwrap_or_else(self, f: &fn() -> T) -> T {
|
pub fn unwrap_or_else(self, f: || -> T) -> T {
|
||||||
match self {
|
match self {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => f()
|
None => f()
|
||||||
@ -160,19 +160,19 @@ impl<T> Option<T> {
|
|||||||
|
|
||||||
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
|
/// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map<U>(self, f: &fn(T) -> U) -> Option<U> {
|
pub fn map<U>(self, f: |T| -> U) -> Option<U> {
|
||||||
match self { Some(x) => Some(f(x)), None => None }
|
match self { Some(x) => Some(f(x)), None => None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a function to the contained value or returns a default.
|
/// Applies a function to the contained value or returns a default.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map_default<U>(self, def: U, f: &fn(T) -> U) -> U {
|
pub fn map_default<U>(self, def: U, f: |T| -> U) -> U {
|
||||||
match self { None => def, Some(t) => f(t) }
|
match self { None => def, Some(t) => f(t) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a function to the contained value or do nothing.
|
/// Apply a function to the contained value or do nothing.
|
||||||
/// Returns true if the contained value was mutated.
|
/// Returns true if the contained value was mutated.
|
||||||
pub fn mutate(&mut self, f: &fn(T) -> T) -> bool {
|
pub fn mutate(&mut self, f: |T| -> T) -> bool {
|
||||||
if self.is_some() {
|
if self.is_some() {
|
||||||
*self = Some(f(self.take_unwrap()));
|
*self = Some(f(self.take_unwrap()));
|
||||||
true
|
true
|
||||||
@ -181,7 +181,7 @@ impl<T> Option<T> {
|
|||||||
|
|
||||||
/// Apply a function to the contained value or set it to a default.
|
/// Apply a function to the contained value or set it to a default.
|
||||||
/// Returns true if the contained value was mutated, or false if set to the default.
|
/// Returns true if the contained value was mutated, or false if set to the default.
|
||||||
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool {
|
pub fn mutate_default(&mut self, def: T, f: |T| -> T) -> bool {
|
||||||
if self.is_some() {
|
if self.is_some() {
|
||||||
*self = Some(f(self.take_unwrap()));
|
*self = Some(f(self.take_unwrap()));
|
||||||
true
|
true
|
||||||
@ -235,7 +235,7 @@ impl<T> Option<T> {
|
|||||||
/// Returns `None` if the option is `None`, otherwise calls `f` with the
|
/// Returns `None` if the option is `None`, otherwise calls `f` with the
|
||||||
/// wrapped value and returns the result.
|
/// wrapped value and returns the result.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn and_then<U>(self, f: &fn(T) -> Option<U>) -> Option<U> {
|
pub fn and_then<U>(self, f: |T| -> Option<U>) -> Option<U> {
|
||||||
match self {
|
match self {
|
||||||
Some(x) => f(x),
|
Some(x) => f(x),
|
||||||
None => None,
|
None => None,
|
||||||
@ -254,7 +254,7 @@ impl<T> Option<T> {
|
|||||||
/// Returns the option if it contains a value, otherwise calls `f` and
|
/// Returns the option if it contains a value, otherwise calls `f` and
|
||||||
/// returns the result.
|
/// returns the result.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn or_else(self, f: &fn() -> Option<T>) -> Option<T> {
|
pub fn or_else(self, f: || -> Option<T>) -> Option<T> {
|
||||||
match self {
|
match self {
|
||||||
Some(_) => self,
|
Some(_) => self,
|
||||||
None => f(),
|
None => f(),
|
||||||
@ -273,7 +273,7 @@ impl<T> Option<T> {
|
|||||||
|
|
||||||
/// Filters an optional value using a given function.
|
/// Filters an optional value using a given function.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option<T> {
|
pub fn filtered(self, f: |t: &T| -> bool) -> Option<T> {
|
||||||
match self {
|
match self {
|
||||||
Some(x) => if(f(&x)) {Some(x)} else {None},
|
Some(x) => if(f(&x)) {Some(x)} else {None},
|
||||||
None => None
|
None => None
|
||||||
@ -282,7 +282,7 @@ impl<T> Option<T> {
|
|||||||
|
|
||||||
/// Applies a function zero or more times until the result is `None`.
|
/// Applies a function zero or more times until the result is `None`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn while_some(self, blk: &fn(v: T) -> Option<T>) {
|
pub fn while_some(self, blk: |v: T| -> Option<T>) {
|
||||||
let mut opt = self;
|
let mut opt = self;
|
||||||
while opt.is_some() {
|
while opt.is_some() {
|
||||||
opt = blk(opt.unwrap());
|
opt = blk(opt.unwrap());
|
||||||
|
@ -94,7 +94,7 @@ pub mod win32 {
|
|||||||
use os::TMPBUF_SZ;
|
use os::TMPBUF_SZ;
|
||||||
use libc::types::os::arch::extra::DWORD;
|
use libc::types::os::arch::extra::DWORD;
|
||||||
|
|
||||||
pub fn fill_utf16_buf_and_decode(f: &fn(*mut u16, DWORD) -> DWORD)
|
pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD)
|
||||||
-> Option<~str> {
|
-> Option<~str> {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -125,7 +125,7 @@ pub mod win32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_utf16_p<T>(s: &str, f: &fn(*u16) -> T) -> T {
|
pub fn as_utf16_p<T>(s: &str, f: |*u16| -> T) -> T {
|
||||||
let mut t = s.to_utf16();
|
let mut t = s.to_utf16();
|
||||||
// Null terminate before passing on.
|
// Null terminate before passing on.
|
||||||
t.push(0u16);
|
t.push(0u16);
|
||||||
@ -137,7 +137,7 @@ pub mod win32 {
|
|||||||
Accessing environment variables is not generally threadsafe.
|
Accessing environment variables is not generally threadsafe.
|
||||||
Serialize access through a global lock.
|
Serialize access through a global lock.
|
||||||
*/
|
*/
|
||||||
fn with_env_lock<T>(f: &fn() -> T) -> T {
|
fn with_env_lock<T>(f: || -> T) -> T {
|
||||||
use unstable::mutex::{Mutex, MUTEX_INIT};
|
use unstable::mutex::{Mutex, MUTEX_INIT};
|
||||||
use unstable::finally::Finally;
|
use unstable::finally::Finally;
|
||||||
|
|
||||||
|
@ -559,7 +559,7 @@ impl<'self, P: GenericPath> Display<'self, P> {
|
|||||||
/// If the path is not UTF-8, invalid sequences will be replaced with the
|
/// If the path is not UTF-8, invalid sequences will be replaced with the
|
||||||
/// unicode replacement char. This involves allocation.
|
/// unicode replacement char. This involves allocation.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_str<T>(&self, f: &fn(&str) -> T) -> T {
|
pub fn with_str<T>(&self, f: |&str| -> T) -> T {
|
||||||
let opt = if self.filename { self.path.filename_str() }
|
let opt = if self.filename { self.path.filename_str() }
|
||||||
else { self.path.as_str() };
|
else { self.path.as_str() };
|
||||||
match opt {
|
match opt {
|
||||||
|
@ -87,7 +87,7 @@ impl ToCStr for Path {
|
|||||||
|
|
||||||
impl IterBytes for Path {
|
impl IterBytes for Path {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter_bytes(&self, lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool {
|
fn iter_bytes(&self, lsb0: bool, f: |buf: &[u8]| -> bool) -> bool {
|
||||||
self.repr.iter_bytes(lsb0, f)
|
self.repr.iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ impl ToCStr for Path {
|
|||||||
|
|
||||||
impl IterBytes for Path {
|
impl IterBytes for Path {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter_bytes(&self, lsb0: bool, f: &fn(&[u8]) -> bool) -> bool {
|
fn iter_bytes(&self, lsb0: bool, f: |&[u8]| -> bool) -> bool {
|
||||||
self.repr.iter_bytes(lsb0, f)
|
self.repr.iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -970,7 +970,8 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> {
|
|||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
|
|
||||||
fn parse_two_comps<'a>(mut path: &'a str, f: &fn(char)->bool) -> Option<(uint, uint)> {
|
fn parse_two_comps<'a>(mut path: &'a str, f: |char| -> bool)
|
||||||
|
-> Option<(uint, uint)> {
|
||||||
let idx_a = match path.find(|x| f(x)) {
|
let idx_a = match path.find(|x| f(x)) {
|
||||||
None => return None,
|
None => return None,
|
||||||
Some(x) => x
|
Some(x) => x
|
||||||
|
@ -56,7 +56,7 @@ impl<T> Clone for *mut T {
|
|||||||
|
|
||||||
/// Return the first offset `i` such that `f(buf[i]) == true`.
|
/// Return the first offset `i` such that `f(buf[i]) == true`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
|
pub unsafe fn position<T>(buf: *T, f: |&T| -> bool) -> uint {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
if f(&(*offset(buf, i as int))) { return i; }
|
if f(&(*offset(buf, i as int))) { return i; }
|
||||||
@ -195,7 +195,7 @@ pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
|||||||
|
|
||||||
SAFETY NOTE: Pointer-arithmetic. Dragons be here.
|
SAFETY NOTE: Pointer-arithmetic. Dragons be here.
|
||||||
*/
|
*/
|
||||||
pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: &fn(*T)) {
|
pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
|
||||||
debug!("array_each_with_len: before iterate");
|
debug!("array_each_with_len: before iterate");
|
||||||
if (arr as uint == 0) {
|
if (arr as uint == 0) {
|
||||||
fail!("ptr::array_each_with_len failure: arr input is null pointer");
|
fail!("ptr::array_each_with_len failure: arr input is null pointer");
|
||||||
@ -217,7 +217,7 @@ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: &fn(*T)) {
|
|||||||
pointer array. Barely less-dodgy Pointer Arithmetic.
|
pointer array. Barely less-dodgy Pointer Arithmetic.
|
||||||
Dragons be here.
|
Dragons be here.
|
||||||
*/
|
*/
|
||||||
pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
|
pub unsafe fn array_each<T>(arr: **T, cb: |*T|) {
|
||||||
if (arr as uint == 0) {
|
if (arr as uint == 0) {
|
||||||
fail!("ptr::array_each_with_len failure: arr input is null pointer");
|
fail!("ptr::array_each_with_len failure: arr input is null pointer");
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ impl<T> RcMut<T> {
|
|||||||
impl<T> RcMut<T> {
|
impl<T> RcMut<T> {
|
||||||
/// Fails if there is already a mutable borrow of the box
|
/// Fails if there is already a mutable borrow of the box
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_borrow<U>(&self, f: &fn(&T) -> U) -> U {
|
pub fn with_borrow<U>(&self, f: |&T| -> U) -> U {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!((*self.ptr).borrow != Mutable);
|
assert!((*self.ptr).borrow != Mutable);
|
||||||
let previous = (*self.ptr).borrow;
|
let previous = (*self.ptr).borrow;
|
||||||
@ -216,7 +216,7 @@ impl<T> RcMut<T> {
|
|||||||
|
|
||||||
/// Fails if there is already a mutable or immutable borrow of the box
|
/// Fails if there is already a mutable or immutable borrow of the box
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_mut_borrow<U>(&self, f: &fn(&mut T) -> U) -> U {
|
pub fn with_mut_borrow<U>(&self, f: |&mut T| -> U) -> U {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert_eq!((*self.ptr).borrow, Nothing);
|
assert_eq!((*self.ptr).borrow, Nothing);
|
||||||
(*self.ptr).borrow = Mutable;
|
(*self.ptr).borrow = Mutable;
|
||||||
|
@ -28,7 +28,7 @@ use unstable::raw;
|
|||||||
* then build a MovePtrAdaptor wrapped around your struct.
|
* then build a MovePtrAdaptor wrapped around your struct.
|
||||||
*/
|
*/
|
||||||
pub trait MovePtr {
|
pub trait MovePtr {
|
||||||
fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void);
|
fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void);
|
||||||
fn push_ptr(&mut self);
|
fn push_ptr(&mut self);
|
||||||
fn pop_ptr(&mut self);
|
fn pop_ptr(&mut self);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ pub fn ReprVisitor<'a>(ptr: *c_void,
|
|||||||
|
|
||||||
impl<'self> MovePtr for ReprVisitor<'self> {
|
impl<'self> MovePtr for ReprVisitor<'self> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void) {
|
fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void) {
|
||||||
self.ptr = adjustment(self.ptr);
|
self.ptr = adjustment(self.ptr);
|
||||||
}
|
}
|
||||||
fn push_ptr(&mut self) {
|
fn push_ptr(&mut self) {
|
||||||
@ -131,7 +131,7 @@ impl<'self> ReprVisitor<'self> {
|
|||||||
// Various helpers for the TyVisitor impl
|
// Various helpers for the TyVisitor impl
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get<T>(&mut self, f: &fn(&mut ReprVisitor, &T)) -> bool {
|
pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T|) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
f(self, transmute::<*c_void,&T>(self.ptr));
|
f(self, transmute::<*c_void,&T>(self.ptr));
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ impl<T, E: ToStr> Result<T, E> {
|
|||||||
/// parse_bytes(buf)
|
/// parse_bytes(buf)
|
||||||
/// }
|
/// }
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map<U>(self, op: &fn(T) -> U) -> Result<U,E> {
|
pub fn map<U>(self, op: |T| -> U) -> Result<U,E> {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => Ok(op(t)),
|
Ok(t) => Ok(op(t)),
|
||||||
Err(e) => Err(e)
|
Err(e) => Err(e)
|
||||||
@ -156,7 +156,7 @@ impl<T, E: ToStr> Result<T, E> {
|
|||||||
/// This function can be used to pass through a successful result while handling
|
/// This function can be used to pass through a successful result while handling
|
||||||
/// an error.
|
/// an error.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map_err<F>(self, op: &fn(E) -> F) -> Result<T,F> {
|
pub fn map_err<F>(self, op: |E| -> F) -> Result<T,F> {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
Err(e) => Err(op(e))
|
Err(e) => Err(op(e))
|
||||||
@ -208,7 +208,7 @@ impl<T, E: ToStr> Result<T, E> {
|
|||||||
///
|
///
|
||||||
/// This function can be used for control flow based on result values
|
/// This function can be used for control flow based on result values
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn and_then<U>(self, op: &fn(T) -> Result<U, E>) -> Result<U, E> {
|
pub fn and_then<U>(self, op: |T| -> Result<U, E>) -> Result<U, E> {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => op(t),
|
Ok(t) => op(t),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
@ -228,7 +228,7 @@ impl<T, E: ToStr> Result<T, E> {
|
|||||||
///
|
///
|
||||||
/// This function can be used for control flow based on result values
|
/// This function can be used for control flow based on result values
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn or_else<F>(self, op: &fn(E) -> Result<T, F>) -> Result<T, F> {
|
pub fn or_else<F>(self, op: |E| -> Result<T, F>) -> Result<T, F> {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
Err(e) => op(e),
|
Err(e) => op(e),
|
||||||
@ -378,12 +378,14 @@ pub fn collect<T, E, Iter: Iterator<Result<T, E>>>(mut iterator: Iter)
|
|||||||
/// If an `Err` is encountered, it is immediately returned.
|
/// If an `Err` is encountered, it is immediately returned.
|
||||||
/// Otherwise, the folded value is returned.
|
/// Otherwise, the folded value is returned.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fold<T, V, E,
|
pub fn fold<T,
|
||||||
|
V,
|
||||||
|
E,
|
||||||
Iter: Iterator<Result<T, E>>>(
|
Iter: Iterator<Result<T, E>>>(
|
||||||
mut iterator: Iter,
|
mut iterator: Iter,
|
||||||
mut init: V,
|
mut init: V,
|
||||||
f: &fn(V, T) -> V)
|
f: |V, T| -> V)
|
||||||
-> Result<V, E> {
|
-> Result<V, E> {
|
||||||
for t in iterator {
|
for t in iterator {
|
||||||
match t {
|
match t {
|
||||||
Ok(v) => init = f(init, v),
|
Ok(v) => init = f(init, v),
|
||||||
@ -399,9 +401,7 @@ pub fn fold<T, V, E,
|
|||||||
/// If an `Err` is encountered, it is immediately returned.
|
/// If an `Err` is encountered, it is immediately returned.
|
||||||
/// Otherwise, a simple `Ok(())` is returned.
|
/// Otherwise, a simple `Ok(())` is returned.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fold_<T, E, Iter: Iterator<Result<T, E>>>(
|
pub fn fold_<T,E,Iter:Iterator<Result<T,E>>>(iterator: Iter) -> Result<(),E> {
|
||||||
iterator: Iter)
|
|
||||||
-> Result<(), E> {
|
|
||||||
fold(iterator, (), |_, _| ())
|
fold(iterator, (), |_, _| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,8 @@ mod imp {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_lock<T>(f: &fn() -> T) -> T {
|
fn with_lock<T>(f: || -> T) -> T {
|
||||||
static mut lock: Mutex = MUTEX_INIT;
|
static mut lock: Mutex = MUTEX_INIT;
|
||||||
|
|
||||||
do (|| {
|
do (|| {
|
||||||
unsafe {
|
unsafe {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
@ -170,7 +170,7 @@ impl EventLoop for BasicLoop {
|
|||||||
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback
|
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)) {
|
fn io<'a>(&'a mut self, f: |&'a mut IoFactory|) {
|
||||||
f(self.io)
|
f(self.io)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ fn try_take_task_borrow_list() -> Option<~[BorrowRecord]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
|
fn swap_task_borrow_list(f: |~[BorrowRecord]| -> ~[BorrowRecord]) {
|
||||||
let borrows = match try_take_task_borrow_list() {
|
let borrows = match try_take_task_borrow_list() {
|
||||||
Some(l) => l,
|
Some(l) => l,
|
||||||
None => ~[]
|
None => ~[]
|
||||||
|
@ -79,8 +79,10 @@ fn version(crate_map: &CrateMap) -> i32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry),
|
fn do_iter_crate_map<'a>(
|
||||||
visited: &mut HashSet<*CrateMap<'a>>) {
|
crate_map: &'a CrateMap<'a>,
|
||||||
|
f: |&ModEntry|,
|
||||||
|
visited: &mut HashSet<*CrateMap<'a>>) {
|
||||||
if visited.insert(crate_map as *CrateMap) {
|
if visited.insert(crate_map as *CrateMap) {
|
||||||
match version(crate_map) {
|
match version(crate_map) {
|
||||||
2 => {
|
2 => {
|
||||||
@ -98,7 +100,7 @@ fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Iterates recursively over `crate_map` and all child crate maps
|
/// Iterates recursively over `crate_map` and all child crate maps
|
||||||
pub fn iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry)) {
|
pub fn iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: |&ModEntry|) {
|
||||||
// XXX: use random numbers as keys from the OS-level RNG when there is a nice
|
// XXX: use random numbers as keys from the OS-level RNG when there is a nice
|
||||||
// way to do this
|
// way to do this
|
||||||
let mut v: HashSet<*CrateMap<'a>> = HashSet::with_capacity_and_keys(0, 0, 32);
|
let mut v: HashSet<*CrateMap<'a>> = HashSet::with_capacity_and_keys(0, 0, 32);
|
||||||
|
@ -369,7 +369,7 @@ impl BlockedTask {
|
|||||||
|
|
||||||
// So that KillHandle can be hashed in the taskgroup bookkeeping code.
|
// So that KillHandle can be hashed in the taskgroup bookkeeping code.
|
||||||
impl IterBytes for KillHandle {
|
impl IterBytes for KillHandle {
|
||||||
fn iter_bytes(&self, lsb0: bool, f: &fn(buf: &[u8]) -> bool) -> bool {
|
fn iter_bytes(&self, lsb0: bool, f: |buf: &[u8]| -> bool) -> bool {
|
||||||
self.data.iter_bytes(lsb0, f)
|
self.data.iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,9 +525,8 @@ impl KillHandle {
|
|||||||
// NB: Takes a pthread mutex -- 'blk' not allowed to reschedule.
|
// NB: Takes a pthread mutex -- 'blk' not allowed to reschedule.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add_lazy_tombstone(parent: &mut KillHandle,
|
fn add_lazy_tombstone(parent: &mut KillHandle,
|
||||||
blk: &fn(Option<proc() -> bool>)
|
blk: |Option<proc() -> bool>| -> proc() -> bool)
|
||||||
-> proc() -> bool) {
|
{
|
||||||
|
|
||||||
let inner: &mut KillHandleInner = unsafe { &mut *parent.get() };
|
let inner: &mut KillHandleInner = unsafe { &mut *parent.get() };
|
||||||
unsafe {
|
unsafe {
|
||||||
do inner.graveyard_lock.lock {
|
do inner.graveyard_lock.lock {
|
||||||
|
@ -18,7 +18,7 @@ pub trait Local {
|
|||||||
fn put(value: ~Self);
|
fn put(value: ~Self);
|
||||||
fn take() -> ~Self;
|
fn take() -> ~Self;
|
||||||
fn exists(unused_value: Option<Self>) -> bool;
|
fn exists(unused_value: Option<Self>) -> bool;
|
||||||
fn borrow<T>(f: &fn(&mut Self) -> T) -> T;
|
fn borrow<T>(f: |&mut Self| -> T) -> T;
|
||||||
unsafe fn unsafe_take() -> ~Self;
|
unsafe fn unsafe_take() -> ~Self;
|
||||||
unsafe fn unsafe_borrow() -> *mut Self;
|
unsafe fn unsafe_borrow() -> *mut Self;
|
||||||
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
|
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
|
||||||
@ -30,7 +30,7 @@ impl Local for Task {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn take() -> ~Task { unsafe { local_ptr::take() } }
|
fn take() -> ~Task { unsafe { local_ptr::take() } }
|
||||||
fn exists(_: Option<Task>) -> bool { local_ptr::exists() }
|
fn exists(_: Option<Task>) -> bool { local_ptr::exists() }
|
||||||
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
|
fn borrow<T>(f: |&mut Task| -> T) -> T {
|
||||||
let mut res: Option<T> = None;
|
let mut res: Option<T> = None;
|
||||||
let res_ptr: *mut Option<T> = &mut res;
|
let res_ptr: *mut Option<T> = &mut res;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -78,7 +78,7 @@ impl Local for Scheduler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn borrow<T>(f: &fn(&mut Scheduler) -> T) -> T {
|
fn borrow<T>(f: |&mut Scheduler| -> T) -> T {
|
||||||
do Local::borrow |task: &mut Task| {
|
do Local::borrow |task: &mut Task| {
|
||||||
match task.sched {
|
match task.sched {
|
||||||
Some(~ref mut task) => {
|
Some(~ref mut task) => {
|
||||||
|
@ -103,7 +103,7 @@ pub fn exists() -> bool {
|
|||||||
/// # Safety note
|
/// # Safety note
|
||||||
///
|
///
|
||||||
/// Does not validate the pointer type.
|
/// Does not validate the pointer type.
|
||||||
pub unsafe fn borrow<T>(f: &fn(&mut T)) {
|
pub unsafe fn borrow<T>(f: |&mut T|) {
|
||||||
let mut value = take();
|
let mut value = take();
|
||||||
|
|
||||||
// XXX: Need a different abstraction from 'finally' here to avoid unsafety
|
// XXX: Need a different abstraction from 'finally' here to avoid unsafety
|
||||||
|
@ -36,7 +36,7 @@ pub trait EventLoop {
|
|||||||
|
|
||||||
/// The asynchronous I/O services. Not all event loops may provide one
|
/// The asynchronous I/O services. Not all event loops may provide one
|
||||||
// FIXME(#9382) this is an awful interface
|
// FIXME(#9382) this is an awful interface
|
||||||
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory));
|
fn io<'a>(&'a mut self, f: |&'a mut IoFactory|);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RemoteCallback {
|
pub trait RemoteCallback {
|
||||||
@ -75,7 +75,7 @@ pub enum CloseBehavior {
|
|||||||
CloseAsynchronously,
|
CloseAsynchronously,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_local_io<T>(f: &fn(&mut IoFactory) -> Option<T>) -> Option<T> {
|
pub fn with_local_io<T>(f: |&mut IoFactory| -> Option<T>) -> Option<T> {
|
||||||
use rt::sched::Scheduler;
|
use rt::sched::Scheduler;
|
||||||
use rt::local::Local;
|
use rt::local::Local;
|
||||||
use io::native;
|
use io::native;
|
||||||
|
@ -556,7 +556,7 @@ impl Scheduler {
|
|||||||
|
|
||||||
pub fn change_task_context(mut ~self,
|
pub fn change_task_context(mut ~self,
|
||||||
next_task: ~Task,
|
next_task: ~Task,
|
||||||
f: &fn(&mut Scheduler, ~Task)) {
|
f: |&mut Scheduler, ~Task|) {
|
||||||
// The current task is grabbed from TLS, not taken as an input.
|
// The current task is grabbed from TLS, not taken as an input.
|
||||||
// Doing an unsafe_take to avoid writing back a null pointer -
|
// Doing an unsafe_take to avoid writing back a null pointer -
|
||||||
// We're going to call `put` later to do that.
|
// We're going to call `put` later to do that.
|
||||||
@ -568,8 +568,8 @@ impl Scheduler {
|
|||||||
|
|
||||||
// These transmutes do something fishy with a closure.
|
// These transmutes do something fishy with a closure.
|
||||||
let f_fake_region = unsafe {
|
let f_fake_region = unsafe {
|
||||||
transmute::<&fn(&mut Scheduler, ~Task),
|
transmute::<|&mut Scheduler, ~Task|,
|
||||||
&fn(&mut Scheduler, ~Task)>(f)
|
|&mut Scheduler, ~Task|>(f)
|
||||||
};
|
};
|
||||||
let f_opaque = ClosureConverter::from_fn(f_fake_region);
|
let f_opaque = ClosureConverter::from_fn(f_fake_region);
|
||||||
|
|
||||||
@ -678,7 +678,7 @@ impl Scheduler {
|
|||||||
/// in order to prevent that fn from performing further scheduling operations.
|
/// in order to prevent that fn from performing further scheduling operations.
|
||||||
/// Doing further scheduling could easily result in infinite recursion.
|
/// Doing further scheduling could easily result in infinite recursion.
|
||||||
pub fn deschedule_running_task_and_then(mut ~self,
|
pub fn deschedule_running_task_and_then(mut ~self,
|
||||||
f: &fn(&mut Scheduler, BlockedTask)) {
|
f: |&mut Scheduler, BlockedTask|) {
|
||||||
// Trickier - we need to get the scheduler task out of self
|
// Trickier - we need to get the scheduler task out of self
|
||||||
// and use it as the destination.
|
// and use it as the destination.
|
||||||
let stask = self.sched_task.take_unwrap();
|
let stask = self.sched_task.take_unwrap();
|
||||||
@ -687,7 +687,7 @@ impl Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn switch_running_tasks_and_then(~self, next_task: ~Task,
|
pub fn switch_running_tasks_and_then(~self, next_task: ~Task,
|
||||||
f: &fn(&mut Scheduler, BlockedTask)) {
|
f: |&mut Scheduler, BlockedTask|) {
|
||||||
// This is where we convert the BlockedTask-taking closure into one
|
// This is where we convert the BlockedTask-taking closure into one
|
||||||
// that takes just a Task, and is aware of the block-or-killed protocol.
|
// that takes just a Task, and is aware of the block-or-killed protocol.
|
||||||
do self.change_task_context(next_task) |sched, task| {
|
do self.change_task_context(next_task) |sched, task| {
|
||||||
@ -829,18 +829,18 @@ impl CleanupJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: Some hacks to put a &fn in Scheduler without borrowck
|
// XXX: Some hacks to put a || closure in Scheduler without borrowck
|
||||||
// complaining
|
// complaining
|
||||||
type UnsafeTaskReceiver = raw::Closure;
|
type UnsafeTaskReceiver = raw::Closure;
|
||||||
trait ClosureConverter {
|
trait ClosureConverter {
|
||||||
fn from_fn(&fn(&mut Scheduler, ~Task)) -> Self;
|
fn from_fn(|&mut Scheduler, ~Task|) -> Self;
|
||||||
fn to_fn(self) -> &fn(&mut Scheduler, ~Task);
|
fn to_fn(self) -> |&mut Scheduler, ~Task|;
|
||||||
}
|
}
|
||||||
impl ClosureConverter for UnsafeTaskReceiver {
|
impl ClosureConverter for UnsafeTaskReceiver {
|
||||||
fn from_fn(f: &fn(&mut Scheduler, ~Task)) -> UnsafeTaskReceiver {
|
fn from_fn(f: |&mut Scheduler, ~Task|) -> UnsafeTaskReceiver {
|
||||||
unsafe { transmute(f) }
|
unsafe { transmute(f) }
|
||||||
}
|
}
|
||||||
fn to_fn(self) -> &fn(&mut Scheduler, ~Task) { unsafe { transmute(self) } }
|
fn to_fn(self) -> |&mut Scheduler, ~Task| { unsafe { transmute(self) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
// On unix, we read randomness straight from /dev/urandom, but the
|
// On unix, we read randomness straight from /dev/urandom, but the
|
||||||
|
@ -282,7 +282,7 @@ impl Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self, f: &fn()) {
|
pub fn run(&mut self, f: ||) {
|
||||||
rtdebug!("run called on task: {}", borrow::to_uint(self));
|
rtdebug!("run called on task: {}", borrow::to_uint(self));
|
||||||
|
|
||||||
// The only try/catch block in the world. Attempt to run the task's
|
// The only try/catch block in the world. Attempt to run the task's
|
||||||
@ -494,7 +494,7 @@ impl Coroutine {
|
|||||||
static UNWIND_TOKEN: uintptr_t = 839147;
|
static UNWIND_TOKEN: uintptr_t = 839147;
|
||||||
|
|
||||||
impl Unwinder {
|
impl Unwinder {
|
||||||
pub fn try(&mut self, f: &fn()) {
|
pub fn try(&mut self, f: ||) {
|
||||||
use unstable::raw::Closure;
|
use unstable::raw::Closure;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -512,7 +512,7 @@ impl Unwinder {
|
|||||||
code: transmute(code),
|
code: transmute(code),
|
||||||
env: transmute(env),
|
env: transmute(env),
|
||||||
};
|
};
|
||||||
let closure: &fn() = transmute(closure);
|
let closure: || = transmute(closure);
|
||||||
closure();
|
closure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -925,7 +925,7 @@ pub fn is_utf16(v: &[u16]) -> bool {
|
|||||||
/// # Failures
|
/// # Failures
|
||||||
///
|
///
|
||||||
/// * Fails on invalid utf-16 data
|
/// * Fails on invalid utf-16 data
|
||||||
pub fn utf16_chars(v: &[u16], f: &fn(char)) {
|
pub fn utf16_chars(v: &[u16], f: |char|) {
|
||||||
let len = v.len();
|
let len = v.len();
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
while (i < len && v[i] != 0u16) {
|
while (i < len && v[i] != 0u16) {
|
||||||
@ -1762,7 +1762,7 @@ pub trait StrSlice<'self> {
|
|||||||
/// Work with the byte buffer and length of a slice.
|
/// Work with the byte buffer and length of a slice.
|
||||||
///
|
///
|
||||||
/// The buffer does not have a null terminator.
|
/// The buffer does not have a null terminator.
|
||||||
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T;
|
fn as_imm_buf<T>(&self, f: |*u8, uint| -> T) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'self> StrSlice<'self> for &'self str {
|
impl<'self> StrSlice<'self> for &'self str {
|
||||||
@ -2268,7 +2268,7 @@ impl<'self> StrSlice<'self> for &'self str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T {
|
fn as_imm_buf<T>(&self, f: |*u8, uint| -> T) -> T {
|
||||||
let v: &[u8] = unsafe { cast::transmute(*self) };
|
let v: &[u8] = unsafe { cast::transmute(*self) };
|
||||||
v.as_imm_buf(f)
|
v.as_imm_buf(f)
|
||||||
}
|
}
|
||||||
@ -2355,7 +2355,7 @@ pub trait OwnedStr {
|
|||||||
///
|
///
|
||||||
/// The caller must make sure any mutations to this buffer keep the string
|
/// The caller must make sure any mutations to this buffer keep the string
|
||||||
/// valid UTF-8!
|
/// valid UTF-8!
|
||||||
fn as_mut_buf<T>(&mut self, f: &fn(*mut u8, uint) -> T) -> T;
|
fn as_mut_buf<T>(&mut self, f: |*mut u8, uint| -> T) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OwnedStr for ~str {
|
impl OwnedStr for ~str {
|
||||||
@ -2456,7 +2456,7 @@ impl OwnedStr for ~str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_buf<T>(&mut self, f: &fn(*mut u8, uint) -> T) -> T {
|
fn as_mut_buf<T>(&mut self, f: |*mut u8, uint| -> T) -> T {
|
||||||
unsafe {
|
unsafe {
|
||||||
raw::as_owned_vec(self).as_mut_buf(f)
|
raw::as_owned_vec(self).as_mut_buf(f)
|
||||||
}
|
}
|
||||||
|
@ -554,7 +554,7 @@ pub fn try<T:Send>(f: proc() -> T) -> Result<T, ~Any> {
|
|||||||
/* Lifecycle functions */
|
/* Lifecycle functions */
|
||||||
|
|
||||||
/// Read the name of the current task.
|
/// Read the name of the current task.
|
||||||
pub fn with_task_name<U>(blk: &fn(Option<&str>) -> U) -> U {
|
pub fn with_task_name<U>(blk: |Option<&str>| -> U) -> U {
|
||||||
use rt::task::Task;
|
use rt::task::Task;
|
||||||
|
|
||||||
if in_green_task_context() {
|
if in_green_task_context() {
|
||||||
@ -605,7 +605,7 @@ pub fn failing() -> bool {
|
|||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
pub fn unkillable<U>(f: &fn() -> U) -> U {
|
pub fn unkillable<U>(f: || -> U) -> U {
|
||||||
use rt::task::Task;
|
use rt::task::Task;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -640,7 +640,7 @@ pub fn unkillable<U>(f: &fn() -> U) -> U {
|
|||||||
* // Task is unkillable again
|
* // Task is unkillable again
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
pub fn rekillable<U>(f: &fn() -> U) -> U {
|
pub fn rekillable<U>(f: || -> U) -> U {
|
||||||
use rt::task::Task;
|
use rt::task::Task;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -1201,7 +1201,7 @@ fn test_spawn_sched_blocking() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn avoid_copying_the_body(spawnfn: &fn(v: proc())) {
|
fn avoid_copying_the_body(spawnfn: |v: proc()|) {
|
||||||
let (p, ch) = stream::<uint>();
|
let (p, ch) = stream::<uint>();
|
||||||
|
|
||||||
let x = ~1;
|
let x = ~1;
|
||||||
|
@ -164,15 +164,17 @@ struct AncestorList(Option<Exclusive<AncestorNode>>);
|
|||||||
|
|
||||||
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
|
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn access_group<U>(x: &TaskGroupArc, blk: &fn(TaskGroupInner) -> U) -> U {
|
fn access_group<U>(x: &TaskGroupArc, blk: |TaskGroupInner| -> U) -> U {
|
||||||
unsafe {
|
unsafe {
|
||||||
x.with(blk)
|
x.with(blk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn access_ancestors<U>(x: &Exclusive<AncestorNode>,
|
fn access_ancestors<U>(
|
||||||
blk: &fn(x: &mut AncestorNode) -> U) -> U {
|
x: &Exclusive<AncestorNode>,
|
||||||
|
blk: |x: &mut AncestorNode| -> U)
|
||||||
|
-> U {
|
||||||
unsafe {
|
unsafe {
|
||||||
x.with(blk)
|
x.with(blk)
|
||||||
}
|
}
|
||||||
@ -197,17 +199,17 @@ fn incr_generation(_ancestors: &AncestorList) -> uint { 0 }
|
|||||||
// is NOT called on the block that forward_blk broke on!).
|
// is NOT called on the block that forward_blk broke on!).
|
||||||
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
|
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
|
||||||
fn each_ancestor(list: &mut AncestorList,
|
fn each_ancestor(list: &mut AncestorList,
|
||||||
bail_blk: &fn(TaskGroupInner),
|
bail_blk: |TaskGroupInner|,
|
||||||
forward_blk: &fn(TaskGroupInner) -> bool)
|
forward_blk: |TaskGroupInner| -> bool)
|
||||||
-> bool {
|
-> bool {
|
||||||
// "Kickoff" call - there was no last generation.
|
// "Kickoff" call - there was no last generation.
|
||||||
return !coalesce(list, bail_blk, forward_blk, uint::max_value);
|
return !coalesce(list, bail_blk, forward_blk, uint::max_value);
|
||||||
|
|
||||||
// Recursively iterates, and coalesces afterwards if needed. Returns
|
// Recursively iterates, and coalesces afterwards if needed. Returns
|
||||||
// whether or not unwinding is needed (i.e., !successful iteration).
|
// whether or not unwinding is needed (i.e., !successful iteration).
|
||||||
fn coalesce(list: &mut AncestorList,
|
fn coalesce(list: &mut AncestorList,
|
||||||
bail_blk: &fn(TaskGroupInner),
|
bail_blk: |TaskGroupInner|,
|
||||||
forward_blk: &fn(TaskGroupInner) -> bool,
|
forward_blk: |TaskGroupInner| -> bool,
|
||||||
last_generation: uint) -> bool {
|
last_generation: uint) -> bool {
|
||||||
let (coalesce_this, early_break) =
|
let (coalesce_this, early_break) =
|
||||||
iterate(list, bail_blk, forward_blk, last_generation);
|
iterate(list, bail_blk, forward_blk, last_generation);
|
||||||
@ -229,8 +231,8 @@ fn each_ancestor(list: &mut AncestorList,
|
|||||||
// True if the supplied block did 'break', here or in any recursive
|
// True if the supplied block did 'break', here or in any recursive
|
||||||
// calls. If so, must call the unwinder on all previous nodes.
|
// calls. If so, must call the unwinder on all previous nodes.
|
||||||
fn iterate(ancestors: &mut AncestorList,
|
fn iterate(ancestors: &mut AncestorList,
|
||||||
bail_blk: &fn(TaskGroupInner),
|
bail_blk: |TaskGroupInner|,
|
||||||
forward_blk: &fn(TaskGroupInner) -> bool,
|
forward_blk: |TaskGroupInner| -> bool,
|
||||||
last_generation: uint)
|
last_generation: uint)
|
||||||
-> (Option<AncestorList>, bool) {
|
-> (Option<AncestorList>, bool) {
|
||||||
// At each step of iteration, three booleans are at play which govern
|
// At each step of iteration, three booleans are at play which govern
|
||||||
@ -457,7 +459,7 @@ impl RuntimeGlue {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_task_handle_and_failing(blk: &fn(&KillHandle, bool)) {
|
fn with_task_handle_and_failing(blk: |&KillHandle, bool|) {
|
||||||
assert!(in_green_task_context());
|
assert!(in_green_task_context());
|
||||||
unsafe {
|
unsafe {
|
||||||
// Can't use safe borrow, because the taskgroup destructor needs to
|
// Can't use safe borrow, because the taskgroup destructor needs to
|
||||||
@ -467,7 +469,7 @@ impl RuntimeGlue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_my_taskgroup<U>(blk: &fn(&Taskgroup) -> U) -> U {
|
fn with_my_taskgroup<U>(blk: |&Taskgroup| -> U) -> U {
|
||||||
assert!(in_green_task_context());
|
assert!(in_green_task_context());
|
||||||
unsafe {
|
unsafe {
|
||||||
// Can't use safe borrow, because creating new hashmaps for the
|
// Can't use safe borrow, because creating new hashmaps for the
|
||||||
@ -545,7 +547,7 @@ fn enlist_many(child: &KillHandle, child_arc: &TaskGroupArc,
|
|||||||
};
|
};
|
||||||
if result {
|
if result {
|
||||||
// Unwinding function in case any ancestral enlisting fails
|
// Unwinding function in case any ancestral enlisting fails
|
||||||
let bail: &fn(TaskGroupInner) = |tg| { leave_taskgroup(tg, child, false) };
|
let bail: |TaskGroupInner| = |tg| { leave_taskgroup(tg, child, false) };
|
||||||
// Attempt to join every ancestor group.
|
// Attempt to join every ancestor group.
|
||||||
result = do each_ancestor(ancestors, bail) |ancestor_tg| {
|
result = do each_ancestor(ancestors, bail) |ancestor_tg| {
|
||||||
// Enlist as a descendant, not as an actual member.
|
// Enlist as a descendant, not as an actual member.
|
||||||
|
@ -107,43 +107,43 @@ impl<T> TrieMap<T> {
|
|||||||
|
|
||||||
/// Visit all key-value pairs in reverse order
|
/// Visit all key-value pairs in reverse order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
pub fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
|
||||||
self.root.each_reverse(f)
|
self.root.each_reverse(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all key-value pairs in order
|
/// Visit all key-value pairs in order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
pub fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
|
||||||
self.root.each(f)
|
self.root.each(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all keys in order
|
/// Visit all keys in order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each_key(&self, f: &fn(&uint) -> bool) -> bool {
|
pub fn each_key(&self, f: |&uint| -> bool) -> bool {
|
||||||
self.each(|k, _| f(k))
|
self.each(|k, _| f(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all values in order
|
/// Visit all values in order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) -> bool {
|
pub fn each_value<'a>(&'a self, f: |&'a T| -> bool) -> bool {
|
||||||
self.each(|_, v| f(v))
|
self.each(|_, v| f(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over the map and mutate the contained values
|
/// Iterate over the map and mutate the contained values
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
|
pub fn mutate_values(&mut self, f: |&uint, &mut T| -> bool) -> bool {
|
||||||
self.root.mutate_values(f)
|
self.root.mutate_values(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all keys in reverse order
|
/// Visit all keys in reverse order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool {
|
pub fn each_key_reverse(&self, f: |&uint| -> bool) -> bool {
|
||||||
self.each_reverse(|k, _| f(k))
|
self.each_reverse(|k, _| f(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all values in reverse order
|
/// Visit all values in reverse order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool {
|
pub fn each_value_reverse(&self, f: |&T| -> bool) -> bool {
|
||||||
self.each_reverse(|_, v| f(v))
|
self.each_reverse(|_, v| f(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,11 +266,11 @@ impl TrieSet {
|
|||||||
|
|
||||||
/// Visit all values in order
|
/// Visit all values in order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
|
pub fn each(&self, f: |&uint| -> bool) -> bool { self.map.each_key(f) }
|
||||||
|
|
||||||
/// Visit all values in reverse order
|
/// Visit all values in reverse order
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn each_reverse(&self, f: &fn(&uint) -> bool) -> bool {
|
pub fn each_reverse(&self, f: |&uint| -> bool) -> bool {
|
||||||
self.map.each_key_reverse(f)
|
self.map.each_key_reverse(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ impl<T> TrieNode<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> TrieNode<T> {
|
impl<T> TrieNode<T> {
|
||||||
fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
fn each<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
|
||||||
for elt in self.children.iter() {
|
for elt in self.children.iter() {
|
||||||
match *elt {
|
match *elt {
|
||||||
Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false },
|
Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false },
|
||||||
@ -339,7 +339,7 @@ impl<T> TrieNode<T> {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
|
||||||
for elt in self.children.rev_iter() {
|
for elt in self.children.rev_iter() {
|
||||||
match *elt {
|
match *elt {
|
||||||
Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
|
Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
|
||||||
@ -350,7 +350,7 @@ impl<T> TrieNode<T> {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
|
fn mutate_values<'a>(&'a mut self, f: |&uint, &mut T| -> bool) -> bool {
|
||||||
for child in self.children.mut_iter() {
|
for child in self.children.mut_iter() {
|
||||||
match *child {
|
match *child {
|
||||||
Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) {
|
Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) {
|
||||||
|
@ -3619,15 +3619,15 @@ pub mod decompose {
|
|||||||
('\U0001d185', '\U0001d189', 230), ('\U0001d18a', '\U0001d18b', 220),
|
('\U0001d185', '\U0001d189', 230), ('\U0001d18a', '\U0001d18b', 220),
|
||||||
('\U0001d1aa', '\U0001d1ad', 230), ('\U0001d242', '\U0001d244', 230)
|
('\U0001d1aa', '\U0001d1ad', 230), ('\U0001d242', '\U0001d244', 230)
|
||||||
];
|
];
|
||||||
pub fn canonical(c: char, i: &fn(char)) { d(c, i, false); }
|
pub fn canonical(c: char, i: |char|) { d(c, i, false); }
|
||||||
|
|
||||||
pub fn compatibility(c: char, i: &fn(char)) { d(c, i, true); }
|
pub fn compatibility(c: char, i: |char|) { d(c, i, true); }
|
||||||
|
|
||||||
pub fn canonical_combining_class(c: char) -> u8 {
|
pub fn canonical_combining_class(c: char) -> u8 {
|
||||||
bsearch_range_value_table(c, combining_class_table)
|
bsearch_range_value_table(c, combining_class_table)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn d(c: char, i: &fn(char), k: bool) {
|
fn d(c: char, i: |char|, k: bool) {
|
||||||
use iter::Iterator;
|
use iter::Iterator;
|
||||||
if c <= '\x7f' { i(c); return; }
|
if c <= '\x7f' { i(c); return; }
|
||||||
|
|
||||||
|
@ -153,10 +153,9 @@ pub mod dl {
|
|||||||
dlopen(ptr::null(), Lazy as libc::c_int)
|
dlopen(ptr::null(), Lazy as libc::c_int)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_for_errors_in<T>(f: &fn()->T) -> Result<T, ~str> {
|
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, ~str> {
|
||||||
use unstable::mutex::{Mutex, MUTEX_INIT};
|
use unstable::mutex::{Mutex, MUTEX_INIT};
|
||||||
static mut lock: Mutex = MUTEX_INIT;
|
static mut lock: Mutex = MUTEX_INIT;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// dlerror isn't thread safe, so we need to lock around this entire
|
// dlerror isn't thread safe, so we need to lock around this entire
|
||||||
// sequence. `atomically` asserts that we don't do anything that
|
// sequence. `atomically` asserts that we don't do anything that
|
||||||
@ -225,7 +224,7 @@ pub mod dl {
|
|||||||
handle
|
handle
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_for_errors_in<T>(f: &fn()->T) -> Result<T, ~str> {
|
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, ~str> {
|
||||||
unsafe {
|
unsafe {
|
||||||
do atomically {
|
do atomically {
|
||||||
SetLastError(0);
|
SetLastError(0);
|
||||||
|
@ -28,13 +28,13 @@ use ops::Drop;
|
|||||||
#[cfg(test)] use task::{failing, spawn};
|
#[cfg(test)] use task::{failing, spawn};
|
||||||
|
|
||||||
pub trait Finally<T> {
|
pub trait Finally<T> {
|
||||||
fn finally(&self, dtor: &fn()) -> T;
|
fn finally(&self, dtor: ||) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! finally_fn {
|
macro_rules! finally_fn {
|
||||||
($fnty:ty) => {
|
($fnty:ty) => {
|
||||||
impl<T> Finally<T> for $fnty {
|
impl<T> Finally<T> for $fnty {
|
||||||
fn finally(&self, dtor: &fn()) -> T {
|
fn finally(&self, dtor: ||) -> T {
|
||||||
let _d = Finallyalizer {
|
let _d = Finallyalizer {
|
||||||
dtor: dtor
|
dtor: dtor
|
||||||
};
|
};
|
||||||
@ -45,7 +45,7 @@ macro_rules! finally_fn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'self,T> Finally<T> for &'self fn() -> T {
|
impl<'self,T> Finally<T> for &'self fn() -> T {
|
||||||
fn finally(&self, dtor: &fn()) -> T {
|
fn finally(&self, dtor: ||) -> T {
|
||||||
let _d = Finallyalizer {
|
let _d = Finallyalizer {
|
||||||
dtor: dtor
|
dtor: dtor
|
||||||
};
|
};
|
||||||
@ -95,7 +95,7 @@ fn test_fail() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_retval() {
|
fn test_retval() {
|
||||||
let closure: &fn() -> int = || 10;
|
let closure: || -> int = || 10;
|
||||||
let i = do closure.finally { };
|
let i = do closure.finally { };
|
||||||
assert_eq!(i, 10);
|
assert_eq!(i, 10);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ mod tests {
|
|||||||
fn synthesize_closure() {
|
fn synthesize_closure() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let x = 10;
|
let x = 10;
|
||||||
let f: &fn(int) -> int = |y| x + y;
|
let f: |int| -> int = |y| x + y;
|
||||||
|
|
||||||
assert_eq!(f(20), 30);
|
assert_eq!(f(20), 30);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ mod tests {
|
|||||||
env: environment
|
env: environment
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_f: &fn(int) -> int = cast::transmute(new_closure);
|
let new_f: |int| -> int = cast::transmute(new_closure);
|
||||||
assert_eq!(new_f(20), 30);
|
assert_eq!(new_f(20), 30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ impl<T> Drop for UnsafeArc<T>{
|
|||||||
* synchronization whatsoever. It only makes sense to use for CPU-local issues.
|
* synchronization whatsoever. It only makes sense to use for CPU-local issues.
|
||||||
*/
|
*/
|
||||||
// FIXME(#8140) should not be pub
|
// FIXME(#8140) should not be pub
|
||||||
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
|
pub unsafe fn atomically<U>(f: || -> U) -> U {
|
||||||
use rt::task::{Task, GreenTask, SchedTask};
|
use rt::task::{Task, GreenTask, SchedTask};
|
||||||
use rt::local::Local;
|
use rt::local::Local;
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ impl LittleLock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn lock<T>(&self, f: &fn() -> T) -> T {
|
pub unsafe fn lock<T>(&self, f: || -> T) -> T {
|
||||||
let this = cast::transmute_mut(self);
|
let this = cast::transmute_mut(self);
|
||||||
do atomically {
|
do atomically {
|
||||||
this.l.lock();
|
this.l.lock();
|
||||||
@ -352,7 +352,7 @@ impl LittleLock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn try_lock<T>(&self, f: &fn() -> T) -> Option<T> {
|
pub unsafe fn try_lock<T>(&self, f: || -> T) -> Option<T> {
|
||||||
let this = cast::transmute_mut(self);
|
let this = cast::transmute_mut(self);
|
||||||
do atomically {
|
do atomically {
|
||||||
if this.l.trylock() {
|
if this.l.trylock() {
|
||||||
@ -372,7 +372,7 @@ impl LittleLock {
|
|||||||
this.l.signal();
|
this.l.signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn lock_and_wait(&self, f: &fn() -> bool) {
|
pub unsafe fn lock_and_wait(&self, f: || -> bool) {
|
||||||
let this = cast::transmute_mut(self);
|
let this = cast::transmute_mut(self);
|
||||||
do atomically {
|
do atomically {
|
||||||
this.l.lock();
|
this.l.lock();
|
||||||
@ -433,7 +433,7 @@ impl<T:Send> Exclusive<T> {
|
|||||||
// accessing the provided condition variable) are prohibited while inside
|
// accessing the provided condition variable) are prohibited while inside
|
||||||
// the Exclusive. Supporting that is a work in progress.
|
// the Exclusive. Supporting that is a work in progress.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn with<U>(&self, f: &fn(x: &mut T) -> U) -> U {
|
pub unsafe fn with<U>(&self, f: |x: &mut T| -> U) -> U {
|
||||||
let rec = self.x.get();
|
let rec = self.x.get();
|
||||||
do (*rec).lock.lock {
|
do (*rec).lock.lock {
|
||||||
if (*rec).failed {
|
if (*rec).failed {
|
||||||
@ -447,14 +447,14 @@ impl<T:Send> Exclusive<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn with_imm<U>(&self, f: &fn(x: &T) -> U) -> U {
|
pub unsafe fn with_imm<U>(&self, f: |x: &T| -> U) -> U {
|
||||||
do self.with |x| {
|
do self.with |x| {
|
||||||
f(cast::transmute_immut(x))
|
f(cast::transmute_immut(x))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn hold_and_signal(&self, f: &fn(x: &mut T)) {
|
pub unsafe fn hold_and_signal(&self, f: |x: &mut T|) {
|
||||||
let rec = self.x.get();
|
let rec = self.x.get();
|
||||||
do (*rec).lock.lock {
|
do (*rec).lock.lock {
|
||||||
if (*rec).failed {
|
if (*rec).failed {
|
||||||
@ -468,7 +468,7 @@ impl<T:Send> Exclusive<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn hold_and_wait(&self, f: &fn(x: &T) -> bool) {
|
pub unsafe fn hold_and_wait(&self, f: |x: &T| -> bool) {
|
||||||
let rec = self.x.get();
|
let rec = self.x.get();
|
||||||
do (*rec).lock.lock_and_wait {
|
do (*rec).lock.lock_and_wait {
|
||||||
if (*rec).failed {
|
if (*rec).failed {
|
||||||
|
@ -132,7 +132,7 @@ use util;
|
|||||||
* Creates an owned vector of size `n_elts` and initializes the elements
|
* Creates an owned vector of size `n_elts` and initializes the elements
|
||||||
* to the value returned by the function `op`.
|
* to the value returned by the function `op`.
|
||||||
*/
|
*/
|
||||||
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T] {
|
pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> ~[T] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut v = with_capacity(n_elts);
|
let mut v = with_capacity(n_elts);
|
||||||
let p = raw::to_mut_ptr(v);
|
let p = raw::to_mut_ptr(v);
|
||||||
@ -211,7 +211,7 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
|
|||||||
* onto the vector being constructed.
|
* onto the vector being constructed.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn build<A>(size: Option<uint>, builder: &fn(push: &fn(v: A))) -> ~[A] {
|
pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> ~[A] {
|
||||||
let mut vec = with_capacity(size.unwrap_or(4));
|
let mut vec = with_capacity(size.unwrap_or(4));
|
||||||
builder(|x| vec.push(x));
|
builder(|x| vec.push(x));
|
||||||
vec
|
vec
|
||||||
@ -338,7 +338,7 @@ pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
|
|||||||
* Apply a function to each element of a vector and return a concatenation
|
* Apply a function to each element of a vector and return a concatenation
|
||||||
* of each result vector
|
* of each result vector
|
||||||
*/
|
*/
|
||||||
pub fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
|
pub fn flat_map<T, U>(v: &[T], f: |t: &T| -> ~[U]) -> ~[U] {
|
||||||
let mut result = ~[];
|
let mut result = ~[];
|
||||||
for elem in v.iter() { result.push_all_move(f(elem)); }
|
for elem in v.iter() { result.push_all_move(f(elem)); }
|
||||||
result
|
result
|
||||||
@ -946,7 +946,7 @@ pub trait ImmutableVector<'self, T> {
|
|||||||
* Apply a function to each element of a vector and return a concatenation
|
* Apply a function to each element of a vector and return a concatenation
|
||||||
* of each result vector
|
* of each result vector
|
||||||
*/
|
*/
|
||||||
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
|
fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U];
|
||||||
/// Returns a pointer to the element at the given index, without doing
|
/// Returns a pointer to the element at the given index, without doing
|
||||||
/// bounds checking.
|
/// bounds checking.
|
||||||
unsafe fn unsafe_ref(&self, index: uint) -> *T;
|
unsafe fn unsafe_ref(&self, index: uint) -> *T;
|
||||||
@ -961,12 +961,12 @@ pub trait ImmutableVector<'self, T> {
|
|||||||
* Returns the index where the comparator returned `Equal`, or `None` if
|
* Returns the index where the comparator returned `Equal`, or `None` if
|
||||||
* not found.
|
* not found.
|
||||||
*/
|
*/
|
||||||
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>;
|
fn bsearch(&self, f: |&T| -> Ordering) -> Option<uint>;
|
||||||
|
|
||||||
/// Deprecated, use iterators where possible
|
/// Deprecated, use iterators where possible
|
||||||
/// (`self.iter().map(f)`). Apply a function to each element
|
/// (`self.iter().map(f)`). Apply a function to each element
|
||||||
/// of a vector and return the results.
|
/// of a vector and return the results.
|
||||||
fn map<U>(&self, &fn(t: &T) -> U) -> ~[U];
|
fn map<U>(&self, |t: &T| -> U) -> ~[U];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Work with the buffer of a vector.
|
* Work with the buffer of a vector.
|
||||||
@ -974,7 +974,7 @@ pub trait ImmutableVector<'self, T> {
|
|||||||
* Allows for unsafe manipulation of vector contents, which is useful for
|
* Allows for unsafe manipulation of vector contents, which is useful for
|
||||||
* foreign interop.
|
* foreign interop.
|
||||||
*/
|
*/
|
||||||
fn as_imm_buf<U>(&self, f: &fn(*T, uint) -> U) -> U;
|
fn as_imm_buf<U>(&self, f: |*T, uint| -> U) -> U;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||||
@ -1104,7 +1104,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
|
fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U] {
|
||||||
flat_map(*self, f)
|
flat_map(*self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,7 +1113,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
|||||||
self.repr().data.offset(index as int)
|
self.repr().data.offset(index as int)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint> {
|
fn bsearch(&self, f: |&T| -> Ordering) -> Option<uint> {
|
||||||
let mut base : uint = 0;
|
let mut base : uint = 0;
|
||||||
let mut lim : uint = self.len();
|
let mut lim : uint = self.len();
|
||||||
|
|
||||||
@ -1132,12 +1132,12 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] {
|
fn map<U>(&self, f: |t: &T| -> U) -> ~[U] {
|
||||||
self.iter().map(f).collect()
|
self.iter().map(f).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_imm_buf<U>(&self, f: &fn(*T, uint) -> U) -> U {
|
fn as_imm_buf<U>(&self, f: |*T, uint| -> U) -> U {
|
||||||
let s = self.repr();
|
let s = self.repr();
|
||||||
f(s.data, s.len)
|
f(s.data, s.len)
|
||||||
}
|
}
|
||||||
@ -1212,7 +1212,7 @@ pub trait ImmutableCopyableVector<T> {
|
|||||||
* Partitions the vector into those that satisfies the predicate, and
|
* Partitions the vector into those that satisfies the predicate, and
|
||||||
* those that do not.
|
* those that do not.
|
||||||
*/
|
*/
|
||||||
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
|
fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]);
|
||||||
/// Returns the element at the given index, without doing bounds checking.
|
/// Returns the element at the given index, without doing bounds checking.
|
||||||
unsafe fn unsafe_get(&self, elem: uint) -> T;
|
unsafe fn unsafe_get(&self, elem: uint) -> T;
|
||||||
|
|
||||||
@ -1223,7 +1223,7 @@ pub trait ImmutableCopyableVector<T> {
|
|||||||
|
|
||||||
impl<'self,T:Clone> ImmutableCopyableVector<T> for &'self [T] {
|
impl<'self,T:Clone> ImmutableCopyableVector<T> for &'self [T] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
|
fn partitioned(&self, f: |&T| -> bool) -> (~[T], ~[T]) {
|
||||||
let mut lefts = ~[];
|
let mut lefts = ~[];
|
||||||
let mut rights = ~[];
|
let mut rights = ~[];
|
||||||
|
|
||||||
@ -1370,12 +1370,12 @@ pub trait OwnedVector<T> {
|
|||||||
/**
|
/**
|
||||||
* Like `filter()`, but in place. Preserves order of `v`. Linear time.
|
* Like `filter()`, but in place. Preserves order of `v`. Linear time.
|
||||||
*/
|
*/
|
||||||
fn retain(&mut self, f: &fn(t: &T) -> bool);
|
fn retain(&mut self, f: |t: &T| -> bool);
|
||||||
/**
|
/**
|
||||||
* Partitions the vector into those that satisfies the predicate, and
|
* Partitions the vector into those that satisfies the predicate, and
|
||||||
* those that do not.
|
* those that do not.
|
||||||
*/
|
*/
|
||||||
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
|
fn partition(self, f: |&T| -> bool) -> (~[T], ~[T]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expands a vector in place, initializing the new elements to the result of
|
* Expands a vector in place, initializing the new elements to the result of
|
||||||
@ -1389,7 +1389,7 @@ pub trait OwnedVector<T> {
|
|||||||
* * init_op - A function to call to retreive each appended element's
|
* * init_op - A function to call to retreive each appended element's
|
||||||
* value
|
* value
|
||||||
*/
|
*/
|
||||||
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T);
|
fn grow_fn(&mut self, n: uint, op: |uint| -> T);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> OwnedVector<T> for ~[T] {
|
impl<T> OwnedVector<T> for ~[T] {
|
||||||
@ -1646,7 +1646,7 @@ impl<T> OwnedVector<T> for ~[T] {
|
|||||||
unsafe { raw::set_len(self, newlen); }
|
unsafe { raw::set_len(self, newlen); }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retain(&mut self, f: &fn(t: &T) -> bool) {
|
fn retain(&mut self, f: |t: &T| -> bool) {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
let mut deleted: uint = 0;
|
let mut deleted: uint = 0;
|
||||||
|
|
||||||
@ -1664,7 +1664,7 @@ impl<T> OwnedVector<T> for ~[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
|
fn partition(self, f: |&T| -> bool) -> (~[T], ~[T]) {
|
||||||
let mut lefts = ~[];
|
let mut lefts = ~[];
|
||||||
let mut rights = ~[];
|
let mut rights = ~[];
|
||||||
|
|
||||||
@ -1678,7 +1678,7 @@ impl<T> OwnedVector<T> for ~[T] {
|
|||||||
|
|
||||||
(lefts, rights)
|
(lefts, rights)
|
||||||
}
|
}
|
||||||
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T) {
|
fn grow_fn(&mut self, n: uint, op: |uint| -> T) {
|
||||||
let new_len = self.len() + n;
|
let new_len = self.len() + n;
|
||||||
self.reserve_at_least(new_len);
|
self.reserve_at_least(new_len);
|
||||||
let mut i: uint = 0u;
|
let mut i: uint = 0u;
|
||||||
@ -1919,7 +1919,7 @@ pub trait MutableVector<'self, T> {
|
|||||||
unsafe fn unsafe_set(self, index: uint, val: T);
|
unsafe fn unsafe_set(self, index: uint, val: T);
|
||||||
|
|
||||||
/// Similar to `as_imm_buf` but passing a `*mut T`
|
/// Similar to `as_imm_buf` but passing a `*mut T`
|
||||||
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U;
|
fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
|
impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
|
||||||
@ -2016,7 +2016,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U {
|
fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U {
|
||||||
let Slice{ data, len } = self.repr();
|
let Slice{ data, len } = self.repr();
|
||||||
f(data as *mut T, len)
|
f(data as *mut T, len)
|
||||||
}
|
}
|
||||||
@ -2107,9 +2107,8 @@ pub mod raw {
|
|||||||
* not bytes).
|
* not bytes).
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn buf_as_slice<T,U>(p: *T,
|
pub unsafe fn buf_as_slice<T,U>(p: *T, len: uint, f: |v: &[T]| -> U)
|
||||||
len: uint,
|
-> U {
|
||||||
f: &fn(v: &[T]) -> U) -> U {
|
|
||||||
f(cast::transmute(Slice {
|
f(cast::transmute(Slice {
|
||||||
data: p,
|
data: p,
|
||||||
len: len
|
len: len
|
||||||
@ -2121,9 +2120,12 @@ pub mod raw {
|
|||||||
* not bytes).
|
* not bytes).
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn mut_buf_as_slice<T,U>(p: *mut T,
|
pub unsafe fn mut_buf_as_slice<T,
|
||||||
len: uint,
|
U>(
|
||||||
f: &fn(v: &mut [T]) -> U) -> U {
|
p: *mut T,
|
||||||
|
len: uint,
|
||||||
|
f: |v: &mut [T]| -> U)
|
||||||
|
-> U {
|
||||||
f(cast::transmute(Slice {
|
f(cast::transmute(Slice {
|
||||||
data: p as *T,
|
data: p as *T,
|
||||||
len: len
|
len: len
|
||||||
|
Loading…
Reference in New Issue
Block a user