Hi,
I'm in the process of fixing a `ty_trait` variance inference bug, which
will void the following code in json.rs:
pub struct Encoder<'a> {
priv wr: &'a mut io::Writer,
priv error: io::IoResult<()>,
}
impl<'a> Encoder<'a> {
pub fn new<'a>(wr: &'a mut io::Writer) -> Encoder<'a> {
Encoder { wr: wr, error: Ok(()) }
}
pub fn buffer_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) ->
~[u8] {
let mut m = MemWriter::new();
{
let mut encoder = Encoder::new(&mut m as &mut io::Writer);
to_encode_object.encode(&mut encoder);
}
m.unwrap()
}
}
If taking a close look, m here is merely a local variable but Encoder<'a>
requires a lifetime at least 'a. A naive fix would be:
let mut encoder = Encoder::new(cast::transmute_mut_region(&mut m));
But of course, it is very uncivilized :) Any suggestion on how to refactor
this piece of code so it won't violate the lifetime requirement?
Regards,
Edward
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev