legion icon indicating copy to clipboard operation
legion copied to clipboard

the trait `legion::EntitySource` is not implemented for Type

Open andreasterrius opened this issue 5 years ago • 3 comments

I encountered this error when trying to use legion 0.1.1

error[E0277]: the trait bound `alers::math::transform::Transform: legion::EntitySource` is not satisfied
  --> src/app\game.rs:45:7
   |
45 |       (Transform::new())
   |       ^^^^^^^^^^^^^^^^^^ the trait `legion::EntitySource` is not implemented for `alers::math::transform::Transform`

error: aborting due to previous error

Here are the definitions for my structs

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Transform {
  pub position: Vector3<f32>,
  pub lcl_rotation : Quaternion<f32>,
  pub scale : Vector3<f32>,
  matrix : Option<Matrix4<f32>>,
}

Here is the offending code

 pub fn load(&mut self, context : &mut Context) {
    // Load meshes
    let mut mesh = resource::fbx_convert::to_static_meshes(
      resource::fbx::load("resources/test/geom/triangle.fbx").unwrap()).first().unwrap();

    // Load shaders
    let mut lambert = resource::shader::ShaderFile::new(
      fs::read_to_string("shaders/lambert.vs").unwrap(),
      fs::read_to_string("shaders/lambert.fs").unwrap()
    );

    context.static_mesh(&mesh);
    context.shader(&lambert);

    // Create entities
    self.world.insert(
      (mesh.uid(), lambert.uid()),
      (Transform::new())
    );
  }

Did I miss out on anything ?

andreasterrius avatar Dec 01 '19 08:12 andreasterrius

EntitySource is implemented for tuples, but in Rust, (Transform::new()) is not a tuple, you need to add a comma after the first element: (Transform::new(),)

kabergstrom avatar Dec 01 '19 15:12 kabergstrom

world.insert also expects an iterator of tuples, so you need something like vec![(Transform::new(),)].

TomGillen avatar Dec 01 '19 15:12 TomGillen

I didn't know that (Transform::new()) isn't considered a tuple in rust.

Probably we can put that somewhere on the docs that world.insert expects an iterator of tuples ? The implementors section of https://docs.rs/legion/0.1.1/legion/trait.EntitySource.html is empty

andreasterrius avatar Dec 02 '19 00:12 andreasterrius