我有这个相当简单的Rust程序:
use std::ops::Deref;
trait Foo {
fn foo(&self);
}
impl Foo for () {
fn foo(&self) {
println!("hello world");
}
}
impl<F> Foo for Box<F> where F: Foo {
fn foo(&self) {
let f: &F = self.deref();
f.foo()
}
}
fn call_foo<F>(foo: &F) where F: Foo {
foo.foo()
}
fn main() {
let foo: Box<Foo> = Box::new(());
call_foo(&foo);
}
但是我收到了编译错误:
$ rustc main.rs
main.rs:26:3: 26:11 error: the trait `core::marker::Sized` is not implemented for the type `Foo` [E0277]
main.rs:26 call_foo(&foo);
^~~~~~~~
main.rs:26:3: 26:11 help: run `rustc --explain E0277` to see a detailed explanation
main.rs:26:3: 26:11 note: `Foo` does not have a constant size known at compile-time
main.rs:26 call_foo(&foo);
^~~~~~~~
main.rs:26:3: 26:11 note: required by `call_foo`
main.rs:26 call_foo(&foo);
^~~~~~~~
error: aborting due to previous error
E0277的错误解释似乎无关。我该如何解决这个问题?