Polish lazy_format!#1274
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the documentation for the lazy_format! macro (and related LazyString type) in diskann-utils, aiming to better reflect current behavior and provide clearer, example-driven guidance.
Changes:
- Replaces outdated/async-logging-focused docs with a focused description of
lazy_format!and how it defers formatting. - Adds a richer rustdoc example demonstrating deferred formatting behavior.
- Cleans up the
LazyStringimplementation to usestd::fmt::Resultdirectly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1274 +/- ##
=======================================
Coverage 91.50% 91.50%
=======================================
Files 498 498
Lines 95522 95536 +14
=======================================
+ Hits 87407 87424 +17
+ Misses 8115 8112 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
diskann-utils/src/lazystring.rs:84
- Same hygiene issue as the
movearm: the non-movearm uses an unqualifiedwrite!, which can be shadowed by downstream macros at the expansion site. Use a fully qualified macro path such as::core::write!.
write!(f, $($arg)*)
| /// If a lazily formatted `'static` compliant variation is needed, the "move" variant | ||
| /// can be used: | ||
| /// |
lazy_format!'s documentation.lazy_format!'
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
diskann-utils/src/lazystring.rs:63
- The docs imply that using
lazy_format!(move, ...)produces a'staticLazyString, butmoveonly captures arguments by value; the result is'staticonly if the captured values themselves are'static(or owned types that don’t borrow). Clarifying this avoids misleading users into thinkingmoveguarantees'static.
/// The default [`LazyString`] created by this macro borrows from its formatted arguments
/// and thus has a lifetime constrained to its arguments.
///
/// If a lazily formatted `'static` compliant variation is needed, the "move" variant
/// can be used:
///
I recently used this utility and noticed that the docs were a little out of date.
In addition, with some extra work (i.e., adding a
movevariant tolazy_format!), the createdLazyStringcan be both'staticandDebug, allowing it to be passed toANNError::message. This enables error reporting likeThe generated code is as-if we wrote
But is more ergonomic to construct. The main benefit here is that it moves string formatting out of the error construction site and up to the error reporting site. Depending on the context, this code motion can clean up the lower level code.