Announcing Rust 1.76.0
Announcing Rust 1.76.0
blog.rust-lang.org Announcing Rust 1.76.0 | Rust Blog
Empowering everyone to build reliable and efficient software.
You're viewing a single thread.
View all comments
23
comments
Oh,
inspect
has finally arrived! That will help a ton with debug logging.19 2 ReplyDo you mind explaining? Maybe with the context of another languages equivalent?
7 0 Replylet 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 });
15 2 ReplyElegant. Thanks!
1 0 ReplyWarning: in the first case "value" is actually a shared reference, not a value.
1 0 Reply
Looks vaguely like
Stream::peek
from Java, I think? There's an equivalent method inIterator::inspect
.2 0 Replyit'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.
1 0 Reply
You've viewed 23 comments.
Scroll to top