diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-12-05 17:37:02 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-12-10 17:55:09 -0800 |
| commit | fd7a513bef7fe3c6f5128cc53135facca37f23e5 (patch) | |
| tree | be733adb0aa531f7d4e1885b234c0bc489f02948 /src/libstd/rt | |
| parent | 61135080554d35cca151614c93693cb524fdffe0 (diff) | |
| download | rust-fd7a513bef7fe3c6f5128cc53135facca37f23e5.tar.gz rust-fd7a513bef7fe3c6f5128cc53135facca37f23e5.zip | |
libstd: Remove `Cell` from the library.
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/basic.rs | 8 | ||||
| -rw-r--r-- | src/libstd/rt/rtio.rs | 23 |
2 files changed, 18 insertions, 13 deletions
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) } |
