]> git.lizzy.rs Git - rust.git/blobdiff - src/libsync/future.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / libsync / future.rs
index 9984d2dd0adb20afcc099d00276cf1c9cad45b2e..2836f9cb4be82d0246f64ec1f539eb55360a1a03 100644 (file)
  * ```
  */
 
-#[allow(missing_doc)];
+#![allow(missing_doc)]
 
 use std::mem::replace;
 
 /// A type encapsulating the result of a computation which may not be complete
 pub struct Future<A> {
-    priv state: FutureState<A>,
+    state: FutureState<A>,
 }
 
 enum FutureState<A> {
-    Pending(proc() -> A),
+    Pending(proc():Send -> A),
     Evaluating,
     Forced(A)
 }
@@ -90,7 +90,7 @@ pub fn from_value(val: A) -> Future<A> {
         Future {state: Forced(val)}
     }
 
-    pub fn from_fn(f: proc() -> A) -> Future<A> {
+    pub fn from_fn(f: proc():Send -> A) -> Future<A> {
         /*!
          * Create a future from a function.
          *
@@ -104,7 +104,7 @@ pub fn from_fn(f: proc() -> A) -> Future<A> {
 }
 
 impl<A:Send> Future<A> {
-    pub fn from_port(port: Port<A>) -> Future<A> {
+    pub fn from_receiver(rx: Receiver<A>) -> Future<A> {
         /*!
          * Create a future from a port
          *
@@ -113,11 +113,11 @@ pub fn from_port(port: Port<A>) -> Future<A> {
          */
 
         Future::from_fn(proc() {
-            port.recv()
+            rx.recv()
         })
     }
 
-    pub fn spawn(blk: proc() -> A) -> Future<A> {
+    pub fn spawn(blk: proc():Send -> A) -> Future<A> {
         /*!
          * Create a future from a unique closure.
          *
@@ -125,13 +125,13 @@ pub fn spawn(blk: proc() -> A) -> Future<A> {
          * value of the future.
          */
 
-        let (port, chan) = Chan::new();
+        let (tx, rx) = channel();
 
         spawn(proc() {
-            chan.send(blk());
+            tx.send(blk());
         });
 
-        Future::from_port(port)
+        Future::from_receiver(rx)
     }
 }
 
@@ -143,34 +143,34 @@ mod test {
 
     #[test]
     fn test_from_value() {
-        let mut f = Future::from_value(~"snail");
-        assert_eq!(f.get(), ~"snail");
+        let mut f = Future::from_value("snail".to_owned());
+        assert_eq!(f.get(), "snail".to_owned());
     }
 
     #[test]
-    fn test_from_port() {
-        let (po, ch) = Chan::new();
-        ch.send(~"whale");
-        let mut f = Future::from_port(po);
-        assert_eq!(f.get(), ~"whale");
+    fn test_from_receiver() {
+        let (tx, rx) = channel();
+        tx.send("whale".to_owned());
+        let mut f = Future::from_receiver(rx);
+        assert_eq!(f.get(), "whale".to_owned());
     }
 
     #[test]
     fn test_from_fn() {
-        let mut f = Future::from_fn(proc() ~"brail");
-        assert_eq!(f.get(), ~"brail");
+        let mut f = Future::from_fn(proc() "brail".to_owned());
+        assert_eq!(f.get(), "brail".to_owned());
     }
 
     #[test]
     fn test_interface_get() {
-        let mut f = Future::from_value(~"fail");
-        assert_eq!(f.get(), ~"fail");
+        let mut f = Future::from_value("fail".to_owned());
+        assert_eq!(f.get(), "fail".to_owned());
     }
 
     #[test]
     fn test_interface_unwrap() {
-        let f = Future::from_value(~"fail");
-        assert_eq!(f.unwrap(), ~"fail");
+        let f = Future::from_value("fail".to_owned());
+        assert_eq!(f.unwrap(), "fail".to_owned());
     }
 
     #[test]
@@ -181,8 +181,8 @@ fn test_get_ref_method() {
 
     #[test]
     fn test_spawn() {
-        let mut f = Future::spawn(proc() ~"bale");
-        assert_eq!(f.get(), ~"bale");
+        let mut f = Future::spawn(proc() "bale".to_owned());
+        assert_eq!(f.get(), "bale".to_owned());
     }
 
     #[test]