在Bevy书中,使用了以下代码:
struct GreetTimer(Timer);
fn greet_people(
time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
// update our timer with the time elapsed since the last update
// if that caused the timer to finish, we say hello to everyone
if timer.0.tick(time.delta()).just_finished() {
for name in query.iter() {
println!("hello {}!", name.0);
}
}
}timer.0和name.0调用的作用是什么?这本书没有涉及到它,我看到Timer有一个tick方法,既然timer已经是一个Timer,那么.0在这里做什么呢
发布于 2021-11-11 20:38:16
它与元组相关。在rust中,可以通过项目位置来访问元组,方法如下:
let foo: (u32, u32) = (0, 1);
println!("{}", foo.0);
println!("{}", foo.1);一些(元组)结构也会发生这种情况:
struct Foo(u32);
let foo = Foo(1);
println!("{}", foo.0);您可以进一步检查一些documentation。
https://stackoverflow.com/questions/69934627
复制相似问题