You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create problem occurrences from a shared ProblemType through calls such as INVALID_PARAMETERS.detail(message).instance(uri). These calls borrow the type URI and title from the definition, and callers can omit extensions without constructing NoExtensions.
Add const conversions from &ProblemType and ProblemType to ProblemDetails, with empty extensions and omitted occurrence fields. Converting a reference borrows the metadata; converting an owned definition moves it.
Add .detail(), .instance(), and .extensions() to both types. Each call returns complete problem details, and replacing extensions can change their type.
Default the extension type to NoExtensions.
Support const construction through nightly const traits. The destruction bound applies to the old extension value when it is replaced; runtime calls support extensions with ordinary Drop implementations.
Document the methods with complete examples for borrowed explanations, owned instance URIs, and serialized extension members.
Use the fluent methods in existing serialization tests and check borrowed and owned strings with assert_matches!.
Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
modifies a Cargo-publishable library, but it is not yet ready to publish
📜 Does this require a change to the docs?
The changes in this PR:
require changes to docs which are made as part of this PR
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
do not affect the execution graph
⚠️ Known issues
The crate requires nightly features const_convert, const_destruct, and const_trait_impl. Const callers use Cow::Borrowed(...) for string literals and enable const_convert and const_trait_impl. Runtime calls accept &str, String, and Cow.
🐾 Next steps
Connect problem definitions to OpenAPI and the public /v1 API in follow-up work.
🛡 What tests cover this?
Five doctests cover runtime and const construction, borrowed explanations, owned instance URIs, and serialized extension members.
A source-local unit test verifies that converting a reference borrows the definition's owned metadata strings.
The details_static_metadata integration test creates an occurrence through fluent calls, checks that the detail and instance borrow the original strings, and checks the serialized output.
All 30 crate tests pass, including extension-validation tests and JSON Schema snapshots. All five doctests, Clippy, Rustdoc, and formatting checks also pass.
❓ How to test this?
Run from the repository root with the pinned toolchain:
let details = INVALID_PARAMETERS.detail("The limit must be a positive integer.").instance("/problem-occurrences/42");let details = details.extensions(extensions);let details = ProblemDetails::from(&INVALID_PARAMETERS);
Low Risk
Library-only API ergonomics for HTTP problem details; no auth, persistence, or wire-format behavior changes beyond optional default type parameter.
Overview Connects shared ProblemType definitions to RFC 9457 occurrences via From conversions and a fluent builder API, so callers can write INVALID_PARAMETERS.detail(msg).instance(uri) instead of manually copying metadata and NoExtensions.
ProblemDetails now defaults its extension type parameter to NoExtensions. Both ProblemType and ProblemDetails gain const detail, instance, and extensions methods; reference-based conversion borrows type URI/title from the definition when possible. The crate enables nightly const-trait features (const_convert, const_destruct, const_trait_impl) to support const construction.
Tests and doctests are updated to use the new API and assert borrowing behavior with assert_matches!.
Reviewed by Cursor Bugbot for commit a05f516. Bugbot is set up for automated code reviews on this repo. Configure here.
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
area/libsRelates to first-party libraries/crates/packages (area)area/testsNew or updated tests
2 participants
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.
🌟 What is the purpose of this PR?
Create problem occurrences from a shared
ProblemTypethrough calls such asINVALID_PARAMETERS.detail(message).instance(uri). These calls borrow the type URI and title from the definition, and callers can omit extensions without constructingNoExtensions.🔗 Related links
ProblemTypeandProblemDetails(internal)Ignore BE-353
🚫 Blocked by
problematiccrate #9683 — the initialproblematiccrate; this PR is based on its branch.🔍 What does this change?
&ProblemTypeandProblemTypetoProblemDetails, with empty extensions and omitted occurrence fields. Converting a reference borrows the metadata; converting an owned definition moves it..detail(),.instance(), and.extensions()to both types. Each call returns complete problem details, and replacing extensions can change their type.NoExtensions.Dropimplementations.assert_matches!.Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
The crate requires nightly features
const_convert,const_destruct, andconst_trait_impl. Const callers useCow::Borrowed(...)for string literals and enableconst_convertandconst_trait_impl. Runtime calls accept&str,String, andCow.🐾 Next steps
Connect problem definitions to OpenAPI and the public
/v1API in follow-up work.🛡 What tests cover this?
details_static_metadataintegration test creates an occurrence through fluent calls, checks that the detail and instance borrow the original strings, and checks the serialized output.❓ How to test this?
Run from the repository root with the pinned toolchain:
📹 Demo