Chopped code that shows this error:
fn with_connector<C: NetworkConnector>(connector: &mut C) -> HttpResult<Request> {
let stream = try!(connector.connect(host, port, scheme));
let stream = BufferedWriter::new(box stream as Box<NetworkStream + Send>);
// ^~~ parameter `C` may not live long enough, consider an explicit lifetime 'static
}
pub trait NetworkConnector {
type Stream: NetworkStream + Send;
pub fn connect(...) -> IoResult<Self::Stream>;
}
Code fixed. Note that the lifetime wasn't need on C, though the error message says it was.
fn with_connector<'a, C: NetworkConnector<Stream = T>, T: NetworkStream+'a>(connector: &C) -> Result<Box<NetworkStream + 'a>, ()> {
let stream = try!(connector.connect());
Ok(box stream as Box<NetworkStream + 'a>)
}
trait NetworkStream {}
pub trait NetworkConnector {
type Stream: NetworkStream;
fn connect(&self) -> Result<Self::Stream, ()>;
}
/cc @nick29581
Chopped code that shows this error:
Code fixed. Note that the lifetime wasn't need on C, though the error message says it was.
/cc @nick29581