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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ All notable changes to this project will be documented in this file.
### Added
- _Nothing yet._

## [0.6.0] - 2025-10-08

### Added
- Recognised empty placeholder bodies (`{}` / `{:?}`) as implicit positional
identifiers, numbering them by appearance and exposing the new
`TemplateIdentifier::Implicit` variant in the template API.
- Propagated the implicit identifier metadata through
`template_support::TemplateIdentifierSpec`, ensuring derive-generated display
implementations resolve tuple fields in placeholder order.

### Fixed
- Preserved `TemplateError::EmptyPlaceholder` diagnostics for whitespace-only
placeholders, matching previous error reporting for invalid bodies.

### Tests
- Added parser regressions covering implicit placeholder sequencing and the
whitespace-only error path.

## [0.5.15] - 2025-10-07

### Added
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "masterror"
version = "0.5.15"
version = "0.6.0"
rust-version = "1.90"
edition = "2024"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -49,8 +49,8 @@ turnkey = []
openapi = ["dep:utoipa"]

[workspace.dependencies]
masterror-derive = { version = "0.1.7", path = "masterror-derive" }
masterror-template = { version = "0.1.4", path = "masterror-template" }
masterror-derive = { version = "0.2.0", path = "masterror-derive" }
masterror-template = { version = "0.2.0", path = "masterror-template" }

[dependencies]
masterror-derive = { workspace = true }
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Stable categories, conservative HTTP mapping, no `unsafe`.

~~~toml
[dependencies]
masterror = { version = "0.5.15", default-features = false }
masterror = { version = "0.6.0", default-features = false }
# or with features:
# masterror = { version = "0.5.15", features = [
# masterror = { version = "0.6.0", features = [
# "axum", "actix", "openapi", "serde_json",
# "sqlx", "sqlx-migrate", "reqwest", "redis",
# "validator", "config", "tokio", "multipart",
Expand Down Expand Up @@ -66,10 +66,10 @@ masterror = { version = "0.5.15", default-features = false }
~~~toml
[dependencies]
# lean core
masterror = { version = "0.5.15", default-features = false }
masterror = { version = "0.6.0", default-features = false }

# with Axum/Actix + JSON + integrations
# masterror = { version = "0.5.15", features = [
# masterror = { version = "0.6.0", features = [
# "axum", "actix", "openapi", "serde_json",
# "sqlx", "sqlx-migrate", "reqwest", "redis",
# "validator", "config", "tokio", "multipart",
Expand Down Expand Up @@ -383,13 +383,13 @@ assert_eq!(resp.status, 401);
Minimal core:

~~~toml
masterror = { version = "0.5.15", default-features = false }
masterror = { version = "0.6.0", default-features = false }
~~~

API (Axum + JSON + deps):

