Skip to content

Commit

Permalink
from_nested_meta can stay a part of FromMeta trait
Browse files Browse the repository at this point in the history
This was initially removed in an attempt to get rid of `NestedMeta`, but
since the type stays, the function can too.
  • Loading branch information
jonasbb authored and TedDriggs committed Apr 27, 2023
1 parent 71beef6 commit 1da9218
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ impl Error {
/// overridden:
///
/// * `FromMeta::from_meta`
/// * `FromMeta::from_nested_meta`
/// * `FromMeta::from_value`
pub fn with_span<T: Spanned>(mut self, node: &T) -> Self {
if !self.has_span() {
Expand Down
8 changes: 8 additions & 0 deletions core/src/from_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ use crate::{Error, Result};
/// * Allows for fallible parsing; will populate the target field with the result of the
/// parse attempt.
pub trait FromMeta: Sized {
fn from_nested_meta(item: &NestedMeta) -> Result<Self> {
(match *item {
NestedMeta::Lit(ref lit) => Self::from_value(lit),
NestedMeta::Meta(ref mi) => Self::from_meta(mi),
})
.map_err(|e| e.with_span(item))
}

/// Create an instance from a `syn::Meta` by dispatching to the format-appropriate
/// trait function. This generally should not be overridden by implementers.
///
Expand Down

0 comments on commit 1da9218

Please sign in to comment.