我预计这会起作用:
trait Task<R, E> {
fn run(&self) -> Result<R, E>;
}
mod test {
use super::Task;
struct Foo;
impl<uint, uint> Task<uint, uint> for Foo {
fn run(&self) -> Result<uint, uint> {
return Err(0);
}
}
fn can_have_task_trait() {
Foo;
}
}
fn main() {
test::can_have_task_trait();
}
...但它没有:
<anon>:10:3: 14:4 error: the trait `core::kinds::Sized` is not implemented for the type `<generic #0>`
<anon>:10 impl<uint, uint> Task<uint, uint> for Foo {
<anon>:11 fn run(&self) -> Result<uint, uint> {
<anon>:12 return Err(0);
<anon>:13 }
<anon>:14 }
<anon>:10:3: 14:4 note: the trait `core::kinds::Sized` must be implemented because it is required by `Task`
<anon>:10 impl<uint, uint> Task<uint, uint> for Foo {
<anon>:11 fn run(&self) -> Result<uint, uint> {
<anon>:12 return Err(0);
<anon>:13 }
<anon>:14 }
<anon>:10:3: 14:4 error: the trait `core::kinds::Sized` is not implemented for the type `<generic #1>`
<anon>:10 impl<uint, uint> Task<uint, uint> for Foo {
<anon>:11 fn run(&self) -> Result<uint, uint> {
<anon>:12 return Err(0);
<anon>:13 }
<anon>:14 }
<anon>:10:3: 14:4 note: the trait `core::kinds::Sized` must be implemented because it is required by `Task`
<anon>:10 impl<uint, uint> Task<uint, uint> for Foo {
<anon>:11 fn run(&self) -> Result<uint, uint> {
<anon>:12 return Err(0);
<anon>:13 }
<anon>:14 }
error: aborting due to 2 previous errors
playpen: application terminated with error code 101
Program ended.
婴儿围栏:http://is.gd/kxDt0P http://is.gd/kxDt0P
发生什么了?
我不知道这个错误意味着什么。
是不是我正在使用 Result 并且要求 U、V 没有调整大小?在这种情况下,为什么要调整它们的尺寸?我没有写:
Task<Sized? R, Sized? E>
现在所有泛型都是动态调整大小的吗? (在这种情况下,“Sized”是什么意思?甚至是什么意思?)
这是怎么回事?