-
Notifications
You must be signed in to change notification settings - Fork 48
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
How to use both View and ViewMut's Get trait as a generic? #151
Comments
Edit: Below I rushed. use shipyard::*;
#[derive(Component)]
struct Person();
fn my_func(p: impl Get, id: EntityId) {
if p.get(id).is_ok() {}
}
fn system1(people: View<Person>) {
let id = todo!();
my_func(&people, id);
}
fn system1_mut(people: ViewMut<Person>) {
let id = todo!();
my_func(&people, id);
} Previous comment: I like this question ❤️ Maybe Both use shipyard::*;
#[derive(Component)]
pub struct C(u32);
fn f_view(c: View<C>) {
f(&c);
}
fn f_view_mut(c: ViewMut<C>) {
f(&c);
}
fn f(_: &SparseSet<C>) { }
fn main() {
let world = World::new();
world.run(f_view);
world.run(f_view_mut);
} It's showing one of my favorite aspect of the beautiful |
..and SparseSet can be casted to the fancy Edit: Getting |
Thank you |
Thanks @toyboot4e! I can give a bit of context to explain why The feature in this case is the "new" tracking, inspired by Bevy.
|
Can I do this? |
You can restrict the component type by specifying fn some_func<'a>(monsters: impl Get<Out = &'a Monster>) {
if let Ok(monster) = monsters.get(some_entity_id) {
let monster_id = monster.get_monster_id();
}
}
fn main() {
let world = World::new();
world.run(|vm_monster: ViewMut<Monster>| {
some_func(&vm_monster);
});
world.run(|v_monster: View<Monster>| {
some_func(&v_monster);
});
} |
Thank you for answering! But I have some minor problem..
|
You can add a fn some_func<'a>(monsters: impl Get<Out = &'a Monster> + Copy) { |
I'd like to create some function like this.
p
can beView
andViewMut
.Can I get some help?
The text was updated successfully, but these errors were encountered: