Hey! Really like this crate, especially the lack of unwraps (rest my soul (◡ ‿ ◡ .))
But while making a little toy game, I found that there's really no way to pass a collection of functions into the builder.
The following code:
use bon::Builder;
use std::collections::HashMap;
fn main() {
let player_1 = Player::builder().skills(bon::map! {
"slash": |field| { /* ... */ },
"punch": |field| { /* ... */ },
});
}
#[derive(Builder)]
struct Player {
skills: HashMap<String, fn(Field)>,
}
struct Field(/* ... */);
Gives this error:
error[E0277]: the trait bound `for<'a> fn(Field<'a>): From<{closure@src/main.rs:7:16: 7:23}>` is not satisfied
I found that both fn pointers & dynamic dispatch break because of impl Into, so bon::map and the like don't work.
Maybe you can use as or other kind of cast but I imagine that'd be very awkward.
Hey! Really like this crate, especially the lack of unwraps (rest my soul (◡ ‿ ◡ .))
But while making a little toy game, I found that there's really no way to pass a collection of functions into the builder.
The following code:
Gives this error:
I found that both
fnpointers & dynamic dispatch break because ofimpl Into, sobon::mapand the like don't work.Maybe you can use
asor other kind of cast but I imagine that'd be very awkward.