Elektrine lite

← Feed

@ekuber@hachyderm.io

2026-07-21 17:37 UTC

#RustLang pro-tip: When wanting to inspect the value of a binding in a let-chain, you can take advantage of blocks being expressions as well and add one in the middle of the chain if let Some(next) = iter.peek() && { tracing::info!(?next); true } && let Some(...) = ... This is less disruptive than having to disentangle the chain every time you want to inspect something in the middle #Rust

Replies (2)

  • @FineFindus@floss.social 2026-07-21 17:42

    @ekuber@hachyderm.io That's pretty neat, but wouldn't it be easier to use the dbg! macro?

    Open ##5313219

  • @ekuber@hachyderm.io That's a cool trick in general. In this case I'd opt to use Option::inspect. if let Some(next) = iter.peek().inspect(|next| tracing::info!(?next)) ... https://doc.rust-lang.org/std/option/enum.Option.html#method.inspect

    Open ##5313223