Using a Storage impl as the function parameter

(constatinus) #1
pub fn getEntitiesCord<'a, T>(x: f32, y: f32, entities: impl Join) -> Vec<&'a mut Entity> {
let mutable = match entities {
    WriteStorage => true,
    ReadStorage => false,
let mut list = Vec::new();
let ents = (&mut entities).join();
for i in ents {
    if i.getLoc() == x && i.getLoc() == y {

Just to note, in this func Entity is refered to my own Entity definition ass shared::Entity.
So, i want a function parameter to take both ReadStorage and WriteStorage. But i do know that the way i interfere with them is through the join() method. So i call the impl and right when i try to do anything with the implementation:
no method named getLoc found for type <impl Join as server::server::amethyst::specs::Join>::Type in the current scope
help: items from traits can only be used if the trait is implemented and in scope
note: the following trait defines an item getLoc, perhaps you need to implement it:
candidate #1: shared::EntityTrustc(E0599)

(Théo Degioanni) #2

What do you expect your join call to return? It seems like you believe it will return your custom entity type, but not only does it not return entities (by default), you don’t really have any information on what sort of output you will get from the impl Join statement.

(constatinus) #3

Well, an iterator of my Entity type should be returned? And, how do i give this information…?

(Théo Degioanni) #4

What is your entity struct meant to be? In which situation do you want a join to return your entity type?

I think you are trying to solve your problem in a way that is not how specs works. Have you gotten to read the Amethyst book or the specs book? They are great resources to get a better grasp at how one builds ECS logic in specs.

(constatinus) #5

I think we might have a misunderstanding here. My Entity type is not a replacement for the amethyst Entity, but rather, just a normal struct. Which, could be given inside a lets say ReadStorage<'a, shared::Entity>

(Théo Degioanni) #6

Ah okay I see. Unfortunately there is no easy way to take a Join with an arbitrary amount of elements in specs. You will have to either specialize your function, create a macro that generates the function for each join type you need, or extract the join’s bitmask and join that with the storage (I don’t remember how to do it from the top of my head but I can look it up if you want to go down that road).

(constatinus) #7

Aaah, damn it. Is this a rust problem, kinda looks like it. Or at lest would be cool to make this func unsafe to work. Nevermind thanks for clearing this up i had my head banging.