1use super::*;
4#[allow(unreachable_pub)] pub use crate::{
6 ast_enum::{GenericParam, TraitBoundModifier, TypeParamBound, WherePredicate},
7 ast_struct::{
8 BoundLifetimes, ConstParam, LifetimeParam, PredicateLifetime, TraitBound, TypeParam,
9 WhereClause,
10 },
11};
12
13ast_struct! {
14 #[derive(Default)]
16 pub struct Generics {
17 #[serde(default, skip_serializing_if = "Punctuated::is_empty")]
20 pub(crate) params: Punctuated<GenericParam>,
21 #[serde(default, skip_serializing_if = "Option::is_none")]
24 pub(crate) where_clause: Option<WhereClause>,
25 }
26}
27
28impl Generics {
29 pub(crate) fn is_none(&self) -> bool {
30 self.params.is_empty() && self.where_clause.is_none() }
32}
33
34impl TraitBoundModifier {
35 pub(crate) fn is_none(&self) -> bool {
36 match self {
37 TraitBoundModifier::None => true,
38 TraitBoundModifier::Maybe => false,
39 }
40 }
41}
42
43impl Default for TraitBoundModifier {
44 fn default() -> Self {
45 TraitBoundModifier::None
46 }
47}
48
49ast_struct! {
50 pub struct PredicateType {
52 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub(crate) lifetimes: Option<BoundLifetimes>,
54 pub(crate) bounded_ty: Type,
55 pub(crate) bounds: Punctuated<TypeParamBound>,
58 }
59}
60
61mod convert {
62 use super::*;
63
64 syn_trait_impl!(syn::Generics);
66 impl From<&syn::Generics> for Generics {
67 fn from(other: &syn::Generics) -> Self {
68 assert_eq!(other.lt_token.is_some(), other.gt_token.is_some());
70 assert!(other.params.is_empty() || other.lt_token.is_some(), "expected `<`");
72
73 Self { params: other.params.map_into(), where_clause: other.where_clause.map_into() }
74 }
75 }
76 impl From<&Generics> for syn::Generics {
77 fn from(other: &Generics) -> Self {
78 Self {
79 lt_token: default_or_none(!other.params.is_empty()),
80 params: other.params.map_into(),
81 gt_token: default_or_none(!other.params.is_empty()),
82 where_clause: other.where_clause.map_into(),
83 }
84 }
85 }
86}