2019-11-17 15:30:48 +01:00
|
|
|
## setup
|
|
|
|
|
|
|
|
In module `modules`, I have:
|
|
|
|
|
|
|
|
```rust
|
|
|
|
pub trait Module {
|
|
|
|
fn run(&self, record: &mut Record) -> Result<bool, ()>;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
In module `filters`, I have:
|
|
|
|
|
|
|
|
```rust
|
2019-11-17 16:16:25 +01:00
|
|
|
pub struct Equals { … }
|
2019-11-17 15:30:48 +01:00
|
|
|
|
2019-11-17 16:16:25 +01:00
|
|
|
impl Equals {
|
2019-11-17 15:30:48 +01:00
|
|
|
pub fn from_args(mut args: ModuleArgs) -> Equals {
|
|
|
|
Equals { … }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-17 16:16:25 +01:00
|
|
|
impl Module for Equals {
|
2019-11-17 15:30:48 +01:00
|
|
|
fn run(&self, record: &mut Record) -> Result<bool, ()> { … }
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## goal, “naive-style”
|
|
|
|
|
|
|
|
What I really want (for a start) is that, in module `modules`:
|
|
|
|
|
|
|
|
```rust
|
|
|
|
struct Available {
|
2019-11-17 16:16:25 +01:00
|
|
|
name: String,
|
|
|
|
cons: Box<fn(ModuleArgs) -> dyn Module>
|
2019-11-17 15:30:48 +01:00
|
|
|
}
|
|
|
|
|
2019-11-17 16:16:25 +01:00
|
|
|
const available: [Available] = [
|
|
|
|
Available { name: "equals", cons: Box.new(filters::Equals::from_args) }
|
|
|
|
];
|
2019-11-17 15:30:48 +01:00
|
|
|
```
|
|
|
|
|
2019-11-17 16:16:25 +01:00
|
|
|
with `available` being an array of available modules, each having a name and a constructor.
|
2019-11-17 15:30:48 +01:00
|
|
|
|
|
|
|
## problem
|
|
|
|
|
2019-11-17 16:16:25 +01:00
|
|
|
The above code gives me these errors (which I suspect are hiding the next error about `"equals"` probably being `&str` instead of `String`…):
|
|
|
|
|
|
|
|
* first:
|
|
|
|
|
|
|
|
```
|
|
|
|
error[E0423]: expected value, found struct `Box`
|
|
|
|
--> src/modules.rs:10:37
|
|
|
|
|
|
|
|
|
10 | Available { name: "equals", cons: Box.new(filters::Equals::from_args) }
|
|
|
|
| ^^^ constructor is not visible here due to private fields
|
|
|
|
```
|
|
|
|
|
|
|
|
* second:
|
|
|
|
|
|
|
|
```
|
|
|
|
error[E0277]: the size for values of type `[modules::Available]` cannot be known at compilation time
|
|
|
|
--> src/modules.rs:9:18
|
|
|
|
|
|
|
|
|
9 | const available: [Available] = [
|
|
|
|
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
|
|
|
|
|
|
|
|
= help: the trait `std::marker::Sized` is not implemented for `[modules::Available]`
|
|
|
|
```
|