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
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.

## [0.10.7] - 2025-10-24

### Fixed
- Published the shared template parser crate so `masterror-derive` no longer
depends on a workspace-only package when uploaded to crates.io.

### Documentation
- Added a dedicated README for `masterror-template` describing installation,
parsing examples and formatter metadata for crates.io readers.
### Tests
- Added regression coverage for long classifier needles to exercise the
heap-allocation fallback.
Expand All @@ -16,6 +23,8 @@ All notable changes to this project will be documented in this file.
- Precomputed lowercase Turnkey classifier needles with a stack-backed buffer
to remove repeated transformations while keeping the common zero-allocation
path for short patterns.
- Bumped `masterror-derive` to `0.6.6` and `masterror-template` to `0.3.6` so
downstream users rely on the newly published parser crate.


## [0.10.6] - 2025-09-21
Expand Down Expand Up @@ -168,6 +177,12 @@ All notable changes to this project will be documented in this file.
- Documented the `#[app_error(...)]` attribute in the README, outlining the
struct and enum mapping patterns and the `message` flag behaviour.

## [0.6.6] - 2025-10-24

### Fixed
- Pointed the derive crate at the published `masterror-template` dependency so
`cargo publish` succeeds without private workspace patches.

## [0.6.5] - 2025-10-12

### Added
Expand Down Expand Up @@ -465,6 +480,15 @@ All notable changes to this project will be documented in this file.
### Documentation
- Documented browser/WASM support and console logging workflow in the README and crate docs.

## [0.3.6] - 2025-10-24

### Added
- Wrote a README for crates.io explaining installation and parser usage.

### Fixed
- Removed the `publish = false` flag so the shared template parser can be
released alongside the derive crate.

## [0.3.5] - 2025-09-12
### Added
- Conversion from `teloxide_core::RequestError` into `AppError` (feature `teloxide`).
Expand Down Expand Up @@ -565,10 +589,19 @@ All notable changes to this project will be documented in this file.
- **MSRV:** 1.89
- **No unsafe:** the crate forbids `unsafe`.

[0.10.7]: https://github.com/RAprogramm/masterror/releases/tag/v0.10.7
[0.10.6]: https://github.com/RAprogramm/masterror/releases/tag/v0.10.6
[0.6.6]: https://github.com/RAprogramm/masterror/releases/tag/v0.6.6
[0.6.5]: https://github.com/RAprogramm/masterror/releases/tag/v0.6.5
[0.6.4]: https://github.com/RAprogramm/masterror/releases/tag/v0.6.4
[0.6.3]: https://github.com/RAprogramm/masterror/releases/tag/v0.6.3
[0.6.2]: https://github.com/RAprogramm/masterror/releases/tag/v0.6.2
[0.6.0]: https://github.com/RAprogramm/masterror/releases/tag/v0.6.0
[0.5.2]: https://github.com/RAprogramm/masterror/releases/tag/v0.5.2
[0.5.1]: https://github.com/RAprogramm/masterror/releases/tag/v0.5.1
[0.5.0]: https://github.com/RAprogramm/masterror/releases/tag/v0.5.0
[0.4.0]: https://github.com/RAprogramm/masterror/releases/tag/v0.4.0
[0.3.6]: https://github.com/RAprogramm/masterror/releases/tag/v0.3.6
[0.3.5]: https://github.com/RAprogramm/masterror/releases/tag/v0.3.5
[0.3.4]: https://github.com/RAprogramm/masterror/releases/tag/v0.3.4
[0.3.3]: https://github.com/RAprogramm/masterror/releases/tag/v0.3.3
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ turnkey = []
openapi = ["dep:utoipa"]

[workspace.dependencies]
masterror-derive = { version = "0.6.2" }
masterror-template = { version = "0.3.1" }
masterror-derive = { version = "0.6.6" }
masterror-template = { version = "0.3.6" }

[dependencies]
masterror-derive = { version = "0.6" }
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,4 +709,3 @@ MSRV = 1.90 (may raise in minor, never in patch).
Apache-2.0 OR MIT, at your option.

