Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

_No changes yet._
### Added
- `masterror::error::template` module providing a parsed representation of
`#[error("...")]` strings and a formatter hook for future custom derives.

## [0.5.0] - 2025-09-23

Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ assert_eq!(wrapped.to_string(), "I/O failed: disk offline");
valid.
- `#[error(transparent)]` enforces single-field wrappers that forward
`Display`/`source` to the inner error.
- `masterror::error::template::ErrorTemplate` parses `#[error("...")]`
strings, exposing literal and placeholder segments so custom derives can be
implemented without relying on `thiserror`.

```rust
use masterror::error::template::{ErrorTemplate, TemplateIdentifier};

let template = ErrorTemplate::parse("{code}: {message}").expect("parse");
let display = template.display_with(|placeholder, f| match placeholder.identifier() {
TemplateIdentifier::Named("code") => write!(f, "{}", 404),
TemplateIdentifier::Named("message") => f.write_str("Not Found"),
_ => Ok(()),
});

assert_eq!(display.to_string(), "404: Not Found");
```

</details>

Expand Down Expand Up @@ -329,4 +345,3 @@ MSRV = 1.89 (may raise in minor, never in patch).
Apache-2.0 OR MIT, at your option.

</details>

16 changes: 16 additions & 0 deletions README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ assert_eq!(wrapped.to_string(), "I/O failed: disk offline");
valid.
- `#[error(transparent)]` enforces single-field wrappers that forward
`Display`/`source` to the inner error.
- `masterror::error::template::ErrorTemplate` parses `#[error("...")]`
strings, exposing literal and placeholder segments so custom derives can be
implemented without relying on `thiserror`.

```rust
use masterror::error::template::{ErrorTemplate, TemplateIdentifier};

let template = ErrorTemplate::parse("{code}: {message}").expect("parse");
let display = template.display_with(|placeholder, f| match placeholder.identifier() {
TemplateIdentifier::Named("code") => write!(f, "{}", 404),
TemplateIdentifier::Named("message") => f.write_str("Not Found"),
_ => Ok(()),
});

assert_eq!(display.to_string(), "404: Not Found");
```

</details>

Expand Down
14 changes: 14 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Utilities for building custom error derive infrastructure.
//!
//! This module exposes lower-level building blocks that will eventually power
//! a native replacement for the `thiserror` derive. The initial goal is to
//! parse and validate display templates (`#[error("...")]`) in a reusable
//! and well-tested manner so that future procedural macros can focus on
//! generating code.
//!
//! The API is intentionally low level. It makes no assumptions about how the
//! parsed data is going to be used and instead provides precise spans and
//! formatting metadata that higher-level code can rely on.

/// Parser and formatter helpers for `#[error("...")]` templates.
pub mod template;
Loading
Loading