json - cannot move out of dereference -
i'm learning rust extra::json module. here example (with unneeed type annotations):
let j:result<json,jsonerror> = from_str("[{\"bar\":\"baz\", \"biz\":123}]"); let l:list = match j { ok(list(l)) => l, ok(_) => fail!("expected list @ top level"), err(e) => fail!(fmt!("error: %?", e)) }; println(fmt!("item = %?", l.iter().advance(|i|{ match { &object(o) => { println(fmt!("object %?", o)); }, _ => { fail!("should list of objects, no?"); } } println(fmt!("i=%?", i)); true })));
when compile, this:
$ rust run json.rs json.rs:70:9: 70:18 error: cannot move out of dereference of & pointer json.rs:70 &object(o) => { ^~~~~~~~~ note: in expansion of fmt! json.rs:68:10: 79:6 note: expansion site error: aborting due previous error
i have other examples of using match don't hit error.
thanks help!
patterns destructuring, means move out of thing match on default. want:
&object(ref o) => { ... }
which takes borrowed reference member, rather moving out of it.
Comments
Post a Comment