third_party/rust/darling_core/src/usage/generics_ext.rs
author Emilio Cobos Álvarez <emilio@crisal.io>
Sun, 02 Dec 2018 12:15:47 -0500
changeset 449236 d2c99742610827141e7c50a5da9692449fcbc6b3
permissions -rw-r--r--
Bug 1511811 - Revendor Rust dependencies.

use syn::Generics;

use usage::{IdentSet, LifetimeSet};

/// Extension trait for pulling specific generics data from a generics AST representation.
pub trait GenericsExt {
    /// Get the set of all lifetimes declared by the syntax element.
    /// This does not look for usage of the lifetime; see `UsesLifetimes` for that.
    fn declared_lifetimes(&self) -> LifetimeSet;

    /// Get the set of all type parameters declared by the syntax element.
    /// This does not look for usage of the type parameter; see `UsesTypeParams` for that.
    fn declared_type_params(&self) -> IdentSet;
}

impl GenericsExt for Generics {
    fn declared_lifetimes(&self) -> LifetimeSet {
        self.lifetimes().map(|lt| lt.lifetime.clone()).collect()
    }

    fn declared_type_params(&self) -> IdentSet {
        self.type_params().map(|tp| tp.ident.clone()).collect()
    }
}