1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Extension traits

use proc_macro2::{Ident, Punct, Spacing, Span};

/// [`Ident`] extensions
pub trait MacroificCoreIdentExt {
    /// Shorthand for `Ident::new(name, Span::call_site())`
    fn create(name: &str) -> Self;
}

/// [`Punct`] extensions
pub trait MacroificCorePunctExt {
    /// Create a new [`Punct`] with [`Spacing::Alone`]
    fn new_alone(ch: char) -> Self;

    /// Create a new [`Punct`] with [`Spacing::Joint`]
    fn new_joint(ch: char) -> Self;
}

impl MacroificCorePunctExt for Punct {
    #[inline]
    fn new_alone(ch: char) -> Self {
        Self::new(ch, Spacing::Alone)
    }

    #[inline]
    fn new_joint(ch: char) -> Self {
        Self::new(ch, Spacing::Joint)
    }
}

impl MacroificCoreIdentExt for Ident {
    #[inline]
    fn create(name: &str) -> Self {
        Self::new(name, Span::call_site())
    }
}