telety_impl/alias/
error.rs

1use proc_macro2::Span;
2
3pub struct Error {
4    span: Span,
5    pub kind: Kind,
6}
7
8pub enum Kind {
9    AssociatedType,
10    Closure,
11    Trait,
12}
13
14impl Kind {
15    pub(crate) fn error(self, span: Span) -> Error {
16        Error::new(span, self)
17    }
18}
19
20impl Error {
21    pub(crate) fn new(span: Span, kind: Kind) -> Self {
22        Self { span, kind }
23    }
24}
25
26impl From<Error> for syn::Error {
27    fn from(value: Error) -> Self {
28        let Error { span, kind } = value;
29
30        let message = match kind {
31            Kind::AssociatedType => "Associated types are not supported".to_string(),
32            Kind::Closure => "Closure traits are not supported".to_string(),
33            Kind::Trait => "Traits have limited support, use #[telety(path, alias_traits = \"always\")] if all traits are publicly used.".to_string(),
34        };
35
36        syn::Error::new(span, message)
37    }
38}