Skip to content

Commit ece50b3

Browse files
committed
ability specify additional trait bounds for Visit trait
1 parent 221ae54 commit ece50b3

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎fyrox-core-derive/src/visit.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ fn impl_visit_enum(ty_args: &args::TypeArgs, variant_args: &[args::VariantArgs])
120120
}
121121
});
122122

123-
let (impl_generics, ty_generics, where_clause) = ty_args.generics.split_for_impl();
123+
let generics = ty_args.impl_generics();
124+
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
124125

125126
quote! {
126127
fn id #impl_generics (me: &#ty_ident #ty_generics) -> #id_type #where_clause {
@@ -178,7 +179,8 @@ fn impl_visit_enum(ty_args: &args::TypeArgs, variant_args: &[args::VariantArgs])
178179
}
179180
});
180181

181-
let (impl_generics, ty_generics, where_clause) = ty_args.generics.split_for_impl();
182+
let generics = ty_args.impl_generics();
183+
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
182184

183185
quote! {
184186
fn from_id #impl_generics (

‎fyrox-core-derive/src/visit/args.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ pub struct TypeArgs {
3333
pub pre_visit_method: Option<Ident>,
3434
#[darling(default)]
3535
pub post_visit_method: Option<Ident>,
36+
/// Custom `Visit` impl type boundary.
37+
#[darling(default)]
38+
pub bounds: Option<Vec<WherePredicate>>,
39+
}
40+
41+
impl TypeArgs {
42+
pub fn impl_generics(&self) -> Generics {
43+
let mut generics = self.generics.clone();
44+
45+
let clause = generics.make_where_clause();
46+
47+
if let Some(bounds) = &self.bounds {
48+
clause.predicates.extend(bounds.iter().cloned());
49+
}
50+
51+
generics
52+
}
3653
}
3754

3855
/// Parsed from struct's or enum variant's field

0 commit comments

Comments
 (0)