Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Rust traits for Screeps types #2

Open
ashkitten opened this issue Mar 24, 2018 · 3 comments
Open

Implement Rust traits for Screeps types #2

ashkitten opened this issue Mar 24, 2018 · 3 comments
Labels
C-enhancement Category: A PR with an enhancement or a proposed on in an issue.

Comments

@ashkitten
Copy link

Things like Index, IndexMut, etc. should be implemented for better integration with Rust code

@daboross
Copy link
Collaborator

In general, agreed!

Were there any specific Screeps types you were thinking Index/IndexMut would be appropriate for?

@ashkitten
Copy link
Author

I was specifically thinking the dict types (creeps, spawns, memory) should have Index/IndexMut, and probably also be iterable?

@daboross
Copy link
Collaborator

Alright- that makes sense.

The current design of the Game.* dicts could be redone so they support implementing traits. Right now they're modules, but we could make them structs with no fields. It could then implement IntoIterator, which would work well, but I'm not so sure about Index.

The main problem I see with implementing Index for them is that Index::index needs to return some sort of reference borrowed from the structure. We don't currently store Creep / Structure / etc. instances in screeps-game-api, and we would need to in order to implement Index. I'm not sure about how to solve this unless we just went ahead and allowed fetching all values into a HashMap<String, Creep> which could then be indexed.


For memory, the main question I have is what type the index should result in. I went with methods for each specific type in order to have checked/typed access.

Do you think introducing a MemoryValue enum with different possible types would be good, or would Index return stdweb::Value?

Even here though, there's still the problem with references. Rust's Index trait seems designed for data structures which really hold their data, and don't fetch it from an external place.

daboross added a commit that referenced this issue Apr 7, 2018
@daboross daboross reopened this Apr 10, 2018
@shanemadden shanemadden added the C-enhancement Category: A PR with an enhancement or a proposed on in an issue. label Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A PR with an enhancement or a proposed on in an issue.
Projects
None yet
Development

No branches or pull requests

3 participants