kamadorueda / santiago

Santiago is a lexing and parsing toolkit for Rust
91 stars 7 forks source link

manual impl => `#[derive]` #1

Closed pro465 closed 2 years ago

pro465 commented 2 years ago

why is the test taking sooo long?

kamadorueda commented 2 years ago

The CI agents run as a service in my home computer, I have tu turn them on manually hehe

But now that the tests ran, this error made me remember why I didn't use derive macros, using derive macros require me to anotate every function in the codebase with where AST: Clone, and I didn't want to impose such restrictions in the AST type, since it's defined by users according to their needs, and cloning is not always something people want since it hurts performance


error[E0599]: the method `clone` exists for struct `HashMap<Rc<String>, GrammarRule<AST>>`, but its trait bounds were not satisfied
--
  | --> src/grammar/mod.rs:39:37
  | \|
  | 39  \|           Grammar { rules: self.rules.clone() }
  | \|                                       ^^^^^ method cannot be called on `HashMap<Rc<String>, GrammarRule<AST>>` due to unsatisfied trait bounds
  | \|
  | ::: src/grammar/grammar_rule.rs:16:1
  | \|
  | 16  \|   pub struct GrammarRule<AST> {
  | \|   --------------------------- doesn't satisfy `GrammarRule<AST>: Clone`
  | \|
  | = note: the following trait bounds were not satisfied:
  | `GrammarRule<AST>: Clone`
  | which is required by `HashMap<Rc<String>, GrammarRule<AST>>: Clone`
  | help: consider annotating `GrammarRule<AST>` with `#[derive(Clone)]`
  | \|
  | 16  \| #[derive(Clone)]

by not using the derive macros, I can keep the AST type without trait conditions