Add suggestion, refactor Format and add Remove ContextFormat#4
Merged
Conversation
There was a problem hiding this comment.
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>andseparatorstrategies for type-level composition of formatters. - Introduces
Suggest,Suggestion, andMainResultWithSuggestion. - 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Formattrait and related APIs to support more flexible composition of formatting strategies and error types.New formatting combinators and strategies:
Add<L, R>combinator and theseparatormodule, providing type-level composition of twoFormatstrategies and built-in separator strategies likeNewLine,Space,Colon,ColonSpace, and convenience aliases such asWithSep,WithSpace,WithNewLine, andWithColonSpace. This enables building custom error formatting strategies by composing existing ones. [1] [2]API changes and trait improvements:
Formattrait to be generic over the formatted type (Format<E: ?Sized>) instead of requiringE: Errorat the trait level. This allows composing formatting strategies through non-error types, such as context wrappers. [1] [2]Formattedwrapper and itsDisplayimplementation to work with the new genericFormat<E>trait.suggestion()helper to theFormatErrortrait, rendering only the top-level suggestion hint for errors that implementSuggest. [1] [2]Documentation and examples:
README.mdandexamples/custom_format.rsto demonstrate the new compositional formatting strategies, the newFormat<E>trait, and the use of combinators and separators. [1] [2] [3]Deprecations and removals:
FormatOneLinetype alias and thewith_context::ContextFormattrait, which are now superseded by the new composition approach.Internal refactoring and tests:
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.