From 64ebc32b3d1f88f7e4038c95cb03cc54beb340d9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 18 Apr 2021 18:29:20 +1000 Subject: [PATCH] tidy up Rust imports rustfmt can do this automatically, but only when run with a nightly toolchain, so it needs to be manually done for now - see rslib/rusfmt.toml --- rslib/build/protobuf.rs | 3 +- rslib/rustfmt.toml | 4 ++ rslib/src/backend/adding.rs | 3 +- rslib/src/backend/card.rs | 4 +- rslib/src/backend/cardrendering.rs | 2 +- rslib/src/backend/collection.rs | 5 +- rslib/src/backend/config.rs | 8 +-- rslib/src/backend/dbproxy.rs | 3 +- rslib/src/backend/deckconfig.rs | 2 +- rslib/src/backend/decks.rs | 2 +- rslib/src/backend/error.rs | 3 +- rslib/src/backend/i18n.rs | 5 +- rslib/src/backend/media.rs | 2 +- rslib/src/backend/mod.rs | 19 +++--- rslib/src/backend/notes.rs | 2 +- rslib/src/backend/notetypes.rs | 2 +- rslib/src/backend/progress.rs | 6 +- rslib/src/backend/scheduler/mod.rs | 2 +- rslib/src/backend/search/mod.rs | 2 +- rslib/src/backend/search/search_node.rs | 7 +-- rslib/src/backend/stats.rs | 2 +- rslib/src/backend/sync/mod.rs | 5 +- rslib/src/backend/sync/server.rs | 3 +- rslib/src/backend/tags.rs | 2 +- rslib/src/browser_table.rs | 4 +- rslib/src/card/mod.rs | 24 ++++--- rslib/src/cloze.rs | 15 +++-- rslib/src/collection/mod.rs | 12 ++-- rslib/src/config/bool.rs | 3 +- rslib/src/config/deck.rs | 4 +- rslib/src/config/mod.rs | 8 +-- rslib/src/config/notetype.rs | 4 +- rslib/src/config/string.rs | 3 +- rslib/src/dbcheck.rs | 8 ++- rslib/src/deckconf/mod.rs | 13 ++-- rslib/src/deckconf/schema11.rs | 9 +-- rslib/src/deckconf/update.rs | 8 ++- rslib/src/decks/counts.rs | 3 +- rslib/src/decks/mod.rs | 22 ++++--- rslib/src/decks/name.rs | 6 +- rslib/src/decks/schema11.rs | 14 +++-- rslib/src/decks/tree.rs | 14 +++-- rslib/src/error/db.rs | 3 +- rslib/src/error/mod.rs | 15 +++-- rslib/src/error/network.rs | 4 +- rslib/src/error/search.rs | 5 +- rslib/src/findreplace.rs | 6 +- rslib/src/latex.rs | 8 +-- rslib/src/log.rs | 4 +- rslib/src/media/changetracker.rs | 38 +++++++----- rslib/src/media/check.rs | 62 ++++++++++++------- rslib/src/media/database.rs | 16 ++--- rslib/src/media/files.rs | 25 +++++--- rslib/src/media/mod.rs | 20 ++++-- rslib/src/media/sync.rs | 47 +++++++++----- rslib/src/notes/mod.rs | 21 ++++--- rslib/src/notes/undo.rs | 3 +- rslib/src/notetype/cardgen.rs | 8 ++- rslib/src/notetype/emptycards.rs | 4 +- rslib/src/notetype/mod.rs | 31 +++++----- rslib/src/notetype/render.rs | 3 +- rslib/src/notetype/schema11.rs | 15 ++--- rslib/src/notetype/stock.rs | 3 +- rslib/src/preferences.rs | 3 +- rslib/src/prelude.rs | 3 +- rslib/src/revlog/mod.rs | 8 ++- rslib/src/scheduler/answering/current.rs | 3 +- rslib/src/scheduler/answering/learning.rs | 3 +- rslib/src/scheduler/answering/mod.rs | 15 +++-- rslib/src/scheduler/answering/preview.rs | 8 +-- rslib/src/scheduler/answering/relearning.rs | 3 +- rslib/src/scheduler/answering/review.rs | 3 +- rslib/src/scheduler/bury_and_suspend.rs | 12 ++-- rslib/src/scheduler/congrats.rs | 3 +- rslib/src/scheduler/filtered/card.rs | 3 +- rslib/src/scheduler/filtered/mod.rs | 11 ++-- rslib/src/scheduler/new.rs | 6 +- rslib/src/scheduler/queue/builder/mod.rs | 10 ++- rslib/src/scheduler/queue/builder/sorting.rs | 6 +- rslib/src/scheduler/queue/entry.rs | 3 +- rslib/src/scheduler/queue/limits.rs | 3 +- rslib/src/scheduler/queue/mod.rs | 11 ++-- rslib/src/scheduler/reviews.rs | 7 ++- rslib/src/scheduler/states/filtered.rs | 3 +- rslib/src/scheduler/states/learning.rs | 3 +- rslib/src/scheduler/states/mod.rs | 21 +++---- rslib/src/scheduler/states/new.rs | 3 +- rslib/src/scheduler/states/normal.rs | 3 +- rslib/src/scheduler/states/relearning.rs | 3 +- .../scheduler/states/rescheduling_filter.rs | 3 +- rslib/src/scheduler/states/review.rs | 3 +- rslib/src/scheduler/timespan.rs | 6 +- rslib/src/scheduler/timing.rs | 6 +- rslib/src/scheduler/upgrade.rs | 3 +- rslib/src/search/mod.rs | 17 +++-- rslib/src/search/parser.rs | 17 ++--- rslib/src/search/sqlwriter.rs | 13 ++-- rslib/src/search/writer.rs | 6 +- rslib/src/serde.rs | 6 +- rslib/src/stats/card.rs | 5 +- rslib/src/storage/card/mod.rs | 21 ++++--- rslib/src/storage/collection_timestamps.rs | 3 +- rslib/src/storage/config/mod.rs | 8 ++- rslib/src/storage/deck/mod.rs | 13 ++-- rslib/src/storage/deckconf/mod.rs | 10 +-- rslib/src/storage/graves/mod.rs | 8 ++- rslib/src/storage/mod.rs | 4 +- rslib/src/storage/note/mod.rs | 3 +- rslib/src/storage/notetype/mod.rs | 13 ++-- rslib/src/storage/revlog/mod.rs | 18 +++--- rslib/src/storage/sqlite.rs | 17 ++--- rslib/src/storage/sync.rs | 3 +- rslib/src/storage/sync_check.rs | 3 +- rslib/src/storage/tag/mod.rs | 7 ++- rslib/src/sync/http.rs | 6 +- rslib/src/sync/http_client.rs | 42 ++++++------- rslib/src/sync/mod.rs | 36 +++++------ rslib/src/sync/server.rs | 8 +-- rslib/src/tags/bulkadd.rs | 1 + rslib/src/tags/matcher.rs | 3 +- rslib/src/tags/register.rs | 7 ++- rslib/src/tags/remove.rs | 3 +- rslib/src/template.rs | 29 ++++++--- rslib/src/template_filters.rs | 24 ++++--- rslib/src/text.rs | 7 ++- rslib/src/timestamp.rs | 7 ++- rslib/src/undo/mod.rs | 8 +-- rslib/src/version.rs | 3 +- 128 files changed, 649 insertions(+), 524 deletions(-) create mode 100644 rslib/rustfmt.toml diff --git a/rslib/build/protobuf.rs b/rslib/build/protobuf.rs index 30aa3a6a2..42c0440a3 100644 --- a/rslib/build/protobuf.rs +++ b/rslib/build/protobuf.rs @@ -1,8 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use std::path::PathBuf; -use std::{env, fmt::Write}; +use std::{env, fmt::Write, path::PathBuf}; struct CustomGenerator {} diff --git a/rslib/rustfmt.toml b/rslib/rustfmt.toml new file mode 100644 index 000000000..3c812a2b9 --- /dev/null +++ b/rslib/rustfmt.toml @@ -0,0 +1,4 @@ +# this is not supported on stable Rust, and is ignored by the Bazel rules; it is only +# useful for manual invocation with 'cargo +nightly fmt' +imports_granularity = "Crate" +group_imports = "StdExternalCrate" diff --git a/rslib/src/backend/adding.rs b/rslib/src/backend/adding.rs index 50d24512c..261d7ce13 100644 --- a/rslib/src/backend/adding.rs +++ b/rslib/src/backend/adding.rs @@ -1,8 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::adding::DeckAndNotetype; -use crate::backend_proto::DeckAndNotetype as DeckAndNotetypeProto; +use crate::{adding::DeckAndNotetype, backend_proto::DeckAndNotetype as DeckAndNotetypeProto}; impl From for DeckAndNotetypeProto { fn from(s: DeckAndNotetype) -> Self { diff --git a/rslib/src/backend/card.rs b/rslib/src/backend/card.rs index 2e2b0973c..03c7b59e9 100644 --- a/rslib/src/backend/card.rs +++ b/rslib/src/backend/card.rs @@ -4,12 +4,12 @@ use std::convert::{TryFrom, TryInto}; use super::Backend; -use crate::prelude::*; +pub(super) use crate::backend_proto::cards_service::Service as CardsService; use crate::{ backend_proto as pb, card::{CardQueue, CardType}, + prelude::*, }; -pub(super) use pb::cards_service::Service as CardsService; impl CardsService for Backend { fn get_card(&self, input: pb::CardId) -> Result { diff --git a/rslib/src/backend/cardrendering.rs b/rslib/src/backend/cardrendering.rs index a2a016b8e..a68e3ea7b 100644 --- a/rslib/src/backend/cardrendering.rs +++ b/rslib/src/backend/cardrendering.rs @@ -2,6 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::Backend; +pub(super) use crate::backend_proto::cardrendering_service::Service as CardRenderingService; use crate::{ backend_proto as pb, latex::{extract_latex, extract_latex_expanding_clozes, ExtractedLatex}, @@ -11,7 +12,6 @@ use crate::{ template::RenderedNode, text::{extract_av_tags, sanitize_html_no_images, strip_av_tags, AvTag}, }; -pub(super) use pb::cardrendering_service::Service as CardRenderingService; impl CardRenderingService for Backend { fn extract_av_tags(&self, input: pb::ExtractAvTagsIn) -> Result { diff --git a/rslib/src/backend/collection.rs b/rslib/src/backend/collection.rs index 577954d83..dd23890c2 100644 --- a/rslib/src/backend/collection.rs +++ b/rslib/src/backend/collection.rs @@ -1,7 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use slog::error; + use super::{progress::Progress, Backend}; +pub(super) use crate::backend_proto::collection_service::Service as CollectionService; use crate::{ backend::progress::progress_to_proto, backend_proto as pb, @@ -9,8 +12,6 @@ use crate::{ log::{self, default_logger}, prelude::*, }; -pub(super) use pb::collection_service::Service as CollectionService; -use slog::error; impl CollectionService for Backend { fn latest_progress(&self, _input: pb::Empty) -> Result { diff --git a/rslib/src/backend/config.rs b/rslib/src/backend/config.rs index a1aeaabd1..751866ba7 100644 --- a/rslib/src/backend/config.rs +++ b/rslib/src/backend/config.rs @@ -1,16 +1,16 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use serde_json::Value; + use super::Backend; +pub(super) use crate::backend_proto::config_service::Service as ConfigService; use crate::{ backend_proto as pb, + backend_proto::config::{bool::Key as BoolKeyProto, string::Key as StringKeyProto}, config::{BoolKey, StringKey}, prelude::*, }; -use pb::config::bool::Key as BoolKeyProto; -use pb::config::string::Key as StringKeyProto; -pub(super) use pb::config_service::Service as ConfigService; -use serde_json::Value; impl From for BoolKey { fn from(k: BoolKeyProto) -> Self { diff --git a/rslib/src/backend/dbproxy.rs b/rslib/src/backend/dbproxy.rs index fb85d2071..c9dba9c13 100644 --- a/rslib/src/backend/dbproxy.rs +++ b/rslib/src/backend/dbproxy.rs @@ -1,13 +1,14 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{prelude::*, storage::SqliteStorage}; use rusqlite::{ types::{FromSql, FromSqlError, ToSql, ToSqlOutput, ValueRef}, OptionalExtension, }; use serde_derive::{Deserialize, Serialize}; +use crate::{prelude::*, storage::SqliteStorage}; + #[derive(Deserialize)] #[serde(tag = "kind", rename_all = "lowercase")] pub(super) enum DbRequest { diff --git a/rslib/src/backend/deckconfig.rs b/rslib/src/backend/deckconfig.rs index 86b813dca..968c10f70 100644 --- a/rslib/src/backend/deckconfig.rs +++ b/rslib/src/backend/deckconfig.rs @@ -2,12 +2,12 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::Backend; +pub(super) use crate::backend_proto::deckconfig_service::Service as DeckConfigService; use crate::{ backend_proto as pb, deckconf::{DeckConf, DeckConfSchema11, UpdateDeckConfigsIn}, prelude::*, }; -pub(super) use pb::deckconfig_service::Service as DeckConfigService; impl DeckConfigService for Backend { fn add_or_update_deck_config_legacy( diff --git a/rslib/src/backend/decks.rs b/rslib/src/backend/decks.rs index 5f88279af..ebe2ca96d 100644 --- a/rslib/src/backend/decks.rs +++ b/rslib/src/backend/decks.rs @@ -4,13 +4,13 @@ use std::convert::TryFrom; use super::Backend; +pub(super) use crate::backend_proto::decks_service::Service as DecksService; use crate::{ backend_proto::{self as pb}, decks::{DeckSchema11, FilteredSearchOrder}, prelude::*, scheduler::filtered::FilteredDeckForUpdate, }; -pub(super) use pb::decks_service::Service as DecksService; impl DecksService for Backend { fn add_deck_legacy(&self, input: pb::Json) -> Result { diff --git a/rslib/src/backend/error.rs b/rslib/src/backend/error.rs index 2e5c2a24c..20a02b464 100644 --- a/rslib/src/backend/error.rs +++ b/rslib/src/backend/error.rs @@ -3,12 +3,11 @@ use crate::{ backend_proto as pb, + backend_proto::backend_error::Kind, error::{AnkiError, SyncErrorKind}, prelude::*, }; -use pb::backend_error::Kind; - impl AnkiError { pub(super) fn into_protobuf(self, tr: &I18n) -> pb::BackendError { let localized = self.localized_description(tr); diff --git a/rslib/src/backend/i18n.rs b/rslib/src/backend/i18n.rs index 8136a8974..2430088bf 100644 --- a/rslib/src/backend/i18n.rs +++ b/rslib/src/backend/i18n.rs @@ -3,14 +3,15 @@ use std::collections::HashMap; +use fluent::{FluentArgs, FluentValue}; + use super::Backend; +pub(super) use crate::backend_proto::i18n_service::Service as I18nService; use crate::{ backend_proto as pb, prelude::*, scheduler::timespan::{answer_button_time, time_span}, }; -use fluent::{FluentArgs, FluentValue}; -pub(super) use pb::i18n_service::Service as I18nService; impl I18nService for Backend { fn translate_string(&self, input: pb::TranslateStringIn) -> Result { diff --git a/rslib/src/backend/media.rs b/rslib/src/backend/media.rs index 9c8f7ba7f..306c96b40 100644 --- a/rslib/src/backend/media.rs +++ b/rslib/src/backend/media.rs @@ -2,12 +2,12 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::{progress::Progress, Backend}; +pub(super) use crate::backend_proto::media_service::Service as MediaService; use crate::{ backend_proto as pb, media::{check::MediaChecker, MediaManager}, prelude::*, }; -pub(super) use pb::media_service::Service as MediaService; impl MediaService for Backend { // media diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 38497c36b..f4da3463a 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -26,6 +26,16 @@ mod stats; mod sync; mod tags; +use std::{ + result, + sync::{Arc, Mutex}, +}; + +use once_cell::sync::OnceCell; +use progress::AbortHandleSlot; +use prost::Message; +use tokio::runtime::{self, Runtime}; + use self::{ card::CardsService, cardrendering::CardRenderingService, @@ -44,7 +54,6 @@ use self::{ sync::{SyncService, SyncState}, tags::TagsService, }; - use crate::{ backend::dbproxy::db_command_bytes, backend_proto as pb, @@ -52,14 +61,6 @@ use crate::{ error::{AnkiError, Result}, i18n::I18n, }; -use once_cell::sync::OnceCell; -use progress::AbortHandleSlot; -use prost::Message; -use std::{ - result, - sync::{Arc, Mutex}, -}; -use tokio::runtime::{self, Runtime}; pub struct Backend { col: Arc>>, diff --git a/rslib/src/backend/notes.rs b/rslib/src/backend/notes.rs index 864c0e5e0..8b42087f4 100644 --- a/rslib/src/backend/notes.rs +++ b/rslib/src/backend/notes.rs @@ -4,12 +4,12 @@ use std::collections::HashSet; use super::Backend; +pub(super) use crate::backend_proto::notes_service::Service as NotesService; use crate::{ backend_proto::{self as pb}, cloze::add_cloze_numbers_in_string, prelude::*, }; -pub(super) use pb::notes_service::Service as NotesService; impl NotesService for Backend { fn new_note(&self, input: pb::NotetypeId) -> Result { diff --git a/rslib/src/backend/notetypes.rs b/rslib/src/backend/notetypes.rs index 29708a55a..0c283608d 100644 --- a/rslib/src/backend/notetypes.rs +++ b/rslib/src/backend/notetypes.rs @@ -2,12 +2,12 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::Backend; +pub(super) use crate::backend_proto::notetypes_service::Service as NotetypesService; use crate::{ backend_proto as pb, notetype::{all_stock_notetypes, Notetype, NotetypeSchema11}, prelude::*, }; -pub(super) use pb::notetypes_service::Service as NotetypesService; impl NotetypesService for Backend { fn add_or_update_notetype(&self, input: pb::AddOrUpdateNotetypeIn) -> Result { diff --git a/rslib/src/backend/progress.rs b/rslib/src/backend/progress.rs index 3890c97d0..b7ec45911 100644 --- a/rslib/src/backend/progress.rs +++ b/rslib/src/backend/progress.rs @@ -1,9 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use futures::future::AbortHandle; use std::sync::{Arc, Mutex}; +use futures::future::AbortHandle; + +use super::Backend; use crate::{ backend_proto as pb, dbcheck::DatabaseCheckProgress, @@ -12,8 +14,6 @@ use crate::{ sync::{FullSyncProgress, NormalSyncProgress, SyncStage}, }; -use super::Backend; - pub(super) struct ThrottlingProgressHandler { pub state: Arc>, pub last_update: coarsetime::Instant, diff --git a/rslib/src/backend/scheduler/mod.rs b/rslib/src/backend/scheduler/mod.rs index 49084ad93..a90f01265 100644 --- a/rslib/src/backend/scheduler/mod.rs +++ b/rslib/src/backend/scheduler/mod.rs @@ -5,6 +5,7 @@ mod answering; mod states; use super::Backend; +pub(super) use crate::backend_proto::scheduling_service::Service as SchedulingService; use crate::{ backend_proto::{self as pb}, prelude::*, @@ -14,7 +15,6 @@ use crate::{ }, stats::studied_today, }; -pub(super) use pb::scheduling_service::Service as SchedulingService; impl SchedulingService for Backend { /// This behaves like _updateCutoff() in older code - it also unburies at the start of diff --git a/rslib/src/backend/search/mod.rs b/rslib/src/backend/search/mod.rs index 49a49d7f5..23efcd423 100644 --- a/rslib/src/backend/search/mod.rs +++ b/rslib/src/backend/search/mod.rs @@ -7,6 +7,7 @@ mod search_node; use std::{convert::TryInto, str::FromStr, sync::Arc}; use super::Backend; +pub(super) use crate::backend_proto::search_service::Service as SearchService; use crate::{ backend_proto as pb, backend_proto::sort_order::Value as SortOrderProto, @@ -14,7 +15,6 @@ use crate::{ prelude::*, search::{concatenate_searches, replace_search_node, write_nodes, Node, SortMode}, }; -pub(super) use pb::search_service::Service as SearchService; impl SearchService for Backend { fn build_search_string(&self, input: pb::SearchNode) -> Result { diff --git a/rslib/src/backend/search/search_node.rs b/rslib/src/backend/search/search_node.rs index 1a0897c80..8d23f0d5e 100644 --- a/rslib/src/backend/search/search_node.rs +++ b/rslib/src/backend/search/search_node.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use itertools::Itertools; use std::convert::{TryFrom, TryInto}; +use itertools::Itertools; + use crate::{ backend_proto as pb, prelude::*, @@ -18,9 +19,7 @@ impl TryFrom for Node { type Error = AnkiError; fn try_from(msg: pb::SearchNode) -> std::result::Result { - use pb::search_node::group::Joiner; - use pb::search_node::Filter; - use pb::search_node::Flag; + use pb::search_node::{group::Joiner, Filter, Flag}; Ok(if let Some(filter) = msg.filter { match filter { Filter::Tag(s) => Node::Search(SearchNode::Tag(escape_anki_wildcards(&s))), diff --git a/rslib/src/backend/stats.rs b/rslib/src/backend/stats.rs index 01ef3ea83..ee079ad30 100644 --- a/rslib/src/backend/stats.rs +++ b/rslib/src/backend/stats.rs @@ -2,8 +2,8 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::Backend; +pub(super) use crate::backend_proto::stats_service::Service as StatsService; use crate::{backend_proto as pb, prelude::*}; -pub(super) use pb::stats_service::Service as StatsService; impl StatsService for Backend { fn card_stats(&self, input: pb::CardId) -> Result { diff --git a/rslib/src/backend/sync/mod.rs b/rslib/src/backend/sync/mod.rs index 9dd218e68..320e580a7 100644 --- a/rslib/src/backend/sync/mod.rs +++ b/rslib/src/backend/sync/mod.rs @@ -8,6 +8,8 @@ use std::sync::Arc; use futures::future::{AbortHandle, AbortRegistration, Abortable}; use slog::warn; +use super::{progress::AbortHandleSlot, Backend}; +pub(super) use crate::backend_proto::sync_service::Service as SyncService; use crate::{ backend_proto as pb, collection::open_collection, @@ -19,9 +21,6 @@ use crate::{ }, }; -use super::{progress::AbortHandleSlot, Backend}; -pub(super) use pb::sync_service::Service as SyncService; - #[derive(Default)] pub(super) struct SyncState { remote_sync_status: RemoteSyncStatus, diff --git a/rslib/src/backend/sync/server.rs b/rslib/src/backend/sync/server.rs index a5a907e48..7f6fb5b5c 100644 --- a/rslib/src/backend/sync/server.rs +++ b/rslib/src/backend/sync/server.rs @@ -2,10 +2,11 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use std::{path::PathBuf, sync::MutexGuard}; + use tokio::runtime::Runtime; -use crate::backend::{Backend, BackendState}; use crate::{ + backend::{Backend, BackendState}, error::SyncErrorKind, prelude::*, sync::{ diff --git a/rslib/src/backend/tags.rs b/rslib/src/backend/tags.rs index 26fce5287..1c72de457 100644 --- a/rslib/src/backend/tags.rs +++ b/rslib/src/backend/tags.rs @@ -2,8 +2,8 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::{notes::to_note_ids, Backend}; +pub(super) use crate::backend_proto::tags_service::Service as TagsService; use crate::{backend_proto as pb, prelude::*}; -pub(super) use pb::tags_service::Service as TagsService; impl TagsService for Backend { fn clear_unused_tags(&self, _input: pb::Empty) -> Result { diff --git a/rslib/src/browser_table.rs b/rslib/src/browser_table.rs index d0f2dded7..dbe0064ae 100644 --- a/rslib/src/browser_table.rs +++ b/rslib/src/browser_table.rs @@ -6,14 +6,14 @@ use std::sync::Arc; use itertools::Itertools; use strum::{Display, EnumIter, EnumString, IntoEnumIterator}; -use crate::error::{AnkiError, Result}; -use crate::i18n::I18n; use crate::{ backend_proto as pb, card::{Card, CardId, CardQueue, CardType}, collection::Collection, config::BoolKey, decks::{Deck, DeckId}, + error::{AnkiError, Result}, + i18n::I18n, notes::{Note, NoteId}, notetype::{CardTemplate, Notetype, NotetypeKind}, scheduler::{timespan::time_span, timing::SchedTimingToday}, diff --git a/rslib/src/card/mod.rs b/rslib/src/card/mod.rs index 6bfdf01b4..b59e7c52d 100644 --- a/rslib/src/card/mod.rs +++ b/rslib/src/card/mod.rs @@ -3,18 +3,24 @@ pub(crate) mod undo; -use crate::error::{AnkiError, FilteredDeckError, Result}; -use crate::notes::NoteId; -use crate::{ - collection::Collection, config::SchedulerVersion, prelude::*, timestamp::TimestampSecs, - types::Usn, -}; -use crate::{define_newtype, ops::StateChanges}; +use std::collections::HashSet; -use crate::{deckconf::DeckConf, decks::DeckId}; use num_enum::TryFromPrimitive; use serde_repr::{Deserialize_repr, Serialize_repr}; -use std::collections::HashSet; + +use crate::{ + collection::Collection, + config::SchedulerVersion, + deckconf::DeckConf, + decks::DeckId, + define_newtype, + error::{AnkiError, FilteredDeckError, Result}, + notes::NoteId, + ops::StateChanges, + prelude::*, + timestamp::TimestampSecs, + types::Usn, +}; define_newtype!(CardId, i64); diff --git a/rslib/src/cloze.rs b/rslib/src/cloze.rs index 759873e3a..01f219ed3 100644 --- a/rslib/src/cloze.rs +++ b/rslib/src/cloze.rs @@ -1,14 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::latex::contains_latex; -use crate::template::RenderContext; -use crate::text::strip_html_preserving_entities; +use std::{borrow::Cow, collections::HashSet}; + use lazy_static::lazy_static; -use regex::Captures; -use regex::Regex; -use std::borrow::Cow; -use std::collections::HashSet; +use regex::{Captures, Regex}; + +use crate::{latex::contains_latex, template::RenderContext, text::strip_html_preserving_entities}; lazy_static! { static ref CLOZE: Regex = Regex::new( @@ -182,9 +180,10 @@ pub(crate) fn cloze_only_filter<'a>(text: &'a str, context: &RenderContext) -> C #[cfg(test)] mod test { + use std::collections::HashSet; + use super::*; use crate::text::strip_html; - use std::collections::HashSet; #[test] fn cloze() { diff --git a/rslib/src/collection/mod.rs b/rslib/src/collection/mod.rs index b6e8986fc..79660276d 100644 --- a/rslib/src/collection/mod.rs +++ b/rslib/src/collection/mod.rs @@ -5,18 +5,20 @@ pub(crate) mod timestamps; mod transact; pub(crate) mod undo; -use crate::i18n::I18n; -use crate::types::Usn; +use std::{collections::HashMap, path::PathBuf, sync::Arc}; + use crate::{ browser_table, decks::{Deck, DeckId}, + error::Result, + i18n::I18n, + log::Logger, notetype::{Notetype, NotetypeId}, + scheduler::{queue::CardQueues, SchedulerInfo}, storage::SqliteStorage, + types::Usn, undo::UndoManager, }; -use crate::{error::Result, scheduler::queue::CardQueues}; -use crate::{log::Logger, scheduler::SchedulerInfo}; -use std::{collections::HashMap, path::PathBuf, sync::Arc}; pub fn open_collection>( path: P, diff --git a/rslib/src/config/bool.rs b/rslib/src/config/bool.rs index 517a9d499..6e3cf50e6 100644 --- a/rslib/src/config/bool.rs +++ b/rslib/src/config/bool.rs @@ -1,11 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::prelude::*; use serde_aux::field_attributes::deserialize_bool_from_anything; use serde_derive::Deserialize; use strum::IntoStaticStr; +use crate::prelude::*; + #[derive(Debug, Clone, Copy, IntoStaticStr)] #[strum(serialize_all = "camelCase")] pub enum BoolKey { diff --git a/rslib/src/config/deck.rs b/rslib/src/config/deck.rs index 0eef0474c..89e92e2e3 100644 --- a/rslib/src/config/deck.rs +++ b/rslib/src/config/deck.rs @@ -1,10 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::prelude::*; - use strum::IntoStaticStr; +use crate::prelude::*; + /// Auxillary deck state, stored in the config table. #[derive(Debug, Clone, Copy, IntoStaticStr)] #[strum(serialize_all = "camelCase")] diff --git a/rslib/src/config/mod.rs b/rslib/src/config/mod.rs index 200d18302..6a61e18f0 100644 --- a/rslib/src/config/mod.rs +++ b/rslib/src/config/mod.rs @@ -8,13 +8,14 @@ pub(crate) mod schema11; mod string; pub(crate) mod undo; -pub use self::{bool::BoolKey, string::StringKey}; -use crate::prelude::*; use serde::{de::DeserializeOwned, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; use slog::warn; use strum::IntoStaticStr; +pub use self::{bool::BoolKey, string::StringKey}; +use crate::prelude::*; + /// Only used when updating/undoing. #[derive(Debug)] pub(crate) struct ConfigEntry { @@ -263,8 +264,7 @@ pub(crate) enum Weekday { #[cfg(test)] mod test { - use crate::collection::open_test_collection; - use crate::decks::DeckId; + use crate::{collection::open_test_collection, decks::DeckId}; #[test] fn defaults() { diff --git a/rslib/src/config/notetype.rs b/rslib/src/config/notetype.rs index c672964a9..62259e21e 100644 --- a/rslib/src/config/notetype.rs +++ b/rslib/src/config/notetype.rs @@ -1,11 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use strum::IntoStaticStr; + use super::ConfigKey; use crate::prelude::*; -use strum::IntoStaticStr; - /// Notetype config packed into a collection config key. This may change /// frequently, and we want to avoid the potentially expensive notetype /// write/sync. diff --git a/rslib/src/config/string.rs b/rslib/src/config/string.rs index 45bda80fb..9fd2e0844 100644 --- a/rslib/src/config/string.rs +++ b/rslib/src/config/string.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::prelude::*; use strum::IntoStaticStr; +use crate::prelude::*; + #[derive(Debug, Clone, Copy, IntoStaticStr)] #[strum(serialize_all = "camelCase")] pub enum StringKey { diff --git a/rslib/src/dbcheck.rs b/rslib/src/dbcheck.rs index 733661883..09fd78795 100644 --- a/rslib/src/dbcheck.rs +++ b/rslib/src/dbcheck.rs @@ -1,6 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{collections::HashSet, sync::Arc}; + +use itertools::Itertools; +use slog::debug; + use crate::{ collection::Collection, config::SchedulerVersion, @@ -13,9 +18,6 @@ use crate::{ prelude::*, timestamp::{TimestampMillis, TimestampSecs}, }; -use itertools::Itertools; -use slog::debug; -use std::{collections::HashSet, sync::Arc}; #[derive(Debug, Default, PartialEq)] pub struct CheckDatabaseOutput { diff --git a/rslib/src/deckconf/mod.rs b/rslib/src/deckconf/mod.rs index 8927eb4f8..97fe27095 100644 --- a/rslib/src/deckconf/mod.rs +++ b/rslib/src/deckconf/mod.rs @@ -5,13 +5,12 @@ mod schema11; pub(crate) mod undo; mod update; -pub use { - crate::backend_proto::{ - deck_config::config::{LeechAction, NewCardOrder, ReviewCardOrder, ReviewMix}, - deck_config::Config as DeckConfigInner, - }, - schema11::{DeckConfSchema11, NewCardOrderSchema11}, - update::UpdateDeckConfigsIn, +pub use schema11::{DeckConfSchema11, NewCardOrderSchema11}; +pub use update::UpdateDeckConfigsIn; + +pub use crate::backend_proto::deck_config::{ + config::{LeechAction, NewCardOrder, ReviewCardOrder, ReviewMix}, + Config as DeckConfigInner, }; /// Old deck config and cards table store 250% as 2500. diff --git a/rslib/src/deckconf/schema11.rs b/rslib/src/deckconf/schema11.rs index 4e663bda6..7d15c9aae 100644 --- a/rslib/src/deckconf/schema11.rs +++ b/rslib/src/deckconf/schema11.rs @@ -1,15 +1,16 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::{DeckConf, DeckConfId, INITIAL_EASE_FACTOR_THOUSANDS}; -use super::{DeckConfigInner, NewCardOrder}; -use crate::{serde::default_on_invalid, timestamp::TimestampSecs, types::Usn}; +use std::collections::HashMap; + use serde_aux::field_attributes::deserialize_number_from_string; use serde_derive::{Deserialize, Serialize}; use serde_json::Value; use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_tuple::Serialize_tuple; -use std::collections::HashMap; + +use super::{DeckConf, DeckConfId, DeckConfigInner, NewCardOrder, INITIAL_EASE_FACTOR_THOUSANDS}; +use crate::{serde::default_on_invalid, timestamp::TimestampSecs, types::Usn}; #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] #[serde(rename_all = "camelCase")] diff --git a/rslib/src/deckconf/update.rs b/rslib/src/deckconf/update.rs index ae2fb1008..aa5c40d50 100644 --- a/rslib/src/deckconf/update.rs +++ b/rslib/src/deckconf/update.rs @@ -3,9 +3,11 @@ use std::collections::{HashMap, HashSet}; -use pb::deck_configs_for_update::{ConfigWithExtra, CurrentDeck}; - -use crate::{backend_proto as pb, prelude::*}; +use crate::{ + backend_proto as pb, + backend_proto::deck_configs_for_update::{ConfigWithExtra, CurrentDeck}, + prelude::*, +}; pub struct UpdateDeckConfigsIn { pub target_deck_id: DeckId, diff --git a/rslib/src/decks/counts.rs b/rslib/src/decks/counts.rs index 5507e33fd..17593dae5 100644 --- a/rslib/src/decks/counts.rs +++ b/rslib/src/decks/counts.rs @@ -1,8 +1,9 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{backend_proto as pb, prelude::*}; use std::collections::HashMap; +use crate::{backend_proto as pb, prelude::*}; + #[derive(Debug)] pub(crate) struct DueCounts { pub new: u32, diff --git a/rslib/src/decks/mod.rs b/rslib/src/decks/mod.rs index 384041a22..e4e3b8f4e 100644 --- a/rslib/src/decks/mod.rs +++ b/rslib/src/decks/mod.rs @@ -13,22 +13,26 @@ mod stats; mod tree; pub(crate) mod undo; +use std::sync::Arc; + +pub(crate) use counts::DueCounts; +pub(crate) use name::immediate_parent_name; +pub use name::NativeDeckName; +pub use schema11::DeckSchema11; + pub use crate::backend_proto::{ - deck::filtered::{search_term::Order as FilteredSearchOrder, SearchTerm as FilteredSearchTerm}, - deck::kind_container::Kind as DeckKind, - deck::KindContainer as DeckKindContainer, - deck::{Common as DeckCommon, Filtered as FilteredDeck, Normal as NormalDeck}, + deck::{ + filtered::{search_term::Order as FilteredSearchOrder, SearchTerm as FilteredSearchTerm}, + kind_container::Kind as DeckKind, + Common as DeckCommon, Filtered as FilteredDeck, KindContainer as DeckKindContainer, + Normal as NormalDeck, + }, Deck as DeckProto, }; use crate::{ define_newtype, error::FilteredDeckError, markdown::render_markdown, prelude::*, text::sanitize_html_no_images, }; -pub(crate) use counts::DueCounts; -pub(crate) use name::immediate_parent_name; -pub use name::NativeDeckName; -pub use schema11::DeckSchema11; -use std::sync::Arc; define_newtype!(DeckId, i64); diff --git a/rslib/src/decks/name.rs b/rslib/src/decks/name.rs index 3b1db1b4e..6c036317f 100644 --- a/rslib/src/decks/name.rs +++ b/rslib/src/decks/name.rs @@ -1,9 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{prelude::*, text::normalize_to_nfc}; -use itertools::Itertools; use std::borrow::Cow; +use itertools::Itertools; + +use crate::{prelude::*, text::normalize_to_nfc}; + #[derive(Debug, Clone, PartialEq)] pub struct NativeDeckName(String); diff --git a/rslib/src/decks/schema11.rs b/rslib/src/decks/schema11.rs index 23b873a27..873a076b4 100644 --- a/rslib/src/decks/schema11.rs +++ b/rslib/src/decks/schema11.rs @@ -1,17 +1,18 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::HashMap; + +use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; +use serde_tuple::Serialize_tuple; + use super::{DeckCommon, FilteredDeck, FilteredSearchTerm, NormalDeck}; use crate::{ prelude::*, serde::{default_on_invalid, deserialize_bool_from_anything, deserialize_number_from_string}, }; -use serde_derive::{Deserialize, Serialize}; -use serde_json::Value; -use serde_tuple::Serialize_tuple; -use std::collections::HashMap; - #[derive(Serialize, PartialEq, Debug, Clone)] #[serde(untagged)] pub enum DeckSchema11 { @@ -21,10 +22,11 @@ pub enum DeckSchema11 { // serde doesn't support integer/bool enum tags, so we manually pick the correct variant mod dynfix { - use super::{DeckSchema11, FilteredDeckSchema11, NormalDeckSchema11}; use serde::de::{self, Deserialize, Deserializer}; use serde_json::{Map, Value}; + use super::{DeckSchema11, FilteredDeckSchema11, NormalDeckSchema11}; + impl<'de> Deserialize<'de> for DeckSchema11 { fn deserialize(deserializer: D) -> Result where diff --git a/rslib/src/decks/tree.rs b/rslib/src/decks/tree.rs index 0e5d8b939..dc71c46ee 100644 --- a/rslib/src/decks/tree.rs +++ b/rslib/src/decks/tree.rs @@ -1,17 +1,19 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{ + collections::{HashMap, HashSet}, + iter::Peekable, +}; + +use serde_tuple::Serialize_tuple; +use unicase::UniCase; + use super::DueCounts; pub use crate::backend_proto::set_deck_collapsed_in::Scope as DeckCollapseScope; use crate::{ backend_proto::DeckTreeNode, config::SchedulerVersion, ops::OpOutput, prelude::*, undo::Op, }; -use serde_tuple::Serialize_tuple; -use std::{ - collections::{HashMap, HashSet}, - iter::Peekable, -}; -use unicase::UniCase; fn deck_names_to_tree(names: Vec<(DeckId, String)>) -> DeckTreeNode { let mut top = DeckTreeNode::default(); diff --git a/rslib/src/error/db.rs b/rslib/src/error/db.rs index 555fcd69e..ab75cb192 100644 --- a/rslib/src/error/db.rs +++ b/rslib/src/error/db.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::str::Utf8Error; + use anki_i18n::I18n; use rusqlite::{types::FromSqlError, Error}; -use std::str::Utf8Error; use super::AnkiError; diff --git a/rslib/src/error/mod.rs b/rslib/src/error/mod.rs index 215572afb..b2dd0f727 100644 --- a/rslib/src/error/mod.rs +++ b/rslib/src/error/mod.rs @@ -6,16 +6,15 @@ mod filtered; mod network; mod search; -pub use { - db::{DbError, DbErrorKind}, - filtered::FilteredDeckError, - network::{NetworkError, NetworkErrorKind, SyncError, SyncErrorKind}, - search::{ParseError, SearchErrorKind}, -}; +use std::{fmt::Display, io}; + +pub use db::{DbError, DbErrorKind}; +pub use filtered::FilteredDeckError; +pub use network::{NetworkError, NetworkErrorKind, SyncError, SyncErrorKind}; +pub use search::{ParseError, SearchErrorKind}; +use tempfile::PathPersistError; use crate::i18n::I18n; -use std::{fmt::Display, io}; -use tempfile::PathPersistError; pub type Result = std::result::Result; diff --git a/rslib/src/error/network.rs b/rslib/src/error/network.rs index ee3303cd8..e1bed1e8b 100644 --- a/rslib/src/error/network.rs +++ b/rslib/src/error/network.rs @@ -1,11 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::AnkiError; - use anki_i18n::I18n; use reqwest::StatusCode; +use super::AnkiError; + #[derive(Debug, PartialEq)] pub struct NetworkError { pub info: String, diff --git a/rslib/src/error/search.rs b/rslib/src/error/search.rs index 92f6f7a3e..e0a751eed 100644 --- a/rslib/src/error/search.rs +++ b/rslib/src/error/search.rs @@ -1,11 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::AnkiError; +use std::num::ParseIntError; use anki_i18n::I18n; use nom::error::{ErrorKind as NomErrorKind, ParseError as NomParseError}; -use std::num::ParseIntError; + +use super::AnkiError; #[derive(Debug, PartialEq)] pub enum ParseError<'a> { diff --git a/rslib/src/findreplace.rs b/rslib/src/findreplace.rs index 2b5d60c41..1cf028cf5 100644 --- a/rslib/src/findreplace.rs +++ b/rslib/src/findreplace.rs @@ -1,6 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::borrow::Cow; + +use regex::Regex; + use crate::{ collection::Collection, error::{AnkiError, Result}, @@ -8,8 +12,6 @@ use crate::{ prelude::*, text::normalize_to_nfc, }; -use regex::Regex; -use std::borrow::Cow; pub struct FindReplaceContext { nids: Vec, diff --git a/rslib/src/latex.rs b/rslib/src/latex.rs index 48ad2100b..435d2fdd0 100644 --- a/rslib/src/latex.rs +++ b/rslib/src/latex.rs @@ -1,12 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::cloze::expand_clozes_to_reveal_latex; -use crate::media::files::sha1_of_data; -use crate::text::strip_html; +use std::borrow::Cow; + use lazy_static::lazy_static; use regex::{Captures, Regex}; -use std::borrow::Cow; + +use crate::{cloze::expand_clozes_to_reveal_latex, media::files::sha1_of_data, text::strip_html}; lazy_static! { static ref LATEX: Regex = Regex::new( diff --git a/rslib/src/log.rs b/rslib/src/log.rs index 2976ae992..2c0cddd7b 100644 --- a/rslib/src/log.rs +++ b/rslib/src/log.rs @@ -1,11 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{fs, fs::OpenOptions, io}; + pub use slog::{debug, error, Logger}; use slog::{slog_o, Drain}; use slog_async::OverflowStrategy; -use std::fs::OpenOptions; -use std::{fs, io}; const LOG_ROTATE_BYTES: u64 = 50 * 1024 * 1024; diff --git a/rslib/src/media/changetracker.rs b/rslib/src/media/changetracker.rs index 787a2d206..0742be006 100644 --- a/rslib/src/media/changetracker.rs +++ b/rslib/src/media/changetracker.rs @@ -1,16 +1,19 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::error::{AnkiError, Result}; -use crate::log::{debug, Logger}; -use crate::media::database::{MediaDatabaseContext, MediaEntry}; -use crate::media::files::{ - filename_if_normalized, mtime_as_i64, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT, - NONSYNCABLE_FILENAME, +use std::{collections::HashMap, path::Path, time}; + +use crate::{ + error::{AnkiError, Result}, + log::{debug, Logger}, + media::{ + database::{MediaDatabaseContext, MediaEntry}, + files::{ + filename_if_normalized, mtime_as_i64, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT, + NONSYNCABLE_FILENAME, + }, + }, }; -use std::collections::HashMap; -use std::path::Path; -use std::time; struct FilesystemEntry { fname: String, @@ -243,16 +246,17 @@ where #[cfg(test)] mod test { - use crate::error::Result; - use crate::media::changetracker::ChangeTracker; - use crate::media::database::MediaEntry; - use crate::media::files::sha1_of_data; - use crate::media::MediaManager; - use std::path::Path; - use std::time::Duration; - use std::{fs, time}; + use std::{fs, path::Path, time, time::Duration}; + use tempfile::tempdir; + use crate::{ + error::Result, + media::{ + changetracker::ChangeTracker, database::MediaEntry, files::sha1_of_data, MediaManager, + }, + }; + // helper fn change_mtime(p: &Path) { let mtime = p.metadata().unwrap().modified().unwrap(); diff --git a/rslib/src/media/check.rs b/rslib/src/media/check.rs index 13ec9f236..1fe14316c 100644 --- a/rslib/src/media/check.rs +++ b/rslib/src/media/check.rs @@ -1,23 +1,32 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::collection::Collection; -use crate::error::{AnkiError, DbErrorKind, Result}; -use crate::latex::extract_latex_expanding_clozes; -use crate::log::debug; -use crate::media::database::MediaDatabaseContext; -use crate::media::files::{ - data_for_file, filename_if_normalized, normalize_nfc_filename, trash_folder, - MEDIA_SYNC_FILESIZE_LIMIT, +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, + fs, io, + path::Path, }; -use crate::notes::Note; -use crate::text::{normalize_to_nfc, MediaRef}; -use crate::{media::MediaManager, text::extract_media_refs}; + use lazy_static::lazy_static; use regex::Regex; -use std::collections::{HashMap, HashSet}; -use std::path::Path; -use std::{borrow::Cow, fs, io}; + +use crate::{ + collection::Collection, + error::{AnkiError, DbErrorKind, Result}, + latex::extract_latex_expanding_clozes, + log::debug, + media::{ + database::MediaDatabaseContext, + files::{ + data_for_file, filename_if_normalized, normalize_nfc_filename, trash_folder, + MEDIA_SYNC_FILESIZE_LIMIT, + }, + MediaManager, + }, + notes::Note, + text::{extract_media_refs, normalize_to_nfc, MediaRef}, +}; lazy_static! { static ref REMOTE_FILENAME: Regex = Regex::new("(?i)^https?://").unwrap(); @@ -506,18 +515,23 @@ pub(crate) mod test { pub(crate) const MEDIACHECK_ANKI2: &[u8] = include_bytes!("../../tests/support/mediacheck.anki2"); - use super::normalize_and_maybe_rename_files; - use crate::collection::{open_collection, Collection}; - use crate::error::Result; - use crate::i18n::I18n; - use crate::log; - use crate::media::check::{MediaCheckOutput, MediaChecker}; - use crate::media::files::trash_folder; - use crate::media::MediaManager; - use std::path::Path; - use std::{collections::HashMap, fs, io}; + use std::{collections::HashMap, fs, io, path::Path}; + use tempfile::{tempdir, TempDir}; + use super::normalize_and_maybe_rename_files; + use crate::{ + collection::{open_collection, Collection}, + error::Result, + i18n::I18n, + log, + media::{ + check::{MediaCheckOutput, MediaChecker}, + files::trash_folder, + MediaManager, + }, + }; + fn common_setup() -> Result<(TempDir, MediaManager, Collection)> { let dir = tempdir()?; let media_dir = dir.path().join("media"); diff --git a/rslib/src/media/database.rs b/rslib/src/media/database.rs index 6bf58fa63..a9fbcb24b 100644 --- a/rslib/src/media/database.rs +++ b/rslib/src/media/database.rs @@ -1,10 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::error::Result; +use std::{collections::HashMap, path::Path}; + use rusqlite::{params, Connection, OptionalExtension, Row, Statement, NO_PARAMS}; -use std::collections::HashMap; -use std::path::Path; + +use crate::error::Result; fn trace(s: &str) { println!("sql: {}", s) @@ -251,12 +252,13 @@ fn row_to_entry(row: &Row) -> rusqlite::Result { #[cfg(test)] mod test { - use crate::error::Result; - use crate::media::database::MediaEntry; - use crate::media::files::sha1_of_data; - use crate::media::MediaManager; use tempfile::NamedTempFile; + use crate::{ + error::Result, + media::{database::MediaEntry, files::sha1_of_data, MediaManager}, + }; + #[test] fn database() -> Result<()> { let db_file = NamedTempFile::new()?; diff --git a/rslib/src/media/files.rs b/rslib/src/media/files.rs index 6a91f4770..f317482eb 100644 --- a/rslib/src/media/files.rs +++ b/rslib/src/media/files.rs @@ -1,17 +1,24 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::error::{AnkiError, Result}; -use crate::log::{debug, Logger}; +use std::{ + borrow::Cow, + fs, io, + io::Read, + path::{Path, PathBuf}, + time, +}; + use lazy_static::lazy_static; use regex::Regex; use sha1::Sha1; -use std::borrow::Cow; -use std::io::Read; -use std::path::{Path, PathBuf}; -use std::{fs, io, time}; use unicode_normalization::{is_nfc, UnicodeNormalization}; +use crate::{ + error::{AnkiError, Result}, + log::{debug, Logger}, +}; + /// The maximum length we allow a filename to be. When combined /// with the rest of the path, the full path needs to be under ~240 chars /// on some platforms, and some filesystems like eCryptFS will increase @@ -426,12 +433,14 @@ pub(super) fn data_for_file(media_folder: &Path, fname: &str) -> Result( #[cfg(test)] mod test { - use crate::error::Result; - use crate::media::sync::{ - determine_required_change, LocalState, MediaSyncProgress, RequiredChange, - }; - use crate::media::MediaManager; use tempfile::tempdir; use tokio::runtime::Runtime; + use crate::{ + error::Result, + media::{ + sync::{determine_required_change, LocalState, MediaSyncProgress, RequiredChange}, + MediaManager, + }, + }; + async fn test_sync(hkey: &str) -> Result<()> { let dir = tempdir()?; let media_dir = dir.path().join("media"); diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index 14074d088..8936597da 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -3,28 +3,29 @@ pub(crate) mod undo; +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, + convert::TryInto, +}; + +use itertools::Itertools; +use num_integer::Integer; + use crate::{ backend_proto as pb, + backend_proto::note_is_duplicate_or_empty_out::State as DuplicateState, decks::DeckId, define_newtype, error::{AnkiError, Result}, notetype::{CardGenContext, NoteField, Notetype, NotetypeId}, + ops::StateChanges, prelude::*, template::field_is_empty, text::{ensure_string_in_nfc, normalize_to_nfc, strip_html_preserving_media_filenames}, timestamp::TimestampSecs, types::Usn, }; -use crate::{ - backend_proto::note_is_duplicate_or_empty_out::State as DuplicateState, ops::StateChanges, -}; -use itertools::Itertools; -use num_integer::Integer; -use std::{ - borrow::Cow, - collections::{HashMap, HashSet}, - convert::TryInto, -}; define_newtype!(NoteId, i64); diff --git a/rslib/src/notes/undo.rs b/rslib/src/notes/undo.rs index 0bea9912f..46901a7a8 100644 --- a/rslib/src/notes/undo.rs +++ b/rslib/src/notes/undo.rs @@ -1,9 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{prelude::*, undo::UndoableChange}; - use super::NoteTags; +use crate::{prelude::*, undo::UndoableChange}; #[derive(Debug)] pub(crate) enum UndoableNoteChange { diff --git a/rslib/src/notetype/cardgen.rs b/rslib/src/notetype/cardgen.rs index 717d807ab..8292462d6 100644 --- a/rslib/src/notetype/cardgen.rs +++ b/rslib/src/notetype/cardgen.rs @@ -1,6 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::{HashMap, HashSet}; + +use itertools::Itertools; +use rand::{rngs::StdRng, Rng, SeedableRng}; + use super::Notetype; use crate::{ card::{Card, CardId}, @@ -14,9 +19,6 @@ use crate::{ template::ParsedTemplate, types::Usn, }; -use itertools::Itertools; -use rand::{rngs::StdRng, Rng, SeedableRng}; -use std::collections::{HashMap, HashSet}; /// Info about an existing card required when generating new cards #[derive(Debug, PartialEq)] diff --git a/rslib/src/notetype/emptycards.rs b/rslib/src/notetype/emptycards.rs index e2b6067c9..228147e0b 100644 --- a/rslib/src/notetype/emptycards.rs +++ b/rslib/src/notetype/emptycards.rs @@ -1,12 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{collections::HashSet, fmt::Write}; + use super::{ cardgen::group_generated_cards_by_note, CardGenContext, Notetype, NotetypeId, NotetypeKind, }; use crate::{card::CardId, collection::Collection, error::Result, notes::NoteId}; -use std::collections::HashSet; -use std::fmt::Write; pub struct EmptyCardsForNote { pub nid: NoteId, diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index 6bfdc7045..16b48c50e 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -10,24 +10,30 @@ mod schemachange; mod stock; mod templates; -pub use crate::backend_proto::{ - notetype::{ - config::card_requirement::Kind as CardRequirementKind, - config::CardRequirement, - config::Kind as NotetypeKind, - template::Config as CardTemplateConfig, - Config as NotetypeConfig, Template as CardTemplateProto, - {field::Config as NoteFieldConfig, Field as NoteFieldProto}, - }, - Notetype as NotetypeProto, +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, }; + pub(crate) use cardgen::{AlreadyGeneratedCardInfo, CardGenContext}; pub use fields::NoteField; pub(crate) use render::RenderCardOutput; pub use schema11::{CardTemplateSchema11, NoteFieldSchema11, NotetypeSchema11}; pub use stock::all_stock_notetypes; pub use templates::CardTemplate; +use unicase::UniCase; +pub use crate::backend_proto::{ + notetype::{ + config::{ + card_requirement::Kind as CardRequirementKind, CardRequirement, Kind as NotetypeKind, + }, + field::Config as NoteFieldConfig, + template::Config as CardTemplateConfig, + Config as NotetypeConfig, Field as NoteFieldProto, Template as CardTemplateProto, + }, + Notetype as NotetypeProto, +}; use crate::{ collection::Collection, decks::DeckId, @@ -40,11 +46,6 @@ use crate::{ timestamp::TimestampSecs, types::Usn, }; -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, -}; -use unicase::UniCase; define_newtype!(NotetypeId, i64); diff --git a/rslib/src/notetype/render.rs b/rslib/src/notetype/render.rs index de6111a23..3b94d66e1 100644 --- a/rslib/src/notetype/render.rs +++ b/rslib/src/notetype/render.rs @@ -1,6 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{borrow::Cow, collections::HashMap}; + use super::{CardTemplate, Notetype, NotetypeKind}; use crate::{ card::{Card, CardId}, @@ -10,7 +12,6 @@ use crate::{ notes::{Note, NoteId}, template::{field_is_empty, render_card, ParsedTemplate, RenderedNode}, }; -use std::{borrow::Cow, collections::HashMap}; pub struct RenderCardOutput { pub qnodes: Vec, diff --git a/rslib/src/notetype/schema11.rs b/rslib/src/notetype/schema11.rs index a937413eb..f708bd31a 100644 --- a/rslib/src/notetype/schema11.rs +++ b/rslib/src/notetype/schema11.rs @@ -1,6 +1,14 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::HashMap; + +use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; +use serde_repr::{Deserialize_repr, Serialize_repr}; +use serde_tuple::Serialize_tuple; + +use super::{CardRequirementKind, NotetypeId}; use crate::{ decks::DeckId, notetype::{ @@ -11,13 +19,6 @@ use crate::{ timestamp::TimestampSecs, types::Usn, }; -use serde_derive::{Deserialize, Serialize}; -use serde_json::Value; -use serde_repr::{Deserialize_repr, Serialize_repr}; -use serde_tuple::Serialize_tuple; -use std::collections::HashMap; - -use super::{CardRequirementKind, NotetypeId}; #[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)] #[repr(u8)] diff --git a/rslib/src/notetype/stock.rs b/rslib/src/notetype/stock.rs index 6c3a9a2f4..0d8cf6d3e 100644 --- a/rslib/src/notetype/stock.rs +++ b/rslib/src/notetype/stock.rs @@ -3,6 +3,7 @@ use super::NotetypeKind; use crate::{ + backend_proto::stock_notetype::Kind, config::{ConfigEntry, ConfigKey}, error::Result, i18n::I18n, @@ -11,8 +12,6 @@ use crate::{ timestamp::TimestampSecs, }; -use crate::backend_proto::stock_notetype::Kind; - impl SqliteStorage { pub(crate) fn add_stock_notetypes(&self, tr: &I18n) -> Result<()> { for (idx, mut nt) in all_stock_notetypes(tr).into_iter().enumerate() { diff --git a/rslib/src/preferences.rs b/rslib/src/preferences.rs index b7f690086..fb7257f3b 100644 --- a/rslib/src/preferences.rs +++ b/rslib/src/preferences.rs @@ -3,8 +3,7 @@ use crate::{ backend_proto::{ - preferences::scheduling::NewReviewMix as NewRevMixPB, - preferences::{Editing, Reviewing, Scheduling}, + preferences::{scheduling::NewReviewMix as NewRevMixPB, Editing, Reviewing, Scheduling}, Preferences, }, collection::Collection, diff --git a/rslib/src/prelude.rs b/rslib/src/prelude.rs index 53acf131b..306e565f1 100644 --- a/rslib/src/prelude.rs +++ b/rslib/src/prelude.rs @@ -1,6 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +pub use slog::{debug, Logger}; + pub(crate) use crate::types::IntoNewtypeVec; pub use crate::{ card::{Card, CardId}, @@ -17,4 +19,3 @@ pub use crate::{ timestamp::{TimestampMillis, TimestampSecs}, types::Usn, }; -pub use slog::{debug, Logger}; diff --git a/rslib/src/revlog/mod.rs b/rslib/src/revlog/mod.rs index 170e8ac7e..13b1d00d3 100644 --- a/rslib/src/revlog/mod.rs +++ b/rslib/src/revlog/mod.rs @@ -3,13 +3,17 @@ pub(crate) mod undo; -use crate::serde::{default_on_invalid, deserialize_int_from_number}; -use crate::{define_newtype, prelude::*}; use num_enum::TryFromPrimitive; use serde::Deserialize; use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_tuple::Serialize_tuple; +use crate::{ + define_newtype, + prelude::*, + serde::{default_on_invalid, deserialize_int_from_number}, +}; + define_newtype!(RevlogId, i64); impl RevlogId { diff --git a/rslib/src/scheduler/answering/current.rs b/rslib/src/scheduler/answering/current.rs index ff2d3bf46..9db8601f8 100644 --- a/rslib/src/scheduler/answering/current.rs +++ b/rslib/src/scheduler/answering/current.rs @@ -1,6 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use super::CardStateUpdater; use crate::{ card::CardType, decks::DeckKind, @@ -10,8 +11,6 @@ use crate::{ }, }; -use super::CardStateUpdater; - impl CardStateUpdater { pub(crate) fn current_card_state(&self) -> CardState { let due = match &self.deck.kind { diff --git a/rslib/src/scheduler/answering/learning.rs b/rslib/src/scheduler/answering/learning.rs index 992c23d66..d22ca6add 100644 --- a/rslib/src/scheduler/answering/learning.rs +++ b/rslib/src/scheduler/answering/learning.rs @@ -1,14 +1,13 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use super::{CardStateUpdater, RevlogEntryPartial}; use crate::{ card::{CardQueue, CardType}, prelude::*, scheduler::states::{CardState, IntervalKind, LearnState, NewState}, }; -use super::{CardStateUpdater, RevlogEntryPartial}; - impl CardStateUpdater { pub(super) fn apply_new_state( &mut self, diff --git a/rslib/src/scheduler/answering/mod.rs b/rslib/src/scheduler/answering/mod.rs index c6ea0acd8..3ddba4224 100644 --- a/rslib/src/scheduler/answering/mod.rs +++ b/rslib/src/scheduler/answering/mod.rs @@ -9,14 +9,6 @@ mod review; mod revlog; mod undo; -use crate::{ - backend_proto, - card::CardQueue, - deckconf::{DeckConf, LeechAction}, - decks::Deck, - prelude::*, -}; - use revlog::RevlogEntryPartial; use super::{ @@ -26,6 +18,13 @@ use super::{ timespan::answer_button_time_collapsible, timing::SchedTimingToday, }; +use crate::{ + backend_proto, + card::CardQueue, + deckconf::{DeckConf, LeechAction}, + decks::Deck, + prelude::*, +}; #[derive(Copy, Clone)] pub enum Rating { diff --git a/rslib/src/scheduler/answering/preview.rs b/rslib/src/scheduler/answering/preview.rs index abc42d40f..0e8d4bdb9 100644 --- a/rslib/src/scheduler/answering/preview.rs +++ b/rslib/src/scheduler/answering/preview.rs @@ -1,14 +1,13 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use super::{CardStateUpdater, RevlogEntryPartial}; use crate::{ card::CardQueue, config::SchedulerVersion, scheduler::states::{CardState, IntervalKind, PreviewState}, }; -use super::{CardStateUpdater, RevlogEntryPartial}; - impl CardStateUpdater { // fixme: check learning card moved into preview // restores correctly in both learn and day-learn case @@ -41,12 +40,11 @@ impl CardStateUpdater { #[cfg(test)] mod test { - use crate::collection::open_test_collection; - use crate::prelude::*; - use super::*; use crate::{ card::CardType, + collection::open_test_collection, + prelude::*, scheduler::{ answering::{CardAnswer, Rating}, states::{CardState, FilteredState}, diff --git a/rslib/src/scheduler/answering/relearning.rs b/rslib/src/scheduler/answering/relearning.rs index abc5d4d86..cbb2bf7a8 100644 --- a/rslib/src/scheduler/answering/relearning.rs +++ b/rslib/src/scheduler/answering/relearning.rs @@ -1,14 +1,13 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use super::{CardStateUpdater, RevlogEntryPartial}; use crate::{ card::{CardQueue, CardType}, prelude::*, scheduler::states::{CardState, IntervalKind, RelearnState}, }; -use super::{CardStateUpdater, RevlogEntryPartial}; - impl CardStateUpdater { pub(super) fn apply_relearning_state( &mut self, diff --git a/rslib/src/scheduler/answering/review.rs b/rslib/src/scheduler/answering/review.rs index 38ad90b9d..418a7988e 100644 --- a/rslib/src/scheduler/answering/review.rs +++ b/rslib/src/scheduler/answering/review.rs @@ -1,13 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use super::{CardStateUpdater, RevlogEntryPartial}; use crate::{ card::{CardQueue, CardType}, scheduler::states::{CardState, ReviewState}, }; -use super::{CardStateUpdater, RevlogEntryPartial}; - impl CardStateUpdater { pub(super) fn apply_review_state( &mut self, diff --git a/rslib/src/scheduler/bury_and_suspend.rs b/rslib/src/scheduler/bury_and_suspend.rs index 31a3771da..7f5ef8888 100644 --- a/rslib/src/scheduler/bury_and_suspend.rs +++ b/rslib/src/scheduler/bury_and_suspend.rs @@ -1,8 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use super::timing::SchedTimingToday; use crate::{ - backend_proto as pb, + backend_proto::{ + bury_or_suspend_cards_in::Mode as BuryOrSuspendMode, + unbury_cards_in_current_deck_in::Mode as UnburyDeckMode, + }, card::{Card, CardId, CardQueue}, collection::Collection, config::SchedulerVersion, @@ -11,12 +15,6 @@ use crate::{ search::SortMode, }; -use super::timing::SchedTimingToday; -use pb::{ - bury_or_suspend_cards_in::Mode as BuryOrSuspendMode, - unbury_cards_in_current_deck_in::Mode as UnburyDeckMode, -}; - impl Card { /// True if card was buried/suspended prior to the call. pub(crate) fn restore_queue_after_bury_or_suspend(&mut self) -> bool { diff --git a/rslib/src/scheduler/congrats.rs b/rslib/src/scheduler/congrats.rs index 543337316..9b4532c69 100644 --- a/rslib/src/scheduler/congrats.rs +++ b/rslib/src/scheduler/congrats.rs @@ -1,8 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::backend_proto as pb; -use crate::prelude::*; +use crate::{backend_proto as pb, prelude::*}; #[derive(Debug)] pub(crate) struct CongratsInfo { diff --git a/rslib/src/scheduler/filtered/card.rs b/rslib/src/scheduler/filtered/card.rs index 0fb5caeea..71a42f287 100644 --- a/rslib/src/scheduler/filtered/card.rs +++ b/rslib/src/scheduler/filtered/card.rs @@ -1,14 +1,13 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use super::DeckFilterContext; use crate::{ card::{CardQueue, CardType}, config::SchedulerVersion, prelude::*, }; -use super::DeckFilterContext; - impl Card { pub(crate) fn restore_queue_from_type(&mut self) { self.queue = match self.ctype { diff --git a/rslib/src/scheduler/filtered/mod.rs b/rslib/src/scheduler/filtered/mod.rs index e39e1a25a..307423c79 100644 --- a/rslib/src/scheduler/filtered/mod.rs +++ b/rslib/src/scheduler/filtered/mod.rs @@ -6,13 +6,14 @@ mod card; use std::convert::{TryFrom, TryInto}; use crate::{ - config::ConfigKey, + config::{ConfigKey, SchedulerVersion}, decks::{FilteredDeck, FilteredSearchTerm}, error::FilteredDeckError, - search::writer::{deck_search, normalize_search}, -}; -use crate::{ - config::SchedulerVersion, prelude::*, search::SortMode, + prelude::*, + search::{ + writer::{deck_search, normalize_search}, + SortMode, + }, storage::card::filtered::order_and_limit_for_search, }; diff --git a/rslib/src/scheduler/new.rs b/rslib/src/scheduler/new.rs index 70a61ba1d..7c8223195 100644 --- a/rslib/src/scheduler/new.rs +++ b/rslib/src/scheduler/new.rs @@ -1,6 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::{HashMap, HashSet}; + +use rand::seq::SliceRandom; + use crate::{ card::{Card, CardId, CardQueue, CardType}, collection::Collection, @@ -11,8 +15,6 @@ use crate::{ search::SortMode, types::Usn, }; -use rand::seq::SliceRandom; -use std::collections::{HashMap, HashSet}; impl Card { fn schedule_as_new(&mut self, position: u32) { diff --git a/rslib/src/scheduler/queue/builder/mod.rs b/rslib/src/scheduler/queue/builder/mod.rs index 396479ae8..135ee962e 100644 --- a/rslib/src/scheduler/queue/builder/mod.rs +++ b/rslib/src/scheduler/queue/builder/mod.rs @@ -11,13 +11,17 @@ use std::{ collections::{BinaryHeap, HashSet, VecDeque}, }; +use intersperser::Intersperser; +use sized_chain::SizedChain; + use super::{ limits::{remaining_limits_capped_to_parents, RemainingLimits}, CardQueues, Counts, LearningQueueEntry, MainQueueEntry, MainQueueEntryKind, }; -use crate::deckconf::{NewCardOrder, ReviewCardOrder, ReviewMix}; -use crate::prelude::*; -use {intersperser::Intersperser, sized_chain::SizedChain}; +use crate::{ + deckconf::{NewCardOrder, ReviewCardOrder, ReviewMix}, + prelude::*, +}; /// Temporary holder for review cards that will be built into a queue. #[derive(Debug, Default, Clone)] diff --git a/rslib/src/scheduler/queue/builder/sorting.rs b/rslib/src/scheduler/queue/builder/sorting.rs index 2ba28c54a..868545015 100644 --- a/rslib/src/scheduler/queue/builder/sorting.rs +++ b/rslib/src/scheduler/queue/builder/sorting.rs @@ -1,10 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::{DueCard, NewCard, NewCardOrder, QueueBuilder, ReviewCardOrder}; -use fnv::FnvHasher; use std::{cmp::Ordering, hash::Hasher}; +use fnv::FnvHasher; + +use super::{DueCard, NewCard, NewCardOrder, QueueBuilder, ReviewCardOrder}; + impl QueueBuilder { pub(super) fn sort_new(&mut self) { match self.new_order { diff --git a/rslib/src/scheduler/queue/entry.rs b/rslib/src/scheduler/queue/entry.rs index e33a73ebf..a17350166 100644 --- a/rslib/src/scheduler/queue/entry.rs +++ b/rslib/src/scheduler/queue/entry.rs @@ -2,8 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::{LearningQueueEntry, MainQueueEntry, MainQueueEntryKind}; -use crate::card::CardQueue; -use crate::prelude::*; +use crate::{card::CardQueue, prelude::*}; #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) enum QueueEntry { diff --git a/rslib/src/scheduler/queue/limits.rs b/rslib/src/scheduler/queue/limits.rs index d80322517..aa9d01ce4 100644 --- a/rslib/src/scheduler/queue/limits.rs +++ b/rslib/src/scheduler/queue/limits.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::HashMap; + use super::{Deck, DeckKind}; use crate::deckconf::{DeckConf, DeckConfId}; -use std::collections::HashMap; #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct RemainingLimits { diff --git a/rslib/src/scheduler/queue/mod.rs b/rslib/src/scheduler/queue/mod.rs index f45fa8a3a..f9294700c 100644 --- a/rslib/src/scheduler/queue/mod.rs +++ b/rslib/src/scheduler/queue/mod.rs @@ -13,17 +13,14 @@ use std::{ collections::{BinaryHeap, VecDeque}, }; -use crate::{backend_proto as pb, prelude::*, timestamp::TimestampSecs}; pub(crate) use builder::{DueCard, NewCard}; -pub(crate) use { - entry::{QueueEntry, QueueEntryKind}, - learning::LearningQueueEntry, - main::{MainQueueEntry, MainQueueEntryKind}, -}; +pub(crate) use entry::{QueueEntry, QueueEntryKind}; +pub(crate) use learning::LearningQueueEntry; +pub(crate) use main::{MainQueueEntry, MainQueueEntryKind}; use self::undo::QueueUpdate; - use super::{states::NextCardStates, timing::SchedTimingToday}; +use crate::{backend_proto as pb, prelude::*, timestamp::TimestampSecs}; #[derive(Debug)] pub(crate) struct CardQueues { diff --git a/rslib/src/scheduler/reviews.rs b/rslib/src/scheduler/reviews.rs index 9fdd69095..7e4e06c23 100644 --- a/rslib/src/scheduler/reviews.rs +++ b/rslib/src/scheduler/reviews.rs @@ -1,6 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use lazy_static::lazy_static; +use rand::distributions::{Distribution, Uniform}; +use regex::Regex; + use crate::{ card::{Card, CardId, CardQueue, CardType}, collection::Collection, @@ -9,9 +13,6 @@ use crate::{ error::Result, prelude::*, }; -use lazy_static::lazy_static; -use rand::distributions::{Distribution, Uniform}; -use regex::Regex; impl Card { /// Make card due in `days_from_today`. diff --git a/rslib/src/scheduler/states/filtered.rs b/rslib/src/scheduler/states/filtered.rs index b0de406a9..0905d5738 100644 --- a/rslib/src/scheduler/states/filtered.rs +++ b/rslib/src/scheduler/states/filtered.rs @@ -1,11 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::revlog::RevlogReviewKind; - use super::{ IntervalKind, NextCardStates, PreviewState, ReschedulingFilterState, ReviewState, StateContext, }; +use crate::revlog::RevlogReviewKind; #[derive(Debug, Clone, Copy, PartialEq)] pub enum FilteredState { diff --git a/rslib/src/scheduler/states/learning.rs b/rslib/src/scheduler/states/learning.rs index e142dad4f..621b3024c 100644 --- a/rslib/src/scheduler/states/learning.rs +++ b/rslib/src/scheduler/states/learning.rs @@ -1,9 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::revlog::RevlogReviewKind; - use super::{interval_kind::IntervalKind, CardState, NextCardStates, ReviewState, StateContext}; +use crate::revlog::RevlogReviewKind; #[derive(Debug, Clone, Copy, PartialEq)] pub struct LearnState { diff --git a/rslib/src/scheduler/states/mod.rs b/rslib/src/scheduler/states/mod.rs index 9012c65f5..27844c434 100644 --- a/rslib/src/scheduler/states/mod.rs +++ b/rslib/src/scheduler/states/mod.rs @@ -12,20 +12,19 @@ pub(crate) mod rescheduling_filter; pub(crate) mod review; pub(crate) mod steps; -use rand::prelude::*; -use rand::rngs::StdRng; - -pub use { - filtered::FilteredState, learning::LearnState, new::NewState, normal::NormalState, - preview_filter::PreviewState, relearning::RelearnState, - rescheduling_filter::ReschedulingFilterState, review::ReviewState, -}; - +pub use filtered::FilteredState; pub(crate) use interval_kind::IntervalKind; - -use crate::revlog::RevlogReviewKind; +pub use learning::LearnState; +pub use new::NewState; +pub use normal::NormalState; +pub use preview_filter::PreviewState; +use rand::{prelude::*, rngs::StdRng}; +pub use relearning::RelearnState; +pub use rescheduling_filter::ReschedulingFilterState; +pub use review::ReviewState; use self::steps::LearningSteps; +use crate::revlog::RevlogReviewKind; #[derive(Debug, Clone, Copy, PartialEq)] pub enum CardState { diff --git a/rslib/src/scheduler/states/new.rs b/rslib/src/scheduler/states/new.rs index f67b55aa4..e4d043885 100644 --- a/rslib/src/scheduler/states/new.rs +++ b/rslib/src/scheduler/states/new.rs @@ -1,9 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::revlog::RevlogReviewKind; - use super::interval_kind::IntervalKind; +use crate::revlog::RevlogReviewKind; #[derive(Debug, Clone, Copy, PartialEq, Default)] pub struct NewState { diff --git a/rslib/src/scheduler/states/normal.rs b/rslib/src/scheduler/states/normal.rs index 25c47cb81..7043b24dc 100644 --- a/rslib/src/scheduler/states/normal.rs +++ b/rslib/src/scheduler/states/normal.rs @@ -1,12 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::revlog::RevlogReviewKind; - use super::{ interval_kind::IntervalKind, LearnState, NewState, NextCardStates, RelearnState, ReviewState, StateContext, }; +use crate::revlog::RevlogReviewKind; #[derive(Debug, Clone, Copy, PartialEq)] pub enum NormalState { diff --git a/rslib/src/scheduler/states/relearning.rs b/rslib/src/scheduler/states/relearning.rs index ae635ed51..017b4612c 100644 --- a/rslib/src/scheduler/states/relearning.rs +++ b/rslib/src/scheduler/states/relearning.rs @@ -1,11 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::revlog::RevlogReviewKind; - use super::{ interval_kind::IntervalKind, CardState, LearnState, NextCardStates, ReviewState, StateContext, }; +use crate::revlog::RevlogReviewKind; #[derive(Debug, Clone, Copy, PartialEq)] pub struct RelearnState { diff --git a/rslib/src/scheduler/states/rescheduling_filter.rs b/rslib/src/scheduler/states/rescheduling_filter.rs index 2aa110a71..1993031c4 100644 --- a/rslib/src/scheduler/states/rescheduling_filter.rs +++ b/rslib/src/scheduler/states/rescheduling_filter.rs @@ -1,11 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::revlog::RevlogReviewKind; - use super::{ interval_kind::IntervalKind, normal::NormalState, CardState, NextCardStates, StateContext, }; +use crate::revlog::RevlogReviewKind; #[derive(Debug, Clone, Copy, PartialEq)] pub struct ReschedulingFilterState { diff --git a/rslib/src/scheduler/states/review.rs b/rslib/src/scheduler/states/review.rs index 526ca6a3b..a5fdfe14b 100644 --- a/rslib/src/scheduler/states/review.rs +++ b/rslib/src/scheduler/states/review.rs @@ -1,11 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::revlog::RevlogReviewKind; - use super::{ interval_kind::IntervalKind, CardState, LearnState, NextCardStates, RelearnState, StateContext, }; +use crate::revlog::RevlogReviewKind; pub const INITIAL_EASE_FACTOR: f32 = 2.5; pub const MINIMUM_EASE_FACTOR: f32 = 1.3; diff --git a/rslib/src/scheduler/timespan.rs b/rslib/src/scheduler/timespan.rs index 1088fcc87..84989875d 100644 --- a/rslib/src/scheduler/timespan.rs +++ b/rslib/src/scheduler/timespan.rs @@ -166,8 +166,10 @@ impl Timespan { #[cfg(test)] mod test { - use crate::i18n::I18n; - use crate::scheduler::timespan::{answer_button_time, time_span, MONTH}; + use crate::{ + i18n::I18n, + scheduler::timespan::{answer_button_time, time_span, MONTH}, + }; #[test] fn answer_buttons() { diff --git a/rslib/src/scheduler/timing.rs b/rslib/src/scheduler/timing.rs index 6e5c154ba..f89133332 100644 --- a/rslib/src/scheduler/timing.rs +++ b/rslib/src/scheduler/timing.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::prelude::*; use chrono::{Date, Duration, FixedOffset, Local, TimeZone, Timelike}; +use crate::prelude::*; + #[derive(Debug, PartialEq, Clone, Copy)] pub struct SchedTimingToday { pub now: TimestampSecs, @@ -192,9 +193,10 @@ pub(crate) fn sched_timing_today( #[cfg(test)] mod test { - use super::*; use chrono::{FixedOffset, Local, TimeZone, Utc}; + use super::*; + // static timezone for tests const AEST_MINS_WEST: i32 = -600; diff --git a/rslib/src/scheduler/upgrade.rs b/rslib/src/scheduler/upgrade.rs index b9ae06de6..ae384d854 100644 --- a/rslib/src/scheduler/upgrade.rs +++ b/rslib/src/scheduler/upgrade.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; +use super::timing::local_minutes_west_for_stamp; use crate::{ card::{CardQueue, CardType}, config::SchedulerVersion, @@ -10,8 +11,6 @@ use crate::{ search::SortMode, }; -use super::timing::local_minutes_west_for_stamp; - struct V1FilteredDeckInfo { /// True if the filtered deck had rescheduling enabled. reschedule: bool, diff --git a/rslib/src/search/mod.rs b/rslib/src/search/mod.rs index 367ad6da1..d24b424d8 100644 --- a/rslib/src/search/mod.rs +++ b/rslib/src/search/mod.rs @@ -5,19 +5,24 @@ mod parser; mod sqlwriter; pub(crate) mod writer; +use std::borrow::Cow; + pub use parser::{ parse as parse_search, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind, }; +use rusqlite::types::FromSql; +use sqlwriter::{RequiredTable, SqlWriter}; pub use writer::{concatenate_searches, replace_search_node, write_nodes, BoolSeparator}; -use rusqlite::types::FromSql; -use std::borrow::Cow; - use crate::{ - browser_table::Column, card::CardId, card::CardType, collection::Collection, error::Result, - notes::NoteId, prelude::AnkiError, search::parser::parse, + browser_table::Column, + card::{CardId, CardType}, + collection::Collection, + error::Result, + notes::NoteId, + prelude::AnkiError, + search::parser::parse, }; -use sqlwriter::{RequiredTable, SqlWriter}; #[derive(Debug, PartialEq, Clone, Copy)] pub enum ReturnItemType { diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 9317c450d..a3465ede8 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -1,11 +1,6 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{ - decks::DeckId, - error::{ParseError, Result, SearchErrorKind as FailKind}, - notetype::NotetypeId, -}; use lazy_static::lazy_static; use nom::{ branch::alt, @@ -18,6 +13,12 @@ use nom::{ }; use regex::{Captures, Regex}; +use crate::{ + decks::DeckId, + error::{ParseError, Result, SearchErrorKind as FailKind}, + notetype::NotetypeId, +}; + type IResult<'a, O> = std::result::Result<(&'a str, O), nom::Err>>; type ParseResult<'a, O> = std::result::Result>>; @@ -696,9 +697,8 @@ fn is_parser_escape(txt: &str) -> bool { #[cfg(test)] mod test { - use crate::error::SearchErrorKind; - use super::*; + use crate::error::SearchErrorKind; #[test] fn parsing() -> Result<()> { @@ -858,9 +858,10 @@ mod test { #[test] fn errors() { - use crate::error::AnkiError; use FailKind::*; + use crate::error::AnkiError; + fn assert_err_kind(input: &str, kind: FailKind) { assert_eq!(parse(input), Err(AnkiError::SearchError(kind))); } diff --git a/rslib/src/search/sqlwriter.rs b/rslib/src/search/sqlwriter.rs index 793b504aa..fc4253b97 100644 --- a/rslib/src/search/sqlwriter.rs +++ b/rslib/src/search/sqlwriter.rs @@ -1,6 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{borrow::Cow, fmt::Write}; + use super::{ parser::{Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind}, ReturnItemType, @@ -19,7 +21,6 @@ use crate::{ }, timestamp::TimestampSecs, }; -use std::{borrow::Cow, fmt::Write}; pub(crate) struct SqlWriter<'a> { col: &'a mut Collection, @@ -575,16 +576,16 @@ impl SearchNode { #[cfg(test)] mod test { - use super::*; + use std::{fs, path::PathBuf}; + + use tempfile::tempdir; + + use super::{super::parser::parse, *}; use crate::{ collection::{open_collection, Collection}, i18n::I18n, log, }; - use std::{fs, path::PathBuf}; - use tempfile::tempdir; - - use super::super::parser::parse; // shortcut fn s(req: &mut Collection, search: &str) -> (String, Vec) { diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index f96823830..faefd9337 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -1,6 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::mem; + use crate::{ decks::DeckId as DeckIdType, notetype::NotetypeId as NotetypeIdType, @@ -8,7 +10,6 @@ use crate::{ search::parser::{parse, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind}, text::escape_anki_wildcards, }; -use std::mem; #[derive(Debug, PartialEq)] pub enum BoolSeparator { @@ -191,8 +192,7 @@ pub(crate) fn normalize_search(input: &str) -> Result { #[cfg(test)] mod test { use super::*; - use crate::error::Result; - use crate::search::parse_search as parse; + use crate::{error::Result, search::parse_search as parse}; #[test] fn normalizing() { diff --git a/rslib/src/serde.rs b/rslib/src/serde.rs index 6f61627ee..0d1623eb7 100644 --- a/rslib/src/serde.rs +++ b/rslib/src/serde.rs @@ -1,13 +1,14 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::timestamp::TimestampSecs; use serde::{Deserialize as DeTrait, Deserializer}; pub(crate) use serde_aux::field_attributes::{ deserialize_bool_from_anything, deserialize_number_from_string, }; use serde_json::Value; +use crate::timestamp::TimestampSecs; + /// Note: if you wish to cover the case where a field is missing, make sure you also /// use the `serde(default)` flag. pub(crate) fn default_on_invalid<'de, T, D>(deserializer: D) -> Result @@ -68,9 +69,10 @@ impl FromI64 for TimestampSecs { #[cfg(test)] mod test { - use super::*; use serde::Deserialize; + use super::*; + #[derive(Deserialize, Debug, PartialEq)] struct MaybeInvalid { #[serde(deserialize_with = "default_on_invalid", default)] diff --git a/rslib/src/stats/card.rs b/rslib/src/stats/card.rs index 7d66f3a0a..527d1b69d 100644 --- a/rslib/src/stats/card.rs +++ b/rslib/src/stats/card.rs @@ -1,6 +1,9 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use askama::Template; +use chrono::prelude::*; + use crate::{ card::CardQueue, i18n::I18n, @@ -8,8 +11,6 @@ use crate::{ revlog::{RevlogEntry, RevlogReviewKind}, scheduler::timespan::time_span, }; -use askama::Template; -use chrono::prelude::*; struct CardStats { added: TimestampSecs, diff --git a/rslib/src/storage/card/mod.rs b/rslib/src/storage/card/mod.rs index a700f7c5b..cc9d44bba 100644 --- a/rslib/src/storage/card/mod.rs +++ b/rslib/src/storage/card/mod.rs @@ -3,6 +3,15 @@ pub(crate) mod filtered; +use std::{collections::HashSet, convert::TryFrom, result}; + +use rusqlite::{ + named_params, params, + types::{FromSql, FromSqlError, ValueRef}, + OptionalExtension, Row, NO_PARAMS, +}; + +use super::ids_to_string; use crate::{ card::{Card, CardId, CardQueue, CardType}, deckconf::DeckConfId, @@ -16,15 +25,6 @@ use crate::{ timestamp::{TimestampMillis, TimestampSecs}, types::Usn, }; -use rusqlite::params; -use rusqlite::{ - named_params, - types::{FromSql, FromSqlError, ValueRef}, - OptionalExtension, Row, NO_PARAMS, -}; -use std::{collections::HashSet, convert::TryFrom, result}; - -use super::ids_to_string; impl FromSql for CardType { fn column_result(value: ValueRef<'_>) -> std::result::Result { @@ -515,9 +515,10 @@ impl super::SqliteStorage { #[cfg(test)] mod test { - use crate::{card::Card, i18n::I18n, storage::SqliteStorage}; use std::path::Path; + use crate::{card::Card, i18n::I18n, storage::SqliteStorage}; + #[test] fn add_card() { let tr = I18n::template_only(); diff --git a/rslib/src/storage/collection_timestamps.rs b/rslib/src/storage/collection_timestamps.rs index 5949bcb8c..68c1d8f18 100644 --- a/rslib/src/storage/collection_timestamps.rs +++ b/rslib/src/storage/collection_timestamps.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use rusqlite::{params, NO_PARAMS}; + use super::SqliteStorage; use crate::{collection::timestamps::CollectionTimestamps, prelude::*}; -use rusqlite::{params, NO_PARAMS}; impl SqliteStorage { pub(crate) fn get_collection_timestamps(&self) -> Result { diff --git a/rslib/src/storage/config/mod.rs b/rslib/src/storage/config/mod.rs index 6fad527e7..2dc75e327 100644 --- a/rslib/src/storage/config/mod.rs +++ b/rslib/src/storage/config/mod.rs @@ -1,12 +1,14 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::SqliteStorage; -use crate::{config::ConfigEntry, error::Result, timestamp::TimestampSecs, types::Usn}; +use std::collections::HashMap; + use rusqlite::{params, NO_PARAMS}; use serde::de::DeserializeOwned; use serde_json::Value; -use std::collections::HashMap; + +use super::SqliteStorage; +use crate::{config::ConfigEntry, error::Result, timestamp::TimestampSecs, types::Usn}; impl SqliteStorage { pub(crate) fn set_config_entry(&self, entry: &ConfigEntry) -> Result<()> { diff --git a/rslib/src/storage/deck/mod.rs b/rslib/src/storage/deck/mod.rs index dd27df435..fd26c98b4 100644 --- a/rslib/src/storage/deck/mod.rs +++ b/rslib/src/storage/deck/mod.rs @@ -1,19 +1,20 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::{HashMap, HashSet}; + +use prost::Message; +use rusqlite::{named_params, params, Row, NO_PARAMS}; +use unicase::UniCase; + use super::SqliteStorage; use crate::{ card::CardQueue, config::SchedulerVersion, - decks::immediate_parent_name, - decks::{DeckCommon, DeckKindContainer, DeckSchema11, DueCounts}, + decks::{immediate_parent_name, DeckCommon, DeckKindContainer, DeckSchema11, DueCounts}, error::DbErrorKind, prelude::*, }; -use prost::Message; -use rusqlite::{named_params, params, Row, NO_PARAMS}; -use std::collections::{HashMap, HashSet}; -use unicase::UniCase; fn row_to_deck(row: &Row) -> Result { let common = DeckCommon::decode(row.get_raw(4).as_blob()?)?; diff --git a/rslib/src/storage/deckconf/mod.rs b/rslib/src/storage/deckconf/mod.rs index 19326a5a5..7ba7b3eaf 100644 --- a/rslib/src/storage/deckconf/mod.rs +++ b/rslib/src/storage/deckconf/mod.rs @@ -1,15 +1,17 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::HashMap; + +use prost::Message; +use rusqlite::{params, Row, NO_PARAMS}; +use serde_json::Value; + use super::SqliteStorage; use crate::{ deckconf::{DeckConf, DeckConfId, DeckConfSchema11, DeckConfigInner}, prelude::*, }; -use prost::Message; -use rusqlite::{params, Row, NO_PARAMS}; -use serde_json::Value; -use std::collections::HashMap; fn row_to_deckconf(row: &Row) -> Result { let config = DeckConfigInner::decode(row.get_raw(4).as_blob()?)?; diff --git a/rslib/src/storage/graves/mod.rs b/rslib/src/storage/graves/mod.rs index ee8616562..3fd32fa5d 100644 --- a/rslib/src/storage/graves/mod.rs +++ b/rslib/src/storage/graves/mod.rs @@ -1,6 +1,11 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::convert::TryFrom; + +use num_enum::TryFromPrimitive; +use rusqlite::{params, NO_PARAMS}; + use super::SqliteStorage; use crate::{ card::CardId, @@ -10,9 +15,6 @@ use crate::{ sync::Graves, types::Usn, }; -use num_enum::TryFromPrimitive; -use rusqlite::{params, NO_PARAMS}; -use std::convert::TryFrom; #[derive(TryFromPrimitive)] #[repr(u8)] diff --git a/rslib/src/storage/mod.rs b/rslib/src/storage/mod.rs index 80c902dfb..0ded5336d 100644 --- a/rslib/src/storage/mod.rs +++ b/rslib/src/storage/mod.rs @@ -16,11 +16,11 @@ mod sync_check; mod tag; mod upgrades; +use std::fmt::Write; + pub(crate) use sqlite::SqliteStorage; pub(crate) use sync::open_and_check_sqlite_file; -use std::fmt::Write; - // Write a list of IDs as '(x,y,...)' into the provided string. pub(crate) fn ids_to_string(buf: &mut String, ids: &[T]) where diff --git a/rslib/src/storage/note/mod.rs b/rslib/src/storage/note/mod.rs index 14ce6bf15..6ddb8fc4a 100644 --- a/rslib/src/storage/note/mod.rs +++ b/rslib/src/storage/note/mod.rs @@ -3,6 +3,8 @@ use std::collections::HashSet; +use rusqlite::{params, Row, NO_PARAMS}; + use crate::{ error::Result, notes::{Note, NoteId, NoteTags}, @@ -10,7 +12,6 @@ use crate::{ tags::{join_tags, split_tags}, timestamp::TimestampMillis, }; -use rusqlite::{params, Row, NO_PARAMS}; pub(crate) fn split_fields(fields: &str) -> Vec { fields.split('\x1f').map(Into::into).collect() diff --git a/rslib/src/storage/notetype/mod.rs b/rslib/src/storage/notetype/mod.rs index e341da63e..76a596c6f 100644 --- a/rslib/src/storage/notetype/mod.rs +++ b/rslib/src/storage/notetype/mod.rs @@ -1,21 +1,22 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::{HashMap, HashSet}; + +use prost::Message; +use rusqlite::{params, OptionalExtension, Row, NO_PARAMS}; +use unicase::UniCase; + use super::{ids_to_string, SqliteStorage}; use crate::{ error::{AnkiError, DbErrorKind, Result}, notes::NoteId, notetype::{ AlreadyGeneratedCardInfo, CardTemplate, CardTemplateConfig, NoteField, NoteFieldConfig, - NotetypeConfig, + Notetype, NotetypeConfig, NotetypeId, NotetypeSchema11, }, - notetype::{Notetype, NotetypeId, NotetypeSchema11}, timestamp::TimestampMillis, }; -use prost::Message; -use rusqlite::{params, OptionalExtension, Row, NO_PARAMS}; -use std::collections::{HashMap, HashSet}; -use unicase::UniCase; fn row_to_notetype_core(row: &Row) -> Result { let config = NotetypeConfig::decode(row.get_raw(4).as_blob()?)?; diff --git a/rslib/src/storage/revlog/mod.rs b/rslib/src/storage/revlog/mod.rs index 69495c032..793c289e8 100644 --- a/rslib/src/storage/revlog/mod.rs +++ b/rslib/src/storage/revlog/mod.rs @@ -1,19 +1,21 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::SqliteStorage; -use crate::error::Result; -use crate::{ - backend_proto as pb, - prelude::*, - revlog::{RevlogEntry, RevlogReviewKind}, -}; +use std::convert::TryFrom; + use rusqlite::{ params, types::{FromSql, FromSqlError, ValueRef}, Row, NO_PARAMS, }; -use std::convert::TryFrom; + +use super::SqliteStorage; +use crate::{ + backend_proto as pb, + error::Result, + prelude::*, + revlog::{RevlogEntry, RevlogReviewKind}, +}; pub(crate) struct StudiedToday { pub cards: u32, diff --git a/rslib/src/storage/sqlite.rs b/rslib/src/storage/sqlite.rs index 909b016a7..ff1331718 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -1,18 +1,21 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::config::schema11::schema11_config_as_string; -use crate::error::Result; -use crate::error::{AnkiError, DbErrorKind}; -use crate::timestamp::TimestampMillis; -use crate::{i18n::I18n, scheduler::timing::v1_creation_date, text::without_combining}; +use std::{borrow::Cow, cmp::Ordering, path::Path, sync::Arc}; + use regex::Regex; use rusqlite::{functions::FunctionFlags, params, Connection, NO_PARAMS}; -use std::cmp::Ordering; -use std::{borrow::Cow, path::Path, sync::Arc}; use unicase::UniCase; use super::upgrades::{SCHEMA_MAX_VERSION, SCHEMA_MIN_VERSION, SCHEMA_STARTING_VERSION}; +use crate::{ + config::schema11::schema11_config_as_string, + error::{AnkiError, DbErrorKind, Result}, + i18n::I18n, + scheduler::timing::v1_creation_date, + text::without_combining, + timestamp::TimestampMillis, +}; fn unicase_compare(s1: &str, s2: &str) -> Ordering { UniCase::new(s1).cmp(&UniCase::new(s2)) diff --git a/rslib/src/storage/sync.rs b/rslib/src/storage/sync.rs index 976df1622..5312267b8 100644 --- a/rslib/src/storage/sync.rs +++ b/rslib/src/storage/sync.rs @@ -3,9 +3,10 @@ use std::path::Path; +use rusqlite::{params, types::FromSql, Connection, ToSql, NO_PARAMS}; + use super::*; use crate::prelude::*; -use rusqlite::{params, types::FromSql, Connection, ToSql, NO_PARAMS}; impl SqliteStorage { pub(crate) fn usn(&self, server: bool) -> Result { diff --git a/rslib/src/storage/sync_check.rs b/rslib/src/storage/sync_check.rs index 8a7ebd660..2294e7b91 100644 --- a/rslib/src/storage/sync_check.rs +++ b/rslib/src/storage/sync_check.rs @@ -1,13 +1,14 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use rusqlite::NO_PARAMS; + use super::*; use crate::{ error::SyncErrorKind, prelude::*, sync::{SanityCheckCounts, SanityCheckDueCounts}, }; -use rusqlite::NO_PARAMS; impl SqliteStorage { fn table_has_usn(&self, table: &str) -> Result { diff --git a/rslib/src/storage/tag/mod.rs b/rslib/src/storage/tag/mod.rs index 610057564..1a452c4dd 100644 --- a/rslib/src/storage/tag/mod.rs +++ b/rslib/src/storage/tag/mod.rs @@ -1,11 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::SqliteStorage; -use crate::{error::Result, tags::Tag, types::Usn}; +use std::collections::HashMap; use rusqlite::{params, Row, NO_PARAMS}; -use std::collections::HashMap; + +use super::SqliteStorage; +use crate::{error::Result, tags::Tag, types::Usn}; fn row_to_tag(row: &Row) -> Result { Ok(Tag { diff --git a/rslib/src/sync/http.rs b/rslib/src/sync/http.rs index 7259d5afb..a26bd85fd 100644 --- a/rslib/src/sync/http.rs +++ b/rslib/src/sync/http.rs @@ -3,10 +3,10 @@ use std::{fs, path::PathBuf}; -use super::{Chunk, Graves, SanityCheckCounts, UnchunkedChanges}; -use crate::backend_proto::sync_server_method_in::Method; -use crate::prelude::*; use serde::{Deserialize, Serialize}; + +use super::{Chunk, Graves, SanityCheckCounts, UnchunkedChanges}; +use crate::{backend_proto::sync_server_method_in::Method, prelude::*}; #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub enum SyncRequest { diff --git a/rslib/src/sync/http_client.rs b/rslib/src/sync/http_client.rs index b1d29cca4..ae0a5c963 100644 --- a/rslib/src/sync/http_client.rs +++ b/rslib/src/sync/http_client.rs @@ -1,31 +1,27 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::{server::SyncServer, SYNC_VERSION_MAX}; -use super::{ - Chunk, FullSyncProgress, Graves, SanityCheckCounts, SanityCheckOut, SyncMeta, UnchunkedChanges, -}; -use crate::prelude::*; -use crate::{error::SyncErrorKind, notes::guid, version::sync_client_version}; +use std::{io::prelude::*, path::Path, time::Duration}; + use async_trait::async_trait; use bytes::Bytes; -use flate2::write::GzEncoder; -use flate2::Compression; -use futures::Stream; -use futures::StreamExt; -use reqwest::Body; -use reqwest::{multipart, Client, Response}; +use flate2::{write::GzEncoder, Compression}; +use futures::{Stream, StreamExt}; +use reqwest::{multipart, Body, Client, Response}; use serde::de::DeserializeOwned; - -use super::http::{ - ApplyChangesIn, ApplyChunkIn, ApplyGravesIn, HostKeyIn, HostKeyOut, MetaIn, SanityCheckIn, - StartIn, SyncRequest, -}; -use std::io::prelude::*; -use std::path::Path; -use std::time::Duration; use tempfile::NamedTempFile; +use super::{ + http::{ + ApplyChangesIn, ApplyChunkIn, ApplyGravesIn, HostKeyIn, HostKeyOut, MetaIn, SanityCheckIn, + StartIn, SyncRequest, + }, + server::SyncServer, + Chunk, FullSyncProgress, Graves, SanityCheckCounts, SanityCheckOut, SyncMeta, UnchunkedChanges, + SYNC_VERSION_MAX, +}; +use crate::{error::SyncErrorKind, notes::guid, prelude::*, version::sync_client_version}; + // fixme: 100mb limit pub type FullSyncProgressFn = Box; @@ -288,12 +284,13 @@ impl HttpSyncClient { } } +use std::pin::Pin; + use futures::{ ready, task::{Context, Poll}, }; use pin_project::pin_project; -use std::pin::Pin; use tokio::io::AsyncRead; #[pin_project] @@ -345,12 +342,13 @@ fn sync_endpoint(host_number: u32) -> String { #[cfg(test)] mod test { + use tokio::runtime::Runtime; + use super::*; use crate::{ error::{SyncError, SyncErrorKind}, sync::SanityCheckDueCounts, }; - use tokio::runtime::Runtime; async fn http_client_inner(username: String, password: String) -> Result<()> { let mut syncer = Box::new(HttpSyncClient::new(None, 0)); diff --git a/rslib/src/sync/mod.rs b/rslib/src/sync/mod.rs index b7d405fba..3069ad30d 100644 --- a/rslib/src/sync/mod.rs +++ b/rslib/src/sync/mod.rs @@ -5,13 +5,22 @@ pub mod http; mod http_client; mod server; +use std::collections::HashMap; + +use http_client::HttpSyncClient; +pub use http_client::{FullSyncProgressFn, Timeouts}; +use itertools::Itertools; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use serde_tuple::Serialize_tuple; +pub(crate) use server::{LocalServer, SyncServer}; + use crate::{ backend_proto::{sync_status_out, SyncStatusOut}, card::{Card, CardQueue, CardType}, deckconf::DeckConfSchema11, decks::DeckSchema11, - error::SyncError, - error::SyncErrorKind, + error::{SyncError, SyncErrorKind}, notes::Note, notetype::{Notetype, NotetypeSchema11}, prelude::*, @@ -20,15 +29,6 @@ use crate::{ storage::open_and_check_sqlite_file, tags::{join_tags, split_tags, Tag}, }; -pub use http_client::FullSyncProgressFn; -use http_client::HttpSyncClient; -pub use http_client::Timeouts; -use itertools::Itertools; -use serde::{Deserialize, Serialize}; -use serde_json::Value; -use serde_tuple::Serialize_tuple; -pub(crate) use server::{LocalServer, SyncServer}; -use std::collections::HashMap; pub static SYNC_VERSION_MIN: u8 = 7; pub static SYNC_VERSION_MAX: u8 = 10; @@ -1195,17 +1195,15 @@ mod test { use async_trait::async_trait; use lazy_static::lazy_static; - - use super::server::LocalServer; - use super::*; - use crate::log; - use crate::{ - collection::open_collection, deckconf::DeckConf, decks::DeckKind, i18n::I18n, - notetype::all_stock_notetypes, search::SortMode, - }; use tempfile::{tempdir, TempDir}; use tokio::runtime::Runtime; + use super::{server::LocalServer, *}; + use crate::{ + collection::open_collection, deckconf::DeckConf, decks::DeckKind, i18n::I18n, log, + notetype::all_stock_notetypes, search::SortMode, + }; + fn norm_progress(_: NormalSyncProgress, _: bool) {} fn full_progress(_: FullSyncProgress, _: bool) {} diff --git a/rslib/src/sync/server.rs b/rslib/src/sync/server.rs index c794a31b4..cc38ab226 100644 --- a/rslib/src/sync/server.rs +++ b/rslib/src/sync/server.rs @@ -3,6 +3,10 @@ use std::{fs, path::Path}; +use async_trait::async_trait; +use tempfile::NamedTempFile; + +use super::ChunkableIds; use crate::{ prelude::*, storage::open_and_check_sqlite_file, @@ -11,10 +15,6 @@ use crate::{ UnchunkedChanges, Usn, }, }; -use async_trait::async_trait; -use tempfile::NamedTempFile; - -use super::ChunkableIds; #[async_trait(?Send)] pub trait SyncServer { async fn meta(&self) -> Result; diff --git a/rslib/src/tags/bulkadd.rs b/rslib/src/tags/bulkadd.rs index b208e1dce..320a18ca8 100644 --- a/rslib/src/tags/bulkadd.rs +++ b/rslib/src/tags/bulkadd.rs @@ -4,6 +4,7 @@ //! Adding tags to selected notes in the browse screen. use std::collections::HashSet; + use unicase::UniCase; use super::{join_tags, split_tags}; diff --git a/rslib/src/tags/matcher.rs b/rslib/src/tags/matcher.rs index e093a726e..e74a49f37 100644 --- a/rslib/src/tags/matcher.rs +++ b/rslib/src/tags/matcher.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use regex::{Captures, Regex}; use std::{borrow::Cow, collections::HashSet}; +use regex::{Captures, Regex}; + use super::{join_tags, split_tags}; use crate::prelude::*; pub(crate) struct TagMatcher { diff --git a/rslib/src/tags/register.rs b/rslib/src/tags/register.rs index 7becd2ee3..829bf718b 100644 --- a/rslib/src/tags/register.rs +++ b/rslib/src/tags/register.rs @@ -1,12 +1,13 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{borrow::Cow, collections::HashSet}; + +use unicase::UniCase; + use super::{immediate_parent_name_str, is_tag_separator, split_tags, Tag}; use crate::{prelude::*, text::normalize_to_nfc, types::Usn}; -use std::{borrow::Cow, collections::HashSet}; -use unicase::UniCase; - impl Collection { /// Given a list of tags, fix case, ordering and duplicates. /// Returns true if any new tags were added. diff --git a/rslib/src/tags/remove.rs b/rslib/src/tags/remove.rs index acbfdda01..227533e58 100644 --- a/rslib/src/tags/remove.rs +++ b/rslib/src/tags/remove.rs @@ -96,8 +96,7 @@ impl Collection { #[cfg(test)] mod test { use super::*; - use crate::collection::open_test_collection; - use crate::tags::Tag; + use crate::{collection::open_test_collection, tags::Tag}; #[test] fn clearing() -> Result<()> { diff --git a/rslib/src/template.rs b/rslib/src/template.rs index 5f7359004..719e10df0 100644 --- a/rslib/src/template.rs +++ b/rslib/src/template.rs @@ -1,20 +1,28 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::error::{AnkiError, Result, TemplateError}; -use crate::i18n::I18n; -use crate::{cloze::add_cloze_numbers_in_string, template_filters::apply_filters}; +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, + fmt::Write, + iter, +}; + use lazy_static::lazy_static; -use nom::branch::alt; -use nom::bytes::complete::{tag, take_until}; use nom::{ + branch::alt, + bytes::complete::{tag, take_until}, combinator::{map, rest, verify}, sequence::delimited, }; use regex::Regex; -use std::collections::{HashMap, HashSet}; -use std::fmt::Write; -use std::{borrow::Cow, iter}; + +use crate::{ + cloze::add_cloze_numbers_in_string, + error::{AnkiError, Result, TemplateError}, + i18n::I18n, + template_filters::apply_filters, +}; pub type FieldMap<'a> = HashMap<&'a str, u16>; type TemplateResult = std::result::Result; @@ -792,13 +800,14 @@ fn find_fields_with_filter<'a>( #[cfg(test)] mod test { + use std::collections::HashMap; + use super::{FieldMap, ParsedNode::*, ParsedTemplate as PT}; - use crate::error::TemplateError; use crate::{ + error::TemplateError, i18n::I18n, template::{field_is_empty, nonempty_fields, FieldRequirements, RenderContext}, }; - use std::collections::HashMap; #[test] fn field_empty() { diff --git a/rslib/src/template_filters.rs b/rslib/src/template_filters.rs index 648dd2559..892f70b66 100644 --- a/rslib/src/template_filters.rs +++ b/rslib/src/template_filters.rs @@ -1,13 +1,17 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::cloze::{cloze_filter, cloze_only_filter}; -use crate::template::RenderContext; -use crate::text::strip_html; +use std::borrow::Cow; + use blake3::Hasher; use lazy_static::lazy_static; use regex::{Captures, Regex}; -use std::borrow::Cow; + +use crate::{ + cloze::{cloze_filter, cloze_only_filter}, + template::RenderContext, + text::strip_html, +}; // Filtering //---------------------------------------- @@ -197,12 +201,14 @@ fn tts_filter(filter_name: &str, text: &str) -> Cow<'static, str> { #[cfg(test)] mod test { - use crate::template::RenderContext; - use crate::template_filters::{ - apply_filters, cloze_filter, furigana_filter, hint_filter, kana_filter, kanji_filter, - tts_filter, type_cloze_filter, type_filter, + use crate::{ + template::RenderContext, + template_filters::{ + apply_filters, cloze_filter, furigana_filter, hint_filter, kana_filter, kanji_filter, + tts_filter, type_cloze_filter, type_filter, + }, + text::strip_html, }; - use crate::text::strip_html; #[test] fn furigana() { diff --git a/rslib/src/text.rs b/rslib/src/text.rs index e3d71a225..b7bfa3f92 100644 --- a/rslib/src/text.rs +++ b/rslib/src/text.rs @@ -1,10 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::{borrow::Cow, ptr}; + use lazy_static::lazy_static; use regex::{Captures, Regex}; -use std::borrow::Cow; -use std::ptr; use unicase::eq as uni_eq; use unicode_normalization::{ char::is_combining_mark, is_nfc, is_nfkd_quick, IsNormalized, UnicodeNormalization, @@ -417,9 +417,10 @@ pub(crate) fn matches_glob(text: &str, search: &str) -> bool { #[cfg(test)] mod test { - use super::*; use std::borrow::Cow; + use super::*; + #[test] fn stripping() { assert_eq!(strip_html("test"), "test"); diff --git a/rslib/src/timestamp.rs b/rslib/src/timestamp.rs index 03330e6a9..e37f395a0 100644 --- a/rslib/src/timestamp.rs +++ b/rslib/src/timestamp.rs @@ -1,11 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::define_newtype; +use std::{env, time}; + use chrono::prelude::*; use lazy_static::lazy_static; -use std::env; -use std::time; + +use crate::define_newtype; define_newtype!(TimestampSecs, i64); define_newtype!(TimestampMillis, i64); diff --git a/rslib/src/undo/mod.rs b/rslib/src/undo/mod.rs index 2f6751e84..a5c8bf19e 100644 --- a/rslib/src/undo/mod.rs +++ b/rslib/src/undo/mod.rs @@ -3,14 +3,15 @@ mod changes; -pub use crate::ops::Op; +use std::collections::VecDeque; + pub(crate) use changes::UndoableChange; +pub use crate::ops::Op; use crate::{ ops::{OpChanges, StateChanges}, prelude::*, }; -use std::collections::VecDeque; const UNDO_LIMIT: usize = 30; @@ -245,8 +246,7 @@ impl Collection { #[cfg(test)] mod test { - use crate::card::Card; - use crate::{collection::open_test_collection, prelude::*}; + use crate::{card::Card, collection::open_test_collection, prelude::*}; #[test] fn undo() -> Result<()> { diff --git a/rslib/src/version.rs b/rslib/src/version.rs index b537a4074..a60ff5fa7 100644 --- a/rslib/src/version.rs +++ b/rslib/src/version.rs @@ -1,9 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use lazy_static::lazy_static; use std::env; +use lazy_static::lazy_static; + fn buildinfo(key: &str) -> &'static str { let buildinfo = include_str!(env!("BUILDINFO")); for line in buildinfo.split('\n') {