@@ -39,7 +39,7 @@ pub trait EventLoop {
3939 fn remote_callback ( & mut self , ~Callback ) -> ~RemoteCallback ;
4040
4141 /// The asynchronous I/O services. Not all event loops may provide one.
42- fn io ( & mut self ) -> & ' static mut IoFactory : ' static ;
42+ fn io < ' a > ( & ' a mut self ) -> Option < & ' a mut IoFactory > ;
4343}
4444
4545pub trait RemoteCallback {
@@ -78,19 +78,19 @@ pub enum CloseBehavior {
7878 CloseAsynchronously ,
7979}
8080
81- pub struct LocalIo {
82- factory: & ' static mut IoFactory : ' static ,
81+ pub struct LocalIo < ' a > {
82+ priv factory : & ' a mut IoFactory ,
8383}
8484
8585#[ unsafe_destructor]
86- impl Drop for LocalIo {
86+ impl < ' a > Drop for LocalIo < ' a > {
8787 fn drop ( & mut self ) {
8888 // XXX(pcwalton): Do nothing here for now, but eventually we may want
8989 // something. For now this serves to make `LocalIo` noncopyable.
9090 }
9191}
9292
93- impl LocalIo {
93+ impl < ' a > LocalIo < ' a > {
9494 /// Returns the local I/O: either the local scheduler's I/O services or
9595 /// the native I/O services.
9696 pub fn borrow ( ) -> LocalIo {
@@ -102,8 +102,13 @@ impl LocalIo {
102102 let sched: Option < * mut Scheduler > = Local :: try_unsafe_borrow ( ) ;
103103 match sched {
104104 Some ( sched) => {
105- return LocalIo {
106- factory : ( * sched) . event_loop . io ( ) ,
105+ match ( * sched) . event_loop . io ( ) {
106+ Some ( factory) => {
107+ return LocalIo {
108+ factory : factory,
109+ }
110+ }
111+ None => { }
107112 }
108113 }
109114 None => { }
@@ -120,7 +125,9 @@ impl LocalIo {
120125
121126 /// Returns the underlying I/O factory as a trait reference.
122127 #[ inline]
123- pub fn get ( & mut self ) -> & ' static mut IoFactory {
128+ pub fn get < ' a > ( & ' a mut self ) -> & ' a mut IoFactory {
129+ // XXX(pcwalton): I think this is actually sound? Could borrow check
130+ // allow this safely?
124131 unsafe {
125132 cast:: transmute_copy ( & self . factory )
126133 }
0 commit comments