File: compat_syn_1.rs

package info (click to toggle)
rust-derive-deftly 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,652 kB
  • sloc: perl: 1,032; sh: 373; python: 227; makefile: 11
file content (47 lines) | stat: -rw-r--r-- 1,083 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
//! Definitions for compatibility with syn 1

use super::prelude::*;

/// syn 2 has this distinct type for start/end delimiters for a group
pub use proc_macro2::Span as DelimSpan;

//---------- Spanned ----------

pub use syn::spanned::Spanned;

//---------- Attribute methods ----------

pub trait AttributeExt1 {
    /// syn 2 has this as an inherent method
    fn path(&self) -> &syn::Path;
}
impl AttributeExt1 for syn::Attribute {
    fn path(&self) -> &syn::Path {
        &self.path
    }
}

impl AttributeExt12 for syn::Attribute {
    fn call_in_parens<T, F>(&self, f: F) -> syn::Result<T>
    where
        F: FnOnce(ParseStream<'_>) -> syn::Result<T>,
    {
        (|outer: ParseStream<'_>| {
            let inner;
            let _paren = parenthesized!(inner in outer);
            f(&inner)
        })
        .parse2(self.tokens.clone())
    }
}

//---------- VisPublic ----------

pub trait VisPublicExt {
    fn pub_token(self) -> syn::token::Pub;
}
impl VisPublicExt for syn::VisPublic {
    fn pub_token(self) -> syn::token::Pub {
        self.pub_token
    }
}