I'm trying to return a list of methods bound to their names (RPC implementation):
struct Stub {
fn method_a(&self, args: u8) -> u8 { ... }
fn method_b(&self, args: u8) -> u8 { ... }
}
impl RPCStub for Stub {
fn methods(&self) -> Vec<(String, Box<Fn(&Self, u8) -> u8>)> {
vec!(
("a".to_owned(), Box::new(Self::method_a)),
("b".to_owned(), Box::new(Self::method_b)),
)
}
}
where RPCStub
is defined as:
pub trait RPCStub {
fn methods(&self) -> Vec<(String, Box<Fn(&Self, u8) -> u8>)> where Self: Sized;
}
it all works fine (i.e. compiles) but I can't actually call the methods()
method:
let s = Stub::new();
let m = s.methods();
for (n, _) in m {
println!("{}", n);
}
fails with:
error: the trait `core::marker::Sized` is not implemented for the type `RPCStub + 'static`
any ideas how can I sort this out? I'd really prefer not to get down to match
over string names.