Re: [rust-dev] Checking error at opening file

2013-11-02 Thread Alex Crichton
This api is a little in flux (hopefully #10179 will land soon), but I'm not quite sure what you mean about keeping the file descriptor open. If there was an error opening the file, then a file descriptor was never allocated and there's nothing to keep open. Regardless, once my pull request lands, y

Re: [rust-dev] RFC about std::option and std::result API

2013-11-02 Thread Marvin Löbel
I prepared a patch that renames everything as proposed with the exception of Option's unwrap -> get change here: https://github.com/Kimundi/rust/commit/752912f75f6334da87a476fffc2475a3dfa5639d I touches ~ 300 lines, most of them being the unwrap -> get and unwrap_err -> err_get fallout. In f

Re: [rust-dev] RFC about std::option and std::result API

2013-11-02 Thread Marvin Löbel
On 11/02/2013 04:34 PM, Niko Matsakis wrote: I am generally in favor of this proposal. It seems to be a reasonable way forward. It is unclear to me how many types would benefit from this approach of having methods for each variant, but `Result` certainly does. With respect to possible confusion

[rust-dev] Checking error at opening file

2013-11-02 Thread John Mija
How to check an error at opening a file but without closing its file descriptor? use std::path; use std::rt::io; use std::rt::io::file; let filename = "/some/path"; let f = file::open(&path::Path::new(filename), io::Open, io::Read); ___ Rust-dev maili

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Leah Hanson
Thanks! :D It compiles now! (and works) The working code is here: https://github.com/astrieanna/rust-fun/blob/one_worker_per_element/pmap.rs Best, Leah On Sat, Nov 2, 2013 at 5:21 PM, Simon Sapin wrote: > Le 02/11/2013 21:05, Leah Hanson a écrit : > > Thanks, Brendan. :) >> >> You’re

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Simon Sapin
Le 02/11/2013 21:05, Leah Hanson a écrit : Thanks, Brendan. :) You’re trying to move the ~strs out of the vector. You’ll need to use `move_iter`: Is this "moving" about moving memory around or about promising the compiler that I won't use those elements of the vector again? ~str is an

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Tim Kuehn
Instead of `do spawn` try `do spawn_with(s) |s| { ... }`. Then the closure won't close over s, but rather take it as an argument, allowing it to move it out. Cheers On Sat, Nov 2, 2013 at 5:05 PM, Leah Hanson wrote: > Thanks, Brendan. :) > > You’re trying to move the ~strs out of the vector. Y

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Leah Hanson
Thanks, Brendan. :) You’re trying to move the ~strs out of the vector. You’ll need to use > `move_iter`: > Is this "moving" about moving memory around or about promising the compiler that I won't use those elements of the vector again? > ~~~ > let ports = do myvect.move_iter().map |s| { > le

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Brendan Zabarauskas
You’re trying to move the ~strs out of the vector. You’ll need to use `move_iter`: ~~~ let ports = do myvect.move_iter().map |s| { let (pport, cchan) = stream(); do spawn { cchan.send(fun(s)) } pport }.to_owned_vec(); ~~~ Also note the use of `to_owned_vec`. `map` lazily

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Leah Hanson
Thanks, Scott, I think that's closer. However, now I'm having trouble with my pointer types. Using the element inside a spawn means that I need to capture the owned string in the right way so that the compiler allows me to give it to the other task. This version: ~~~ let ports = do myvect.iter().

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Scott Lawrence
I would think: let ports = do myvect.iter().map { |e| something(e) } On Sat, 2 Nov 2013, Leah Hanson wrote: Hi, I have a ~[~str]. I have code that will turn a ~str into a Port. I want to end up with a [Port]. (or ~ or @ or whatever. I just want to be able to iterate over the Ports later.) S

[rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Leah Hanson
Hi, I have a ~[~str]. I have code that will turn a ~str into a Port. I want to end up with a [Port]. (or ~ or @ or whatever. I just want to be able to iterate over the Ports later.) Since I'm not sure what looping construct to use, I tried with a for-each loop. ~~~ let ports = for s in myvect.i

Re: [rust-dev] RFC about std::option and std::result API

2013-11-02 Thread Niko Matsakis
I am generally in favor of this proposal. It seems to be a reasonable way forward. It is unclear to me how many types would benefit from this approach of having methods for each variant, but `Result` certainly does. With respect to possible confusion between `is_ok()` and `ok()` -- I think that th

Re: [rust-dev] RFC about std::option and std::result API

2013-11-02 Thread Andres Osinski
A '?' suffix for boolean methods would be fantastic. On Sat, Nov 2, 2013 at 4:40 AM, Oren Ben-Kiki wrote: > I would love it if '?' was allowed at the end of any identifier, to make it > natural to name boolean variables, methods, constants, etc. Having to say > is_xxx is ugly IMO. A lint option e

Re: [rust-dev] RFC about std::option and std::result API

2013-11-02 Thread Oren Ben-Kiki
I would love it if '?' was allowed at the end of any identifier, to make it natural to name boolean variables, methods, constants, etc. Having to say is_xxx is ugly IMO. A lint option ensuring this is only applied to boolean typed constructs could help reduce abuse, if this is seen as an issue. On