Just FYI, I have been working on resolving this issue, but don't have time
to write up my intermediate thought process at the moment. Sorry. Hopefully
soon. :)
Niko
On Sat, Mar 22, 2014 at 10:24:51PM +0800, Edward Wang wrote:
> 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
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev