-
Notifications
You must be signed in to change notification settings - Fork 5
/
syn.rs
44 lines (39 loc) · 902 Bytes
/
syn.rs
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
// Example provided in #4
// https://github.com/jmg-duarte/sealed-rs/issues/4
use proc_macro2::*;
use sealed::sealed;
use syn::spanned::Spanned;
#[sealed]
pub trait AsSpan {
fn as_span(&self) -> Span;
}
// expands to:
// pub trait AsSpan: __seal_as_span::Sealed {
// fn as_span(&self) -> Span;
// }
// mod __seal_as_span {
// pub trait Sealed {}
// }
#[sealed]
impl AsSpan for Span {
fn as_span(&self) -> Self {
*self
}
}
// expands to:
// impl AsSpan for Span { // foreign type, cannot place #[sealed]
// fn as_span(&self) -> Self { *self }
// }
// impl __seal_as_span::Sealed for Span {}
#[sealed]
impl<T: Spanned> AsSpan for &T {
fn as_span(&self) -> Span {
self.span()
}
}
// expands to:
// impl<T: Spanned> AsSpan for &T {
// fn as_span(&self) -> Span { self.span() }
// }
// impl<T: Spanned> __seal_as_span::Sealed for &T {}
fn main() {}