Skip to content

Polish lazy_format!#1274

Open
hildebrandmw wants to merge 7 commits into
mainfrom
mhildebr/lazystring
Open

Polish lazy_format!#1274
hildebrandmw wants to merge 7 commits into
mainfrom
mhildebr/lazystring

Conversation

@hildebrandmw

@hildebrandmw hildebrandmw commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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 move variant to lazy_format!), the created LazyString can be both 'static and Debug, allowing it to be passed to ANNError::message. This enables error reporting like

let x = "context";
let y = 10;

let err = ANNError::message(
    ANNErrorKind::Opaque,
    lazy_format!(move, "error message: {x} - {y}),
);

The generated code is as-if we wrote

let x = "context";
let y = 10;

#[derive(Debug)]
struct Message {
    x: &'static str,
    y: usize,
}

impl std::fmt::Display for Message {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "errro message: {} - {}", self.x, self.y)
    }
}

let err = ANNError::message(
    ANNErrorKind::Opaque,
    Message { x, y }
);

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LazyString implementation to use std::fmt::Result directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread diskann-utils/src/lazystring.rs Outdated
Copilot AI review requested due to automatic review settings July 25, 2026 00:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@codecov-commenter

codecov-commenter commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.50%. Comparing base (6caca35) to head (451d2df).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1274   +/-   ##
=======================================
  Coverage   91.50%   91.50%           
=======================================
  Files         498      498           
  Lines       95522    95536   +14     
=======================================
+ Hits        87407    87424   +17     
+ Misses       8115     8112    -3     
Flag Coverage Δ
miri 91.50% <100.00%> (+<0.01%) ⬆️
unittests 91.47% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
diskann-utils/src/lazystring.rs 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings July 25, 2026 00:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 move arm: the non-move arm uses an unqualified write!, which can be shadowed by downstream macros at the expansion site. Use a fully qualified macro path such as ::core::write!.
            write!(f, $($arg)*)

Comment thread diskann-utils/src/lazystring.rs Outdated
Copilot AI review requested due to automatic review settings July 25, 2026 00:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines +61 to +63
/// If a lazily formatted `'static` compliant variation is needed, the "move" variant
/// can be used:
///
Copilot AI review requested due to automatic review settings July 25, 2026 00:52
@hildebrandmw hildebrandmw changed the title Polish lazy_format!'s documentation. Polish lazy_format!' Jul 25, 2026
@hildebrandmw hildebrandmw changed the title Polish lazy_format!' Polish lazy_format! Jul 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 'static LazyString, but move only captures arguments by value; the result is 'static only if the captured values themselves are 'static (or owned types that don’t borrow). Clarifying this avoids misleading users into thinking move guarantees '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:
///

Copilot AI review requested due to automatic review settings July 25, 2026 00:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants