Skip to content

Commit 01053db

Browse files
committed
simplify attribute parsing
1 parent 77befc9 commit 01053db

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

custom_debug_derive/src/field_attributes.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::cell::OnceCell;
2-
31
use darling::util::Flag;
42
use darling::FromMeta;
53
use syn::ExprPath;
@@ -13,7 +11,7 @@ pub struct FieldAttributes {
1311
impl FieldAttributes {
1412
fn new(internal: InternalFieldAttributes) -> darling::Result<Self> {
1513
let mut skip_mode = SkipMode::Default;
16-
let debug_format = OnceCell::new();
14+
let mut debug_format = DebugFormat::Default;
1715

1816
if internal.skip.is_present() {
1917
skip_mode = skip_mode.try_combine(SkipMode::Always)?;
@@ -24,19 +22,13 @@ impl FieldAttributes {
2422
}
2523

2624
if let Some(format) = internal.format {
27-
debug_format
28-
.set(DebugFormat::Format(format))
29-
.map_err(|_| conflicting_format_options_error())?;
25+
debug_format = debug_format.try_combine(DebugFormat::Format(format))?;
3026
}
3127

3228
if let Some(with) = internal.with {
33-
debug_format
34-
.set(DebugFormat::With(with))
35-
.map_err(|_| conflicting_format_options_error())?;
29+
debug_format = debug_format.try_combine(DebugFormat::With(with))?;
3630
}
3731

38-
let debug_format = debug_format.into_inner().unwrap_or(DebugFormat::Default);
39-
4032
Ok(Self {
4133
skip_mode,
4234
debug_format,

0 commit comments

Comments
 (0)