~~~toml
masterror = { version = "0.5.15", features = [
masterror = { version = "0.6.0", features = [
"axum", "serde_json", "openapi",
"sqlx", "reqwest", "redis", "validator", "config", "tokio"
] }
Expand All @@ -398,7 +398,7 @@ masterror = { version = "0.5.15", features = [
API (Actix + JSON + deps):

~~~toml
masterror = { version = "0.5.15", features = [
masterror = { version = "0.6.0", features = [
"actix", "serde_json", "openapi",
"sqlx", "reqwest", "redis", "validator", "config", "tokio"
] }
Expand Down
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.1.7"
version = "0.2.0"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/RAprogramm/masterror"
Expand Down
17 changes: 17 additions & 0 deletions masterror-derive/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ fn struct_placeholder_expr(
}
}
TemplateIdentifierSpec::Positional(index) => fields
.get_positional(*index)
.map(|field| struct_field_expr(field, placeholder.formatter))
.ok_or_else(|| placeholder_error(placeholder.span, &placeholder.identifier)),
TemplateIdentifierSpec::Implicit(index) => fields
.get_positional(*index)
.map(|field| struct_field_expr(field, placeholder.formatter))
.ok_or_else(|| placeholder_error(placeholder.span, &placeholder.identifier))
Expand Down Expand Up @@ -298,6 +302,15 @@ fn variant_tuple_placeholder(
Err(placeholder_error(placeholder.span, &placeholder.identifier))
}
TemplateIdentifierSpec::Positional(index) => bindings
.get(*index)
.map(|binding| {
ResolvedPlaceholderExpr::with(
quote!(#binding),
needs_pointer_value(placeholder.formatter)
)
})
.ok_or_else(|| placeholder_error(placeholder.span, &placeholder.identifier)),
TemplateIdentifierSpec::Implicit(index) => bindings
.get(*index)
.map(|binding| {
ResolvedPlaceholderExpr::with(
Expand Down Expand Up @@ -338,6 +351,10 @@ fn variant_named_placeholder(
TemplateIdentifierSpec::Positional(index) => Err(placeholder_error(
placeholder.span,
&TemplateIdentifierSpec::Positional(*index)
)),
TemplateIdentifierSpec::Implicit(index) => Err(placeholder_error(
placeholder.span,
&TemplateIdentifierSpec::Implicit(*index)
))
}
}
Expand Down
3 changes: 3 additions & 0 deletions masterror-derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,5 +826,8 @@ pub fn placeholder_error(span: Span, identifier: &TemplateIdentifierSpec) -> Err
TemplateIdentifierSpec::Positional(index) => {
Error::new(span, format!("field `{}` is not available", index))
}
TemplateIdentifierSpec::Implicit(index) => {
Error::new(span, format!("field `{}` is not available", index))
}
}
}
4 changes: 3 additions & 1 deletion masterror-derive/src/template_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub struct TemplatePlaceholderSpec {
#[derive(Debug, Clone)]
pub enum TemplateIdentifierSpec {
Named(String),
Positional(usize)
Positional(usize),
Implicit(usize)
}

pub fn parse_display_template(lit: LitStr) -> Result<DisplayTemplate, Error> {
Expand All @@ -49,6 +50,7 @@ pub fn parse_display_template(lit: LitStr) -> Result<DisplayTemplate, Error> {
TemplateIdentifier::Positional(index) => {
TemplateIdentifierSpec::Positional(*index)
}
TemplateIdentifier::Implicit(index) => TemplateIdentifierSpec::Implicit(*index)
};

segments.push(TemplateSegmentSpec::Placeholder(TemplatePlaceholderSpec {
Expand Down
2 changes: 1 addition & 1 deletion masterror-template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "masterror-template"
version = "0.1.4"
version = "0.2.0"
rust-version = "1.90"
edition = "2024"
repository = "https://github.com/RAprogramm/masterror"
Expand Down
31 changes: 30 additions & 1 deletion masterror-template/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ impl<'a> TemplatePlaceholder<'a> {
/// Placeholder identifier parsed from the template.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TemplateIdentifier<'a> {
/// Implicit positional index inferred from the placeholder order (`{}` /
/// `{:?}` / etc.).
Implicit(usize),
/// Positional index (`{0}` / `{1:?}` / etc.).
Positional(usize),
/// Named field (`{name}` / `{kind:?}` / etc.).
Expand All @@ -150,7 +153,7 @@ impl<'a> TemplateIdentifier<'a> {
pub const fn as_str(&self) -> Option<&'a str> {
match self {
Self::Named(value) => Some(value),
Self::Positional(_) => None
Self::Positional(_) | Self::Implicit(_) => None
}
}
}
Expand Down Expand Up @@ -569,6 +572,32 @@ mod tests {
assert_eq!(placeholders[1].identifier(), &named("message"));
}

#[test]
fn parses_implicit_identifiers() {
let template = ErrorTemplate::parse("{}, {:?}, {name}, {}").expect("parse");
let mut placeholders = template.placeholders();

let first = placeholders.next().expect("first placeholder");
assert_eq!(first.identifier(), &TemplateIdentifier::Implicit(0));
assert_eq!(first.formatter(), TemplateFormatter::Display);

let second = placeholders.next().expect("second placeholder");
assert_eq!(second.identifier(), &TemplateIdentifier::Implicit(1));
assert_eq!(
second.formatter(),
TemplateFormatter::Debug {
alternate: false
}
);

let third = placeholders.next().expect("third placeholder");
assert_eq!(third.identifier(), &named("name"));

let fourth = placeholders.next().expect("fourth placeholder");
assert_eq!(fourth.identifier(), &TemplateIdentifier::Implicit(2));
assert!(placeholders.next().is_none());
}

#[test]
fn parses_debug_formatter() {
let template = ErrorTemplate::parse("{0:#?}").expect("parse");
Expand Down
Loading
Loading