serde_attributes/alias/
darling.rs

1use core::convert::TryFrom as _;
2
3use darling_core::{Error as DarlingError, FromMeta};
4use syn::Meta;
5
6use super::{Alias, syn::FromMetaError};
7
8impl FromMeta for Alias {
9    fn from_meta(meta: &Meta) -> Result<Self, DarlingError> {
10        Self::try_from(meta).map_err(|err| match err {
11            FromMetaError::MetaTypeOrPathMismatch(meta) => match meta {
12                Meta::Path(_) => DarlingError::unexpected_type("Meta::Path"),
13                Meta::List(_) => DarlingError::unexpected_type("Meta::List"),
14                Meta::NameValue(meta_name_value) => {
15                    DarlingError::unknown_field_path(&meta_name_value.path)
16                }
17            },
18            FromMetaError::MetaNameValueExprTypeMismatch(expr) => {
19                DarlingError::unexpected_expr_type(expr)
20            }
21        })
22    }
23}