[rust-dev] Misc questions and ideas

Michael Neumann mneumann at ntecs.de
Sun Dec 23 14:53:02 PST 2012


Am Sun, 23 Dec 2012 12:20:07 -0500
schrieb Patrick Walton <pwalton at mozilla.com>:

> On 12/23/12 10:43 AM, Michael Neumann wrote:
> > Hi,
>
> [...]
> 
> > * I do not fully understand the warning of the following script:
> >
> >    fn main() {
> >      let bytes =
> >        io::read_whole_file(&path::Path("/tmp/matching.msgpack")).get();
> >    }
> >
> >    t2.rs:2:14: 2:78 warning: instantiating copy type parameter with
> > a not implicitly copyable type t2.rs:2   let bytes =
> >    io::read_whole_file(&path::Path("/tmp/matching.msgpack")).get();
> >    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> >    Does it mean that it will copy the ~str again? When I use pattern
> >    matching instead of get(), I don't get this warning, but it
> > seems to be slower. Will it just silence the warning???
> 
> Yes, it means it will copy the string again. To avoid this, you want 
> result::unwrap() or option::unwrap() instead. I've been thinking for 
> some time that .unwrap() should change to .get() and .get() should 
> change to .copy_value() or something.

That's strange. If I use result::unwrap() it is consistently becoming
much slower! But the warning goes away. While get() is faster, but
there is this warning. Btw, there is also no .unwrap(), just
result::unwrap(). I believe that unwrap() is copying, while get() is
passing a reference somehow.

Michael


More information about the Rust-dev mailing list