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

## [0.5.14] - 2025-10-06

### Added
- Prepared the derive input structures for future `format_args!` support by
introducing display specification variants for templates with arguments and
`fmt = <path>` handlers, along with `FormatArgsSpec`/`FormatArg` metadata
scaffolding.

## [0.5.13] - 2025-10-05

### Documentation
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
@@ -1,6 +1,6 @@
[package]
name = "masterror"
version = "0.5.13"
version = "0.5.14"
rust-version = "1.90"
edition = "2024"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -49,7 +49,7 @@ turnkey = []
openapi = ["dep:utoipa"]

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

[dependencies]
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.13", default-features = false }
masterror = { version = "0.5.14", default-features = false }
# or with features:
# masterror = { version = "0.5.13", features = [
# masterror = { version = "0.5.14", 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.13", default-features = false }
~~~toml
[dependencies]
# lean core
masterror = { version = "0.5.13", default-features = false }
masterror = { version = "0.5.14", default-features = false }

# with Axum/Actix + JSON + integrations
# masterror = { version = "0.5.13", features = [
# masterror = { version = "0.5.14", 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.13", default-features = false }
masterror = { version = "0.5.14", default-features = false }
~~~

API (Axum + JSON + deps):

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

~~~toml
masterror = { version = "0.5.13", features = [
masterror = { version = "0.5.14", features = [
"actix", "serde_json", "openapi",
"sqlx", "reqwest", "redis", "validator", "config", "tokio"
] }
Expand Down
4 changes: 2 additions & 2 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

~~~toml
[dependencies]
masterror = { version = "0.5.13", default-features = false }
masterror = { version = "0.5.14", default-features = false }
# или с нужными интеграциями
# masterror = { version = "0.5.13", features = [
# masterror = { version = "0.5.14", features = [
# "axum", "actix", "openapi", "serde_json",
# "sqlx", "sqlx-migrate", "reqwest", "redis",
# "validator", "config", "tokio", "multipart",
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.5"
version = "0.1.6"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/RAprogramm/masterror"
Expand Down
22 changes: 18 additions & 4 deletions masterror-derive/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use masterror_template::template::{TemplateFormatter, TemplateFormatterKind};
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
use syn::Error;
use syn::{Error, spanned::Spanned};

use crate::{
input::{
Expand All @@ -25,9 +25,17 @@ fn expand_struct(input: &ErrorInput, data: &StructData) -> Result<TokenStream, E
DisplaySpec::Transparent {
..
} => render_struct_transparent(&data.fields),
DisplaySpec::Template(template) => render_template(template, |placeholder| {
DisplaySpec::Template(template)
| DisplaySpec::TemplateWithArgs {
template, ..
} => render_template(template, |placeholder| {
struct_placeholder_expr(&data.fields, placeholder)
})?
})?,
DisplaySpec::FormatterPath {
path, ..
} => {
return Err(Error::new(path.span(), "`fmt = ...` is not supported yet"));
}
};

let ident = &input.ident;
Expand Down Expand Up @@ -81,7 +89,13 @@ fn render_variant(variant: &VariantData) -> Result<TokenStream, Error> {
DisplaySpec::Transparent {
..
} => render_variant_transparent(variant),
DisplaySpec::Template(template) => render_variant_template(variant, template)
DisplaySpec::Template(template)
| DisplaySpec::TemplateWithArgs {
template, ..
} => render_variant_template(variant, template),
DisplaySpec::FormatterPath {
path, ..
} => Err(Error::new(path.span(), "`fmt = ...` is not supported yet"))
}
}

Expand Down
16 changes: 14 additions & 2 deletions masterror-derive/src/error_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ fn struct_source_body(fields: &Fields, display: &DisplaySpec) -> TokenStream {
quote! { None }
}
}
DisplaySpec::Template(_) => {
DisplaySpec::Template(_)
| DisplaySpec::TemplateWithArgs {
..
}
| DisplaySpec::FormatterPath {
..
} => {
if let Some(field) = fields.iter().find(|field| field.attrs.has_source()) {
let member = &field.member;
field_source_expr(quote!(self.#member), quote!(&self.#member), &field.ty)
Expand All @@ -97,7 +103,13 @@ fn variant_source_arm(variant: &VariantData) -> TokenStream {
DisplaySpec::Transparent {
..
} => variant_transparent_source(variant),
DisplaySpec::Template(_) => variant_template_source(variant)
DisplaySpec::Template(_)
| DisplaySpec::TemplateWithArgs {
..
}
| DisplaySpec::FormatterPath {
..
} => variant_template_source(variant)
}
}

Expand Down
65 changes: 53 additions & 12 deletions masterror-derive/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use proc_macro2::Span;
use proc_macro2::{Span, TokenStream};
use syn::{
Attribute, Data, DataEnum, DataStruct, DeriveInput, Error, Field as SynField,
Fields as SynFields, GenericArgument, Ident, LitStr, spanned::Spanned
Attribute, Data, DataEnum, DataStruct, DeriveInput, Error, Expr, Field as SynField,
Fields as SynFields, GenericArgument, Ident, LitStr, Path, spanned::Spanned
};

use crate::template_support::{DisplayTemplate, TemplateIdentifierSpec, parse_display_template};
Expand All @@ -21,16 +21,20 @@ pub enum ErrorData {

#[derive(Debug)]
pub struct StructData {
pub fields: Fields,
pub display: DisplaySpec
pub fields: Fields,
pub display: DisplaySpec,
#[allow(dead_code)]
pub format_args: FormatArgsSpec
}

#[derive(Debug)]
pub struct VariantData {
pub ident: Ident,
pub fields: Fields,
pub display: DisplaySpec,
pub span: Span
pub ident: Ident,
pub fields: Fields,
pub display: DisplaySpec,
#[allow(dead_code)]
pub format_args: FormatArgsSpec,
pub span: Span
}

#[derive(Debug)]
Expand Down Expand Up @@ -245,8 +249,43 @@ impl FieldAttrs {

#[derive(Debug)]
pub enum DisplaySpec {
Transparent { attribute: Box<Attribute> },
Template(DisplayTemplate)
Transparent {
attribute: Box<Attribute>
},
Template(DisplayTemplate),
#[allow(dead_code)]
TemplateWithArgs {
template: DisplayTemplate,
args: FormatArgsSpec
},
#[allow(dead_code)]
FormatterPath {
path: Path,
args: FormatArgsSpec
}
}

#[allow(dead_code)]
#[derive(Debug, Default)]
pub struct FormatArgsSpec {
pub args: Vec<FormatArg>
}

#[allow(dead_code)]
#[derive(Debug)]
pub struct FormatArg {
pub tokens: TokenStream,
pub expr: Expr,
pub kind: FormatBindingKind,
pub span: Span
}

#[allow(dead_code)]
#[derive(Debug)]
pub enum FormatBindingKind {
Named(Ident),
Positional(usize),
Implicit
}

pub fn parse_input(input: DeriveInput) -> Result<ErrorInput, Error> {
Expand Down Expand Up @@ -300,7 +339,8 @@ fn parse_struct(

Ok(ErrorData::Struct(Box::new(StructData {
fields,
display
display,
format_args: FormatArgsSpec::default()
})))
}

Expand Down Expand Up @@ -348,6 +388,7 @@ fn parse_variant(variant: syn::Variant, errors: &mut Vec<Error>) -> Result<Varia
ident: variant.ident,
fields,
display,
format_args: FormatArgsSpec::default(),
span
})
}
Expand Down
Loading