` in rust? I expected this to work: trait Task { fn ru...">

What the heck is "core :: types :: Sized" not implemented for type `<generiC # 0>` in rust?

I expected this to work:

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();
}

... but it is not:

<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.

playpen: http://is.gd/kxDt0P

So what is going on?

I do not know what this error means.

Is it that I use Result, and that U, V are not dimensional? In which case, why are they dimensional? I did not write:

Task<Sized? R, Sized? E>

Are all generics more dynamic or something else? (in this case, what does Sized mean? even means?)

What's happening?

+4
source share
2 answers

You just need to delete <uint, uint>in impl<uint, uint>, because type parameters go there, not specific types:

impl Task<uint, uint> for Foo { ... }

, , , - , . :

trait Tr {}
impl<X> Tr for () {}
+5

Rust " ": Task<R, E>, (R E).

, <uint, uint>.

, :

trait Foo<R> {}

struct Bar;

struct Baz;

impl<Baz> Foo<Baz> for Bar {}

, Baz , struct Baz: , var var .

, , , , , , , .

+2

All Articles