mirror of
https://github.com/ankitects/anki.git
synced 2026-01-14 06:23:57 -05:00
* Anki: Replace lazy_static with once_cell Unify to once_cell, lazy_static's replacement. The latter in unmaintained. * Anki: Replace once_cell with stabilized LazyCell / LazyLock as far as possible Since 1.80: https://github.com/rust-lang/rust/issues/109736 and https://github.com/rust-lang/rust/pull/98165 Non-Thread-Safe Lazy → std::cell::LazyCell https://doc.rust-lang.org/nightly/std/cell/struct.LazyCell.html Thread-safe SyncLazy → std::sync::LazyLock https://doc.rust-lang.org/nightly/std/sync/struct.LazyLock.html The compiler accepted LazyCell only in minilints. The final use in rslib/src/log.rs couldn't be replaced since get_or_try_init has not yet been standardized: https://github.com/rust-lang/rust/issues/109737 * Declare correct MSRV (dae) Some of our deps require newer Rust versions, so this was misleading. Updating the MSRV also allows us to use .inspect() on Option now
47 lines
1.6 KiB
Rust
47 lines
1.6 KiB
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
use super::CardQueues;
|
|
use crate::prelude::*;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub(crate) struct MainQueueEntry {
|
|
pub id: CardId,
|
|
pub mtime: TimestampSecs,
|
|
pub kind: MainQueueEntryKind,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub(crate) enum MainQueueEntryKind {
|
|
New,
|
|
Review,
|
|
InterdayLearning,
|
|
}
|
|
|
|
impl CardQueues {
|
|
/// Remove the head of the main queue, and update counts.
|
|
pub(super) fn pop_main(&mut self) -> Option<MainQueueEntry> {
|
|
self.main.pop_front().inspect(|head| {
|
|
match head.kind {
|
|
MainQueueEntryKind::New => self.counts.new -= 1,
|
|
MainQueueEntryKind::Review => self.counts.review -= 1,
|
|
MainQueueEntryKind::InterdayLearning => {
|
|
// the bug causing learning counts to go below zero should
|
|
// hopefully be fixed at this point, but ensure we don't wrap
|
|
// if it isn't
|
|
self.counts.learning = self.counts.learning.saturating_sub(1)
|
|
}
|
|
};
|
|
})
|
|
}
|
|
|
|
/// Add an undone entry to the top of the main queue.
|
|
pub(super) fn push_main(&mut self, entry: MainQueueEntry) {
|
|
match entry.kind {
|
|
MainQueueEntryKind::New => self.counts.new += 1,
|
|
MainQueueEntryKind::Review => self.counts.review += 1,
|
|
MainQueueEntryKind::InterdayLearning => self.counts.learning += 1,
|
|
};
|
|
self.main.push_front(entry);
|
|
}
|
|
}
|