@@ -39,7 +39,7 @@ pub trait EventLoop {
39
39
fn remote_callback ( & mut self , ~Callback ) -> ~RemoteCallback ;
40
40
41
41
/// 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 > ;
43
43
}
44
44
45
45
pub trait RemoteCallback {
@@ -78,19 +78,19 @@ pub enum CloseBehavior {
78
78
CloseAsynchronously ,
79
79
}
80
80
81
- pub struct LocalIo {
82
- factory: & ' static mut IoFactory : ' static ,
81
+ pub struct LocalIo < ' a > {
82
+ priv factory : & ' a mut IoFactory ,
83
83
}
84
84
85
85
#[ unsafe_destructor]
86
- impl Drop for LocalIo {
86
+ impl < ' a > Drop for LocalIo < ' a > {
87
87
fn drop ( & mut self ) {
88
88
// XXX(pcwalton): Do nothing here for now, but eventually we may want
89
89
// something. For now this serves to make `LocalIo` noncopyable.
90
90
}
91
91
}
92
92
93
- impl LocalIo {
93
+ impl < ' a > LocalIo < ' a > {
94
94
/// Returns the local I/O: either the local scheduler's I/O services or
95
95
/// the native I/O services.
96
96
pub fn borrow ( ) -> LocalIo {
@@ -102,8 +102,13 @@ impl LocalIo {
102
102
let sched: Option < * mut Scheduler > = Local :: try_unsafe_borrow ( ) ;
103
103
match sched {
104
104
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 => { }
107
112
}
108
113
}
109
114
None => { }
@@ -120,7 +125,9 @@ impl LocalIo {
120
125
121
126
/// Returns the underlying I/O factory as a trait reference.
122
127
#[ 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?
124
131
unsafe {
125
132
cast:: transmute_copy ( & self . factory )
126
133
}
0 commit comments