Skip to content

Add suggestion, refactor Format and add Remove ContextFormat#4

Merged
maxwase merged 3 commits into
masterfrom
add-suggestion
May 17, 2026
Merged

Add suggestion, refactor Format and add Remove ContextFormat#4
maxwase merged 3 commits into
masterfrom
add-suggestion

Conversation

@maxwase
Copy link
Copy Markdown
Owner

@maxwase maxwase commented May 17, 2026

This pull request introduces a new type-level combinator for composing error formatting strategies, expands the formatting API, and updates the documentation and examples to match. It also makes several breaking changes to the Format trait and related APIs to support more flexible composition of formatting strategies and error types.

New formatting combinators and strategies:

  • Added the Add<L, R> combinator and the separator module, providing type-level composition of two Format strategies and built-in separator strategies like NewLine, Space, Colon, ColonSpace, and convenience aliases such as WithSep, WithSpace, WithNewLine, and WithColonSpace. This enables building custom error formatting strategies by composing existing ones. [1] [2]
  • Exposed the new combinators and strategies in the crate root, making them available for users.

API changes and trait improvements:

  • Breaking: Changed the Format trait to be generic over the formatted type (Format<E: ?Sized>) instead of requiring E: Error at the trait level. This allows composing formatting strategies through non-error types, such as context wrappers. [1] [2]
  • Updated the Formatted wrapper and its Display implementation to work with the new generic Format<E> trait.
  • Added the suggestion() helper to the FormatError trait, rendering only the top-level suggestion hint for errors that implement Suggest. [1] [2]

Documentation and examples:

  • Updated the README.md and examples/custom_format.rs to demonstrate the new compositional formatting strategies, the new Format<E> trait, and the use of combinators and separators. [1] [2] [3]
  • Expanded documentation for custom formatting strategies and how to combine them, including detailed examples of composing strategies and using suggestions. [1] [2]

Deprecations and removals:

  • Breaking: Removed the FormatOneLine type alias and the with_context::ContextFormat trait, which are now superseded by the new composition approach.

Internal refactoring and tests:

  • Updated internal tests and implementations to use the new generic Format<E> trait and combinators, ensuring coverage of the new composition model. [1] [2]

These changes provide a more flexible and composable system for error formatting, making it easier to build custom error displays and hints with reusable building blocks.

Copy link
Copy Markdown

Copilot AI left a comment

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 refactors error formatting around a generic Format<E> trait and adds composable formatting strategies, including suggestions and separator-based combinators.

Changes:

  • Adds Add<L, R> and separator strategies for type-level composition of formatters.
  • Introduces Suggest, Suggestion, and MainResultWithSuggestion.
  • Updates WithContext, examples, README, and changelog for the new formatting API.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/add.rs Adds composable formatter combinator and separator strategies.
src/lib.rs Refactors Format to be generic and exports new APIs.
src/main_result.rs Adds suggestion-aware main result aliases and tests.
src/suggestion.rs Adds Suggest trait and Suggestion formatter.
src/with_context.rs Refactors context formatting to use generic Format composition.
src/oneline.rs Updates OneLine for generic Format<E>.
src/tree.rs Updates Tree for generic Format<E>.
src/path_display.rs Updates docs for the new context path formatter.
examples/custom_format.rs Updates custom formatter example for Format<E>.
README.md Documents composing strategies, suggestions, and new API shape.
CHANGELOG.md Records added, changed, and removed public APIs.

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

Comment thread src/with_context.rs Outdated
Comment thread src/main_result.rs
@maxwase maxwase merged commit eac8a28 into master May 17, 2026
4 checks passed
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.

2 participants