about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-08-30 18:00:38 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-09-23 18:23:21 -0700
commit9a4de3f3058ddb2cd43863c7c2723cec3d0fc30a (patch)
tree1e288570b1c33e5fc7579805015d223ebe249336 /src/libstd
parente95996399fe6d306a206082eb1a49189c5afe878 (diff)
downloadrust-9a4de3f3058ddb2cd43863c7c2723cec3d0fc30a.tar.gz
rust-9a4de3f3058ddb2cd43863c7c2723cec3d0fc30a.zip
libsyntax: Introduce routines and remove all `@fn`s from libsyntax save the old visitor
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/routine.rs28
-rw-r--r--src/libstd/std.rs2
-rw-r--r--src/libstd/unstable/extfmt.rs22
3 files changed, 43 insertions, 9 deletions
diff --git a/src/libstd/routine.rs b/src/libstd/routine.rs
new file mode 100644
index 00000000000..e8a91b49c8e
--- /dev/null
+++ b/src/libstd/routine.rs
@@ -0,0 +1,28 @@
+// 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.
+
+/*!
+ * Routines are like closures except that they own their arguments and can
+ * only run once.
+ */
+
+/// A routine that takes no arguments and returns nothing.
+pub trait Runnable {
+    /// The entry point for the routine.
+    fn run(~self);
+}
+
+/// A convenience routine that does nothing.
+pub struct NoOpRunnable;
+
+impl Runnable for NoOpRunnable {
+    fn run(~self) {}
+}
+
diff --git a/src/libstd/std.rs b/src/libstd/std.rs
index f7b55e977e0..5c1bac7418e 100644
--- a/src/libstd/std.rs
+++ b/src/libstd/std.rs
@@ -189,7 +189,7 @@ pub mod reflect;
 pub mod condition;
 pub mod logging;
 pub mod util;
-
+pub mod routine;
 
 /* Unsupported interfaces */
 
diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs
index f2cfd114349..4d53dd7d7bf 100644
--- a/src/libstd/unstable/extfmt.rs
+++ b/src/libstd/unstable/extfmt.rs
@@ -158,11 +158,14 @@ pub mod ct {
 
     // A fragment of the output sequence
     #[deriving(Eq)]
-    pub enum Piece { PieceString(~str), PieceConv(Conv), }
+    pub enum Piece {
+        PieceString(~str),
+        PieceConv(Conv),
+    }
 
-    pub type ErrorFn = @fn(&str) -> !;
+    pub type ErrorFn<'self> = &'self fn(&str) -> !;
 
-    pub fn parse_fmt_string(s: &str, err: ErrorFn) -> ~[Piece] {
+    pub fn parse_fmt_string<'a>(s: &str, err: ErrorFn<'a>) -> ~[Piece] {
         fn push_slice(ps: &mut ~[Piece], s: &str, from: uint, to: uint) {
             if to > from {
                 ps.push(PieceString(s.slice(from, to).to_owned()));
@@ -185,7 +188,10 @@ pub mod ct {
                     i += 1;
                 } else {
                     push_slice(&mut pieces, s, h, i - 1);
-                    let Parsed {val, next} = parse_conversion(s, i, lim, err);
+                    let Parsed {
+                        val,
+                        next
+                    } = parse_conversion(s, i, lim, |s| err(s));
                     pieces.push(val);
                     i = next;
                 }
@@ -224,8 +230,8 @@ pub mod ct {
         }
     }
 
-    pub fn parse_conversion(s: &str, i: uint, lim: uint, err: ErrorFn) ->
-        Parsed<Piece> {
+    pub fn parse_conversion<'a>(s: &str, i: uint, lim: uint, err: ErrorFn<'a>)
+                                -> Parsed<Piece> {
         let param = parse_parameter(s, i, lim);
         // avoid copying ~[Flag] by destructuring
         let Parsed {val: flags_val, next: flags_next} = parse_flags(s,
@@ -308,8 +314,8 @@ pub mod ct {
         }
     }
 
-    pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
-        Parsed<Ty> {
+    pub fn parse_type<'a>(s: &str, i: uint, lim: uint, err: ErrorFn<'a>)
+                          -> Parsed<Ty> {
         if i >= lim { err("missing type in conversion"); }
 
         // FIXME (#2249): Do we really want two signed types here?