about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-12-05 17:37:02 -0800
committerPatrick Walton <pcwalton@mimiga.net>2013-12-10 17:55:09 -0800
commitfd7a513bef7fe3c6f5128cc53135facca37f23e5 (patch)
treebe733adb0aa531f7d4e1885b234c0bc489f02948 /src/libstd
parent61135080554d35cca151614c93693cb524fdffe0 (diff)
downloadrust-fd7a513bef7fe3c6f5128cc53135facca37f23e5.tar.gz
rust-fd7a513bef7fe3c6f5128cc53135facca37f23e5.zip
libstd: Remove `Cell` from the library.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/cell.rs60
-rw-r--r--src/libstd/io/stdio.rs2
-rw-r--r--src/libstd/rt/basic.rs8
-rw-r--r--src/libstd/rt/rtio.rs23
4 files changed, 19 insertions, 74 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs
index e49cf3e5303..280c79f1fd4 100644
--- a/src/libstd/cell.rs
+++ b/src/libstd/cell.rs
@@ -14,66 +14,6 @@ use prelude::*;
 use cast;
 use util::NonCopyable;
 
-
-/*
-A dynamic, mutable location.
-
-Similar to a mutable option type, but friendlier.
-*/
-
-#[no_freeze]
-#[deriving(Clone, DeepClone, Eq)]
-#[allow(missing_doc)]
-pub struct Cell<T> {
-    priv value: Option<T>
-}
-
-impl<T> Cell<T> {
-    /// Creates a new full cell with the given value.
-    pub fn new(value: T) -> Cell<T> {
-        Cell { value: Some(value) }
-    }
-
-    /// Yields the value, failing if the cell is empty.
-    pub fn take(&self) -> T {
-        let this = unsafe { cast::transmute_mut(self) };
-        if this.is_empty() {
-            fail!("attempt to take an empty cell");
-        }
-
-        this.value.take_unwrap()
-    }
-
-    /// Yields the value if the cell is full, or `None` if it is empty.
-    pub fn take_opt(&self) -> Option<T> {
-        let this = unsafe { cast::transmute_mut(self) };
-        this.value.take()
-    }
-
-    /// Returns true if the cell is empty and false if the cell is full.
-    pub fn is_empty(&self) -> bool {
-        self.value.is_none()
-    }
-}
-
-#[test]
-fn test_basic() {
-    let value_cell = Cell::new(~10);
-    assert!(!value_cell.is_empty());
-    let value = value_cell.take();
-    assert!(value == ~10);
-    assert!(value_cell.is_empty());
-}
-
-#[test]
-#[should_fail]
-fn test_take_empty() {
-    let value_cell: Cell<~int> = Cell::new(~0);
-    value_cell.take();
-    value_cell.take();
-}
-
-
 /// A mutable memory location with dynamically checked borrow rules
 #[no_freeze]
 pub struct RefCell<T> {
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index 509ef2a8157..41337075aa9 100644
--- a/src/libstd/io/stdio.rs
+++ b/src/libstd/io/stdio.rs
@@ -31,7 +31,7 @@ use libc;
 use option::{Option, Some, None};
 use result::{Ok, Err};
 use io::buffered::LineBufferedWriter;
-use rt::rtio::{IoFactory, RtioTTY, RtioFileStream, DontClose};
+use rt::rtio::{DontClose, IoFactory, LocalIo, RtioFileStream, RtioTTY};
 use super::{Reader, Writer, io_error, IoError, OtherIoError,
             standard_error, EndOfFile};
 
diff --git a/src/libstd/rt/basic.rs b/src/libstd/rt/basic.rs
index 87b776d3c1e..fa47ceb1c04 100644
--- a/src/libstd/rt/basic.rs
+++ b/src/libstd/rt/basic.rs
@@ -159,11 +159,9 @@ impl EventLoop for BasicLoop {
         ~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback
     }
 
-    fn io(&mut self) -> &'static mut IoFactory:'static {
-        unsafe {
-            let factory: &mut IoFactory = self.io;
-            cast::transmute(factory)
-        }
+    fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> {
+        let factory: &mut IoFactory = self.io;
+        Some(factory)
     }
 }
 
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs
index c6942ab8388..05cc051a23e 100644
--- a/src/libstd/rt/rtio.rs
+++ b/src/libstd/rt/rtio.rs
@@ -39,7 +39,7 @@ pub trait EventLoop {
     fn remote_callback(&mut self, ~Callback) -> ~RemoteCallback;
 
     /// The asynchronous I/O services. Not all event loops may provide one.
-    fn io(&mut self) -> &'static mut IoFactory:'static;
+    fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>;
 }
 
 pub trait RemoteCallback {
@@ -78,19 +78,19 @@ pub enum CloseBehavior {
     CloseAsynchronously,
 }
 
-pub struct LocalIo {
-    factory: &'static mut IoFactory:'static,
+pub struct LocalIo<'a> {
+    priv factory: &'a mut IoFactory,
 }
 
 #[unsafe_destructor]
-impl Drop for LocalIo {
+impl<'a> Drop for LocalIo<'a> {
     fn drop(&mut self) {
         // XXX(pcwalton): Do nothing here for now, but eventually we may want
         // something. For now this serves to make `LocalIo` noncopyable.
     }
 }
 
-impl LocalIo {
+impl<'a> LocalIo<'a> {
     /// Returns the local I/O: either the local scheduler's I/O services or
     /// the native I/O services.
     pub fn borrow() -> LocalIo {
@@ -102,8 +102,13 @@ impl LocalIo {
             let sched: Option<*mut Scheduler> = Local::try_unsafe_borrow();
             match sched {
                 Some(sched) => {
-                    return LocalIo {
-                        factory: (*sched).event_loop.io(),
+                    match (*sched).event_loop.io() {
+                        Some(factory) => {
+                            return LocalIo {
+                                factory: factory,
+                            }
+                        }
+                        None => {}
                     }
                 }
                 None => {}
@@ -120,7 +125,9 @@ impl LocalIo {
 
     /// Returns the underlying I/O factory as a trait reference.
     #[inline]
-    pub fn get(&mut self) -> &'static mut IoFactory {
+    pub fn get<'a>(&'a mut self) -> &'a mut IoFactory {
+        // XXX(pcwalton): I think this is actually sound? Could borrow check
+        // allow this safely?
         unsafe {
             cast::transmute_copy(&self.factory)
         }