Add generic WithContext error#3
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a generic WithContext<C, E, F> error wrapper that pairs an error with a context value and renders both via a static ContextFormat strategy (Colon by default, PathColon for path-aware contexts, plus a WithPath alias). Also introduces an experimental DisplayPath newtype, a new with_context example, README documentation, and conditional no_std doc handling in lib.rs.
Changes:
- New
WithContext<C, E, F>type withContextFormatstrategy trait,Colon/PathColonstrategies,WithPathalias, andError::sourcethat skips the inner error to avoid duplication in chain walks. - New experimental
DisplayPath<T>adapter and an end-to-end example showing nestedWithContextlayers used withMainResult/thiserror. - README section documenting
WithContext/WithPathand alib.rstweak that switches between the README doc and a short fallback depending on thestdfeature.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/with_context.rs | Introduces WithContext, ContextFormat, Colon/PathColon strategies, aliases, and tests. |
| src/path_display.rs | Adds experimental DisplayPath<T> newtype adapting Path-like values to Display. |
| src/lib.rs | Registers new modules/re-exports and gates the README doc on the std feature. |
| examples/with_context.rs | End-to-end example combining nested WithContext with MainResult and thiserror. |
| README.md | Adds "Adding context" section documenting WithContext/WithPath; minor rewording elsewhere. |
| Cargo.toml | Marks the new with_context example as requiring the std feature. |
💡 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.
Also WithPath and experimental Path display wrapper