@snaggen@programming.dev to Rust@programming.dev • 1 year agoAnnouncing Rust 1.76.0blog.rust-lang.orgexternal-linkmessage-square25fedilinkarrow-up1102arrow-down10
arrow-up1102arrow-down1external-linkAnnouncing Rust 1.76.0blog.rust-lang.org@snaggen@programming.dev to Rust@programming.dev • 1 year agomessage-square25fedilink
minus-square@anlumo@feddit.delinkfedilinkEnglish17•1 year agoOh, inspect has finally arrived! That will help a ton with debug logging.
minus-squareλλλlinkfedilink7•edit-21 year agoDo you mind explaining? Maybe with the context of another languages equivalent?
minus-square@anlumo@feddit.delinkfedilinkEnglish13•1 year agolet bar: Result<T, E> = ...; let foo = bar.inspect(|value| log::debug("{}", value)); is equivalent to let bar: Result<T, E> = ...; let foo = bar.map(|value| { log::debug("{}", value); value });
minus-square@xav@programming.devlinkfedilink0•1 year agoWarning: in the first case “value” is actually a shared reference, not a value.
minus-square@GissaMittJobb@lemmy.mllinkfedilink2•1 year agoLooks vaguely like Stream::peek from Java, I think? There’s an equivalent method in Iterator::inspect.
minus-square@owsei@programming.devlinkfedilink1•edit-21 year 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.
Oh,
inspect
has finally arrived! That will help a ton with debug logging.Do you mind explaining? Maybe with the context of another languages equivalent?
let bar: Result<T, E> = ...; let foo = bar.inspect(|value| log::debug("{}", value));
is equivalent to
let bar: Result<T, E> = ...; let foo = bar.map(|value| { log::debug("{}", value); value });
Elegant. Thanks!
Warning: in the first case “value” is actually a shared reference, not a value.
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.