snaggen@programming.dev to Rust@programming.dev · 8 个月前Announcing Rust 1.76.0blog.rust-lang.orgexternal-linkmessage-square20fedilinkarrow-up196
arrow-up196external-linkAnnouncing Rust 1.76.0blog.rust-lang.orgsnaggen@programming.dev to Rust@programming.dev · 8 个月前message-square20fedilink
minus-squareanlumo@feddit.delinkfedilinkEnglisharrow-up16arrow-down2·8 个月前Oh, inspect has finally arrived! That will help a ton with debug logging.
minus-squareλλλ@programming.devlinkfedilinkarrow-up6·edit-28 个月前Do you mind explaining? Maybe with the context of another languages equivalent?
minus-squareanlumo@feddit.delinkfedilinkEnglisharrow-up12arrow-down2·8 个月前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 });
minus-squarexav@programming.devlinkfedilinkarrow-up1·8 个月前Warning: in the first case “value” is actually a shared reference, not a value.
minus-squareGissaMittJobb@lemmy.mllinkfedilinkarrow-up2·8 个月前Looks vaguely like Stream::peek from Java, I think? There’s an equivalent method in Iterator::inspect.
minus-squareowsei@programming.devlinkfedilinkarrow-up1·edit-28 个月前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.
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?
is equivalent to
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.