在 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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
timer.0和电话在做什么name.0?这本书没有解决这个问题,我看到它Timer有一个勾选方法,那么既然已经是一个,.0那么这里在做什么?timerTimer
它与元组有关。在 Rust 中,元组可以通过项目位置以这种方式访问:
let foo: (u32, u32) = (0, 1);
println!("{}", foo.0);
println!("{}", foo.1);
Run Code Online (Sandbox Code Playgroud)
某些(元组)结构也会发生这种情况:
struct Foo(u32);
let foo = Foo(1);
println!("{}", foo.0);
Run Code Online (Sandbox Code Playgroud)
你可以进一步查看一些文档。
| 归档时间: |
|
| 查看次数: |
593 次 |
| 最近记录: |