2 ms·
> but could you get that to compile to the same machine code as this? Well not exactly because the second snippet is not equivalent to the first one (it doesn'
by masklinn 12y ago
> but could you get that to compile to the same machine code as this?
Well not exactly because the second snippet is not equivalent to the first one (it doesn't wrap the result of parse_value() back into an Ok(), and thus I guess wouldn't compile), but aside from that yes: Result.map is trivially implemented in terms of match and (almost always) inlined: https://github.com/rust-lang/rust/blob/master/src/libcore/result.rs#L514 https://github.com/rust-lang/rust/blob/master/src/libcore/re... and the closure is itself inlined. So the resulting assembly should be the exact same between the two versions