小编Mic*_*ael的帖子

Rust `std::time::Instant`“在'提供的瞬间比自己晚'时感到恐慌”

我正在尝试在 Rust 中设置一个简单的计时器,该计时器以特定频率返回 true。

#[derive(Clone, Debug)]
pub struct IntervalTimer {
    pub period: Duration,
    pub delta: Instant,
}

impl IntervalTimer {
    pub fn new(period: Duration) -> Self {
        let delta = Instant::now();
        Self { period, delta }
    }

    /// Returns true if the interval between calls has exceeded the period
    pub fn ready(&mut self) -> bool {
        if self.delta.elapsed() < self.period {
            false
        } else {
            self.delta = self.delta + self.period;
            true
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,这std::time::Instantrayon任务中使用时似乎一直很恐慌(如果重要的话,在 Legion …

linux rust rayon amethyst

5
推荐指数
2
解决办法
1422
查看次数

标签 统计

amethyst ×1

linux ×1

rayon ×1

rust ×1