syn-ext 0.5.0

Human friendly or editable extension for syn
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::ident::GetIdent;
use syn::{Ident, Path};

/// Shortcut to get [syn::Path] from various types
pub trait GetPath {
    /// Returns [syn::Path] from object if possible
    fn get_path(&self) -> Option<&Path>;
}

impl<T> GetIdent for T
where
    T: GetPath,
{
    /// Any [crate::ext::GetPath] automatically implements [crate::ext::GetIdent]
    fn get_ident(&self) -> Option<&Ident> {
        self.get_path().and_then(|p| p.get_ident())
    }
}