On Wed, Apr 4, 2012 at 4:39 PM, Brian Anderson <[email protected]>wrote:
> On 04/04/2012 08:17 AM, Masklinn wrote: > >> On 4 avr. 2012, at 17:09, Eric Holk<[email protected]> wrote: >> >>> In Rust, you can do something like this instead: >>> >>> let parts = vec::map([" a", "b ", " c ", "d"]) {|s| >>> str::trim(s) >>> }; >>> >> Isn't it possible to pass str::trim directly to vec::map? It the >> indirection through the block really needed? >> > > In this case I believe the block isn't necessary, but in many situations > it is so I've gotten used to just always using it (sadly). The reason is > because generic functions always take arguments by reference while > functions on scalars take their arguments by value, so composing them isn't > possible without an adapter between them. Strings are passed by reference > though so this example should work without the extra block. > > I originally wrote this without the extra block, and the compiler complained. I was also trying to use the extension methods (`[" a", "b ", " c ", "d"].map(str::trim)`) instead, but the compiler was having trouble finding them. I'm pretty sure I was using the rustc I had just pulled from Github. -Eric
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
