I'm implementing a game engine, and want to have a set of modules, each of which implements certain rules. Each module exposes a function which conforms to this definition:
fn validate(game: &Game, next_move: String) -> Result<(), MoveError>
Rather than have consumers of these rules use every rule module, I'd like to expose a set (array? Vec<>?) of these validate functions. I was assuming it would be an array of function pointers, something like:
mod rule1;
mod rule2;
type Validate = fn(&Game, String) -> Result<(), MoveError>;
const validations: [Validate] = &[
rule1::validate,
rule2::validate
];
but Rust says:
error[E0277]: the size for values of type `[for<'r> fn(&'r Game, std::string::String) -> std::result::Result<(), MoveError>]` cannot be known at compilation time
--> src/lib.rs:6:20
|
6 | const validations: [Validate] = &[
| ^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `[for<'r> fn(&'r Game, std::string::String) -> std::result::Result<(), MoveError>]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
I've read the linked article and am none the wiser. What's the first step in fixing this error (or perhaps in correcting my lack of understanding)