@[email protected] to [email protected] • 11 months agoAnnouncing Rust 1.76.0blog.rust-lang.orgexternal-linkmessage-square23fedilinkarrow-up1100arrow-down10
arrow-up1100arrow-down1external-linkAnnouncing Rust 1.76.0blog.rust-lang.org@[email protected] to [email protected] • 11 months agomessage-square23fedilink
minus-squareλλλlinkfedilink6•edit-211 months agoDo you mind explaining? Maybe with the context of another languages equivalent?
minus-square@[email protected]linkfedilinkEnglish12•11 months agolet bar: Result = ...; let foo = bar.inspect(|value| log::debug("{}", value)); is equivalent to let bar: Result = ...; let foo = bar.map(|value| { log::debug("{}", value); value });
minus-square@[email protected]linkfedilink1•11 months agoWarning: in the first case “value” is actually a shared reference, not a value.
minus-square@[email protected]linkfedilink2•11 months agoLooks vaguely like Stream::peek from Java, I think? There’s an equivalent method in Iterator::inspect.
minus-square@[email protected]linkfedilink1•edit-211 months agoit’s just a way to use map with a reference instead of the value, by what I understood. could be usefull for logging values in a Result so you can see it. However I think you can already do that by just mapping and returning the variable.
Do you mind explaining? Maybe with the context of another languages equivalent?
let bar: Result = ...; let foo = bar.inspect(|value| log::debug("{}", value));
is equivalent to
let bar: Result = ...; let foo = bar.map(|value| { log::debug("{}", value); value });
Warning: in the first case “value” is actually a shared reference, not a value.
Elegant. Thanks!
Looks vaguely like
Stream::peek
from Java, I think? There’s an equivalent method inIterator::inspect
.it’s just a way to use map with a reference instead of the value, by what I understood.
could be usefull for logging values in a Result so you can see it. However I think you can already do that by just mapping and returning the variable.