</details>

2 changes: 1 addition & 1 deletion masterror-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "masterror-derive"
rust-version = "1.90"
version = "0.6.2"
version = "0.6.6"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/RAprogramm/masterror"
Expand Down
3 changes: 1 addition & 2 deletions masterror-template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[package]
name = "masterror-template"
version = "0.3.1"
version = "0.3.6"
rust-version = "1.90"
edition = "2024"
repository = "https://github.com/RAprogramm/masterror"
readme = "README.md"
description = "Template utilities for masterror and its derive macros"
publish = false
license = "MIT OR Apache-2.0"

[dependencies]
81 changes: 81 additions & 0 deletions masterror-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# masterror-template

`masterror-template` packages the template parser shared by the [`masterror`][masterror] runtime crate and the [`masterror-derive`][derive] procedural macros. It understands the `#[error("...")]` formatting language popularised by `thiserror` v2, producing a structured representation that downstream code can inspect or render.

The crate is intentionally small: it exposes just enough API for advanced applications that want to inspect derived error displays, implement custom derive helpers, or perform static analysis over formatting placeholders.

## Installation

Add the crate alongside `masterror` if you need direct access to the parser:

```toml
[dependencies]
masterror-template = { version = "0.3.6" }
```

`masterror-template` targets Rust 1.90 and builds on stable and nightly toolchains alike.

## Parsing templates

Call [`ErrorTemplate::parse`](https://docs.rs/masterror-template/latest/masterror_template/template/struct.ErrorTemplate.html#method.parse) to turn an `&str` into a structured template:

```rust
use masterror_template::template::{ErrorTemplate, TemplateIdentifier};

fn inspect(template: &str) {
let parsed = ErrorTemplate::parse(template).expect("valid template");

for placeholder in parsed.placeholders() {
match placeholder.identifier() {
TemplateIdentifier::Named(name) => println!("named placeholder: {name}"),
TemplateIdentifier::Positional(index) => println!("positional placeholder: {index}"),
TemplateIdentifier::Implicit(index) => println!("implicit placeholder: {index}"),
}
}
}
```

The parser preserves literal text and exposes every placeholder with span metadata, making it straightforward to surface diagnostics or transform templates programmatically.

## Formatter metadata

Each [`TemplatePlaceholder`](https://docs.rs/masterror-template/latest/masterror_template/template/struct.TemplatePlaceholder.html) advertises the requested formatter through [`TemplateFormatter`](https://docs.rs/masterror-template/latest/masterror_template/template/enum.TemplateFormatter.html) and [`TemplateFormatterKind`](https://docs.rs/masterror-template/latest/masterror_template/template/enum.TemplateFormatterKind.html):

```rust
use masterror_template::template::{ErrorTemplate, TemplateFormatterKind};

let template = ErrorTemplate::parse("{value:#x}").expect("parse");
let placeholder = template.placeholders().next().expect("placeholder");
let formatter = placeholder.formatter();
assert_eq!(formatter.kind(), TemplateFormatterKind::LowerHex);
assert!(formatter.is_alternate());
```

This mirrors the formatting traits accepted by `core::fmt`, enabling consumers to route values through `Display`, `Debug`, hexadecimal, binary, pointer, or exponential renderers.

## Error reporting

Parsing failures produce [`TemplateError`](https://docs.rs/masterror-template/latest/masterror_template/template/enum.TemplateError.html) variants with precise byte ranges. The metadata simplifies IDE integrations and procedural macros that need to point at the offending part of the template.

```rust
use masterror_template::template::ErrorTemplate;

let err = ErrorTemplate::parse("{foo").unwrap_err();
assert!(matches!(err, masterror_template::template::TemplateError::UnterminatedPlaceholder { .. }));
```

## License

Dual licensed under either of

- Apache License, Version 2.0, ([LICENSE-APACHE](../LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](../LICENSE-MIT) or <http://opensource.org/licenses/MIT>)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

[masterror]: https://crates.io/crates/masterror
[derive]: https://crates.io/crates/masterror-derive
Loading