b2adb834d4 | ||
---|---|---|
README.md |
README.md
setup
In module modules
, I have:
pub trait Module {
fn run(&self, record: &mut Record) -> Result<bool, ()>;
}
In module filters
, I have:
pub struct Equals { … }
impl Equals {
pub fn from_args(mut args: ModuleArgs) -> Equals {
Equals { … }
}
}
impl Module for Equals {
fn run(&self, record: &mut Record) -> Result<bool, ()> { … }
}
goal, “naive-style”
What I really want (for a start) is that, in module modules
:
struct Available {
name: String,
cons: Box<fn(ModuleArgs) -> dyn Module>
}
const available: [Available] = [
Available { name: "equals", cons: Box.new(filters::Equals::from_args) }
];
with available
being an array of available modules, each having a name and a constructor.
problem
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]`