Skip to content

Multiple inline enum variants using #[darling(multiple)] #304

Closed Answered by TedDriggs
Techassi asked this question in Q&A
Discussion options

You must be logged in to vote

This can be done using darling(with = ...).

use darling::{ast::NestedMeta, Error, FromDeriveInput, FromMeta};

#[derive(Debug, FromMeta)]
enum Action {
    Added { name: String },
    Edited { was: String, is: String },
    Removed { was: String },
}

/// Read a list of FromMeta objects, preserving order, and return the results
/// as a `Vec`.
pub fn from_list<T: FromMeta>(list: &syn::Meta) -> darling::Result<Vec<T>> {
    match list {
        syn::Meta::List(ref value) => {
            let items = NestedMeta::parse_meta_list(value.tokens.clone())?;
            let mut errors = Error::accumulator();
            let mut parsed = Vec::with_capacity(items.len());
            for nmi in items {

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Techassi
Comment options

Answer selected by TedDriggs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants