Skip to content

Commit 5f3c758

Browse files
committed
fix naming of helper attributes
1 parent 506eaab commit 5f3c758

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
89
- fix imports in `impl_Attribute_for_Parse_and_ToTokens!`
10+
### Added
11+
- allow `#[from_attr]` on top of `#[attribute]`
912

1013
## [0.10.2] - 2024-10-30
1114
### Added

macro/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use quote_use::quote_use as quote;
1414
use syn::spanned::Spanned;
1515
use syn::{DataStruct, DeriveInput, Field, Fields, Generics, Ident, LitStr, Type, Visibility};
1616

17-
const ATTRIBUTE_IDENT: &str = "attribute";
17+
const ATTRIBUTE_IDENTS: &[&str] = &["from_attr", "attribute", "attr"];
1818

1919
#[allow(clippy::large_enum_variant)]
2020
enum StructError {
@@ -184,7 +184,7 @@ impl StructAttrs {
184184
// let mut duplicate: DuplicateStrategy = DuplicateStrategy::AggregateOrError;
185185
for attr in attrs
186186
.into_iter()
187-
.filter(|attr| attr.path().is_ident(ATTRIBUTE_IDENT))
187+
.filter(|attr| ATTRIBUTE_IDENTS.iter().any(|a| attr.path().is_ident(a)))
188188
{
189189
let parser = &mut attr
190190
.meta
@@ -370,7 +370,7 @@ impl FieldAttrs {
370370

371371
for attr in attrs
372372
.into_iter()
373-
.filter(|attr| attr.path().is_ident(ATTRIBUTE_IDENT))
373+
.filter(|attr| ATTRIBUTE_IDENTS.iter().any(|a| attr.path().is_ident(a)))
374374
{
375375
let mut parser = attr
376376
.meta

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
//! ```
44
//! use attribute_derive::FromAttr;
55
//! #[derive(FromAttr)]
6-
//! #[attribute(ident = attr_name)]
6+
//! #[from_attr(ident = attr_name)]
77
//! // overriding the builtin error messages
8-
//! #[attribute(error(missing_field = "`{field}` was not specified"))]
8+
//! #[from_attr(error(missing_field = "`{field}` was not specified"))]
99
//! struct MyAttribute {
1010
//! // Positional values need to be specified before any named ones
11-
//! #[attribute(positional)]
11+
//! #[from_attr(positional)]
1212
//! positional: u8,
1313
//! // Options are optional by default (will be set to None if not specified)
1414
//! optional: Option<String>,
1515
//! required: String,
1616
//! // Any type implementing default can be flagged as default
1717
//! // This will be set to Vec::default() when not specified
18-
//! #[attribute(optional)]
18+
//! #[from_attr(optional)]
1919
//! list: Vec<syn::Type>,
2020
//! // Booleans can be used without assigning a value, i.e., as a flag.
2121
//! // If omitted they are set to false

0 commit comments

Comments
 (0)