#. type: Plain text
#: doc/tutorial-tasks.md:102
msgid ""
-"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
+"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
"Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any "
#. type: Plain text
#: doc/tutorial.md:1510
msgid ""
-"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
+"Owned closures, written `proc`, hold on to "
"things that can safely be sent between processes. They copy the values they "
"close over, much like managed closures, but they also own them: that is, no "
"other code can access them. Owned closures are used in concurrent code, "
"particularly for spawning [tasks][tasks]."
msgstr ""
-"`~` ポインタ型と同様に `~fn` 型 で書き表される所有クロージャは安全にプロセス"
+"`~` `proc` で書き表される所有クロージャは安全にプロセス"
"間で送信することができます。所有クローじゃはマネージドクロージャと全く同じよ"
"うに閉じ込める値をコピーしますが、値を所有します。つまり、他のコードは閉じ込"
"められた値にアクセスできなくなります。所有クロージャは並列プログラム、特に "
#: doc/tutorial.md:1582
msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. "
-"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
+"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
"function that takes an owned closure that takes no arguments."
msgstr ""
"`task::spawn` 関数を用いてタスクを生成する場合、 `do` を用いると便利です。"
-"`spawn` は、 `spawn(fn: ~fn())` という方を持っています。言い換えると、"
+"`spawn` は、 `spawn(fn: proc())` という方を持っています。言い換えると、"
"`spawn` は「引数をとらない所有クロージャ」を引数としてとる関数ということで"
"す。"
#. type: Plain text
#: doc/tutorial-tasks.md:102
msgid ""
-"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
+"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
"Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any "
#. type: Plain text
#: doc/tutorial.md:1510
msgid ""
-"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
+"Owned closures, written `proc`, hold on to "
"things that can safely be sent between processes. They copy the values they "
"close over, much like managed closures, but they also own them: that is, no "
"other code can access them. Owned closures are used in concurrent code, "
#: doc/tutorial.md:1582
msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. "
-"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
+"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
"function that takes an owned closure that takes no arguments."
msgstr ""
library.
The `spawn` function has a very simple type signature: `fn spawn(f:
-~fn())`. Because it accepts only owned closures, and owned closures
+proc())`. Because it accepts only owned closures, and owned closures
contain only owned data, `spawn` can safely move the entire closure
and all its associated state into an entirely different task for
execution. Like any closure, the function passed to `spawn` may capture
## Owned closures
-Owned closures, written `~fn` in analogy to the `~` pointer type,
+Owned closures, written `proc`,
hold on to things that can safely be sent between
processes. They copy the values they close over, much like managed
closures, but they also own them: that is, no other code can access
code.
`do` is a convenient way to create tasks with the `task::spawn`
-function. `spawn` has the signature `spawn(fn: ~fn())`. In other
+function. `spawn` has the signature `spawn(fn: proc())`. In other
words, it is a function that takes an owned closure that takes no
arguments.
#[test]
fn test_task_pool() {
- let f: proc() -> proc(uint) -> uint = || {
+ let f: &fn() -> proc(uint) -> uint = || {
let g: proc(uint) -> uint = |i| i;
g
};
let handle2 = Cell::new(sched2.make_handle());
let tasksFriendHandle = Cell::new(sched2.make_handle());
- let on_exit: ~fn(UnwindResult) = |exit_status| {
+ let on_exit: proc(UnwindResult) = |exit_status| {
handle1.take().send(Shutdown);
handle2.take().send(Shutdown);
assert!(exit_status.is_success());
}
}
- let test_function: ~fn() = || {
+ let test_function: proc() = || {
let io = unsafe { local_io() };
let addr = next_test_ip4();
let maybe_socket = io.udp_bind(addr);
// Master grandchild task exits early.
}
-fn spawn_supervised_blocking(myname: &str, f: ~fn()) {
+fn spawn_supervised_blocking(myname: &str, f: proc()) {
let mut builder = task::task();
let res = builder.future_result();
builder.supervised();
// xfail-test #2978
struct Foo {
- f: ~fn()
+ f: proc()
}
fn call(x: @Foo) {
pub fn main() {
- let foo = ~3;
- let _pfoo = &foo;
- let _f: ~fn() -> int = || *foo + 5;
- //~^ ERROR cannot move `foo`
-
// FIXME(#2202) - Due to the way that borrowck treats closures,
// you get two error reports here.
let bar = ~3;
let _g = || { //~ ERROR capture of moved value
- let _h: ~fn() -> int = || *bar; //~ ERROR capture of moved value
+ let _h: proc() -> int = || *bar; //~ ERROR capture of moved value
};
}
-fn call_f(f: ~fn:Send() -> int) -> int {
+fn call_f(f: proc() -> int) -> int {
f()
}
// except according to those terms.
struct X {
- field: ~fn:Send(),
+ field: &'static fn:Send(),
}
-fn foo(blk: ~fn:()) -> X {
+fn foo(blk: &'static fn:()) -> X {
return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds
}
fn main() {
let x = @3u;
- let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send`
- let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send`
- let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send`
+ let _: proc() = || foo(x); //~ ERROR does not fulfill `Send`
+ let _: proc() = || foo(x); //~ ERROR does not fulfill `Send`
+ let _: proc() = || foo(x); //~ ERROR does not fulfill `Send`
}
// but closure and object types can have lifetime bounds which make
// them not ok (FIXME #5121)
- // assert_send::<~fn:'a()>(); // ERROR does not fulfill `Send`
+ // assert_send::<proc:'a()>(); // ERROR does not fulfill `Send`
// assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send`
// unsafe ptrs are ok unless they point at unsendable things
-type Noncopyable = ~fn();
+type Noncopyable = proc();
struct Foo {
copied: int,
+++ /dev/null
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Testing guarantees provided by once functions.
-// This program would segfault if it were legal.
-
-extern mod extra;
-use extra::arc;
-use std::util;
-
-fn foo(blk: ~fn()) {
- blk();
- blk();
-}
-
-fn main() {
- let x = arc::Arc::new(true);
- do foo {
- assert!(*x.get());
- util::ignore(x); //~ ERROR cannot move out of captured outer variable
- }
-}
// check that the &int here does not cause us to think that `foo`
// contains region pointers
-struct foo(~fn(x: &int));
+struct foo(proc(x: &int));
fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters
zzz();
sentinel();
- let unique_closure: ~fn(int) = |x| {
+ let unique_closure: proc(int) = |x| {
zzz();
sentinel();
let owned = ~5;
- let closure: ~fn() = || {
+ let closure: proc() = || {
zzz();
do_something(&constant, &a_struct.a, owned);
};
fn from_foreign_fn(_x: fn()) { }
fn from_stack_closure(_x: ||) { }
-fn from_unique_closure(_x: ~fn()) { }
+fn from_unique_closure(_x: proc()) { }
fn main() { }
fn main() {
let y = ~0;
- let x: @~fn() = @(|| {
+ let x: @proc() = @(|| {
error!("{:?}", y.clone());
});
failfn();
extern mod extra;
-fn asSendfn( f : ~fn()->uint ) -> uint {
+fn asSendfn( f : proc()->uint ) -> uint {
return f();
}
pub fn main() {
let bar = ~3;
- let h: ~fn() -> int = || *bar;
+ let h: proc() -> int = || *bar;
assert_eq!(h(), 3);
}
pub fn main() {
let x = ~3;
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
- let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
+ let snd_move: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert_eq!(snd_move(), y);
let x = ~4;
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
- let lam_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
+ let lam_move: proc() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert_eq!(lam_move(), y);
}
pub fn main() {
let z = ~Pair { a : 10, b : 12};
- let f: ~fn() = || {
+ let f: proc() = || {
assert_eq!(z.a, 10);
assert_eq!(z.b, 12);
};
use std::comm;
-fn foo(blk: ~fn:Send()) {
+fn foo(blk: proc()) {
blk();
}
*
* The hash should concentrate entropy in the lower bits.
*/
-type HashFn<K> = ~fn(K) -> uint;
-type EqFn<K> = ~fn(K, K) -> bool;
+type HashFn<K> = proc(K) -> uint;
+type EqFn<K> = proc(K, K) -> bool;
struct LM { resize_at: uint, size: uint }
// xfail-test
static generations: uint = 1024+256+128+49;
-fn child_no(x: uint) -> ~fn() {
+fn child_no(x: uint) -> proc() {
|| {
if x < generations {
task::spawn(child_no(x+1));
// xfail-test
type t = {
- f: ~fn()
+ f: proc()
};
pub fn main() {
use std::path;
use std::result;
-type rsrc_loader = ~fn(path: &Path) -> result::Result<~str, ~str>;
+type rsrc_loader = proc(path: &Path) -> result::Result<~str, ~str>;
fn tester()
{
use std::task;
type RingBuffer = ~[f64];
-type SamplesFn = ~fn(samples: &RingBuffer);
+type SamplesFn = proc(samples: &RingBuffer);
enum Msg
{
+++ /dev/null
-fn run(f: &fn()) {
- f()
-}
-
-pub fn main() {
- let f: ~fn() = || ();
- run(f);
-}
// Test that the lambda kind is inferred correctly as a return
// expression
-fn unique() -> ~fn() { return || (); }
+fn unique() -> proc() { return || (); }
pub fn main() {
}
// Test that the lambda kind is inferred correctly as a return
// expression
-fn unique() -> ~fn() { || () }
+fn unique() -> proc() { || () }
pub fn main() {
}
assert_eq!(q.y, !(p.y));
// Issue #1733
- let result: ~fn(int) = |_|();
+ let result: proc(int) = |_|();
result(p[true]);
}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// xfail-fast
-
-use std::task;
-
-pub fn main() { test05(); }
-
-#[deriving(Clone)]
-struct Pair<A,B> {
- a: A,
- b: B,
-}
-
-fn make_generic_record<A,B>(a: A, b: B) -> Pair<A,B> {
- return Pair {a: a, b: b};
-}
-
-fn test05_start(f: &~fn(v: f64, v: ~str) -> Pair<f64, ~str>) {
- let p = (*f)(22.22, ~"Hi");
- info!("{:?}", p.clone());
- assert!(p.a == 22.22);
- assert!(p.b == ~"Hi");
-
- let q = (*f)(44.44, ~"Ho");
- info!("{:?}", q.clone());
- assert!(q.a == 44.44);
- assert!(q.b == ~"Ho");
-}
-
-fn spawn<A,B>(f: extern fn(&~fn(A,B)->Pair<A,B>)) {
- let arg: ~fn(A, B) -> Pair<A,B> = |a, b| make_generic_record(a, b);
- task::spawn(|| f(&arg));
-}
-
-fn test05() {
- spawn::<f64,~str>(test05_start);
-}
pub fn main() { test05(); }
-fn test05_start(f: ~fn(int)) {
+fn test05_start(f: proc(int)) {
f(22);
}
fn test05() {
let three = ~3;
- let fn_to_send: ~fn(int) = |n| {
+ let fn_to_send: proc(int) = |n| {
error!("{}", *three + n); // will copy x into the closure
assert_eq!(*three, 3);
};
}
pub enum TestFn {
- DynTestFn(~fn()),
- DynBenchFn(~fn(&mut int))
+ DynTestFn(proc()),
+ DynBenchFn(proc(&mut int))
}
pub struct TestDesc {
}
}
-fn joinable(f: ~fn()) -> Port<bool> {
+fn joinable(f: proc()) -> Port<bool> {
fn wrapper(c: Chan<bool>, f: &fn()) {
let b = @mut false;
error!("wrapper: task=%? allocated v=%x",
fn test_rm_tempdir() {
let (rd, wr) = stream();
- let f: ~fn() = || {
+ let f: proc() = || {
let tmp = TempDir::new("test_rm_tempdir").unwrap();
wr.send(tmp.path().clone());
fail!("fail to unwind past `tmp`");
let tmp = TempDir::new("test_rm_tempdir").unwrap();
let path = tmp.path().clone();
let cell = Cell::new(tmp);
- let f: ~fn() = || {
+ let f: proc() = || {
let _tmp = cell.take();
fail!("fail to unwind past `tmp`");
};
let path;
{
- let f: ~fn() -> TempDir = || {
+ let f: proc() -> TempDir = || {
TempDir::new("test_rm_tempdir").unwrap()
};
let tmp = task::try(f).expect("test_rm_tmdir");
struct Pointy {
a : maybe_pointy,
- d : ~fn() -> uint,
+ d : proc() -> uint,
}
-fn make_uniq_closure<A:Send>(a: A) -> ~fn() -> uint {
- let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint;
+fn make_uniq_closure<A:Send>(a: A) -> proc() -> uint {
+ let result: proc() -> uint = || ptr::to_unsafe_ptr(&a) as uint;
result
}
struct Pointy {
a : maybe_pointy,
c : ~int,
- d : ~fn()->(),
+ d : proc()->(),
}
fn empty_pointy() -> @mut Pointy {