Hello Edward,

I'm not sure how to help with this variance bug, but I want to warn you
(and it seems everyone else :)) that at least 2 other people have said they
are doing a Json refactor:

https://github.com/mozilla/rust/pull/12740
https://github.com/mozilla/rust/pull/12936

If all your touching are these constructors, then it's probably not much of
an issue, but if you are doing more there's a chance you could run  into
each other.

-Erick



On Sat, Mar 22, 2014 at 7:24 AM, Edward Wang <edward.yu.w...@gmail.com>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
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to