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
This commit is contained in:
Damien Elmes 2021-04-18 18:29:20 +10:00
parent 262b50445c
commit 64ebc32b3d
128 changed files with 649 additions and 524 deletions

View file

@ -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 {}

4
rslib/rustfmt.toml Normal file
View file

@ -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"

View file

@ -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<DeckAndNotetype> for DeckAndNotetypeProto {
fn from(s: DeckAndNotetype) -> Self {

View file

@ -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<pb::Card> {

View file

@ -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<pb::ExtractAvTagsOut> {

View file

@ -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<pb::Progress> {

View file

@ -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<BoolKeyProto> for BoolKey {
fn from(k: BoolKeyProto) -> Self {

View file

@ -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 {

View file

@ -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(

View file

@ -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<pb::OpChangesWithId> {

View file

@ -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);

View file

@ -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<pb::String> {

View file

@ -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

View file

@ -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<Mutex<Option<Collection>>>,

View file

@ -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<pb::Note> {

View file

@ -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<pb::NotetypeId> {

View file

@ -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<Mutex<ProgressState>>,
pub last_update: coarsetime::Instant,

View file

@ -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

View file

@ -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<pb::String> {

View file

@ -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<pb::SearchNode> for Node {
type Error = AnkiError;
fn try_from(msg: pb::SearchNode) -> std::result::Result<Self, Self::Error> {
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))),

View file

@ -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<pb::String> {

View file

@ -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,

View file

@ -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::{

View file

@ -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<pb::OpChangesWithCount> {

View file

@ -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},

View file

@ -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);

View file

@ -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() {

View file

@ -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<P: Into<PathBuf>>(
path: P,

View file

@ -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 {

View file

@ -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")]

View file

@ -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() {

View file

@ -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.

View file

@ -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 {

View file

@ -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 {

View file

@ -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.

View file

@ -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")]

View file

@ -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,

View file

@ -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,

View file

@ -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);

View file

@ -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);

View file

@ -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<D>(deserializer: D) -> Result<DeckSchema11, D::Error>
where

View file

@ -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();

View file

@ -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;

View file

@ -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<T, E = AnkiError> = std::result::Result<T, E>;

View file

@ -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,

View file

@ -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> {

View file

@ -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<NoteId>,

View file

@ -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(

View file

@ -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;

View file

@ -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();

View file

@ -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");

View file

@ -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<MediaEntry> {
#[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()?;

View file

@ -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<Option<V
#[cfg(test)]
mod test {
use std::borrow::Cow;
use tempfile::tempdir;
use crate::media::files::{
add_data_to_folder_uniquely, add_hash_suffix_to_file_stem, normalize_filename,
remove_files, sha1_of_data, truncate_filename, MAX_FILENAME_LENGTH,
};
use std::borrow::Cow;
use tempfile::tempdir;
#[test]
fn normalize() {

View file

@ -1,14 +1,22 @@
// 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 crate::media::database::{open_or_create, MediaDatabaseContext, MediaEntry};
use crate::media::files::{add_data_to_folder_uniquely, mtime_as_i64, remove_files, sha1_of_data};
use crate::media::sync::{MediaSyncProgress, MediaSyncer};
use std::{
borrow::Cow,
path::{Path, PathBuf},
};
use rusqlite::Connection;
use slog::Logger;
use std::borrow::Cow;
use std::path::{Path, PathBuf};
use crate::{
error::Result,
media::{
database::{open_or_create, MediaDatabaseContext, MediaEntry},
files::{add_data_to_folder_uniquely, mtime_as_i64, remove_files, sha1_of_data},
sync::{MediaSyncProgress, MediaSyncer},
},
};
pub mod changetracker;
pub mod check;

View file

@ -1,27 +1,37 @@
// 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, SyncErrorKind};
use crate::media::changetracker::ChangeTracker;
use crate::media::database::{MediaDatabaseContext, MediaDatabaseMetadata, MediaEntry};
use crate::media::files::{
add_file_from_ankiweb, data_for_file, mtime_as_i64, normalize_filename, AddedFile,
use std::{
borrow::Cow,
collections::HashMap,
io,
io::{Read, Write},
path::Path,
time,
};
use crate::media::MediaManager;
use crate::{sync::Timeouts, version};
use bytes::Bytes;
use reqwest::{multipart, Client, Response};
use serde_derive::{Deserialize, Serialize};
use serde_tuple::Serialize_tuple;
use slog::{debug, Logger};
use std::borrow::Cow;
use std::collections::HashMap;
use std::io::{Read, Write};
use std::path::Path;
use std::{io, time};
use time::Duration;
use version::sync_client_version;
use crate::{
error::{AnkiError, Result, SyncErrorKind},
media::{
changetracker::ChangeTracker,
database::{MediaDatabaseContext, MediaDatabaseMetadata, MediaEntry},
files::{
add_file_from_ankiweb, data_for_file, mtime_as_i64, normalize_filename, AddedFile,
},
MediaManager,
},
sync::Timeouts,
version,
};
static SYNC_MAX_FILES: usize = 25;
static SYNC_MAX_BYTES: usize = (2.5 * 1024.0 * 1024.0) as usize;
static SYNC_SINGLE_FILE_MAX_BYTES: usize = 100 * 1024 * 1024;
@ -805,14 +815,17 @@ fn zip_files<'a>(
#[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");

View file

@ -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);

View file

@ -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 {

View file

@ -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)]

View file

@ -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,

View file

@ -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);

View file

@ -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<RenderedNode>,

View file

@ -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)]

View file

@ -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() {

View file

@ -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,

View file

@ -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};

View file

@ -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 {

View file

@ -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 {

View file

@ -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,

View file

@ -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 {

View file

@ -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},

View file

@ -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,

View file

@ -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,

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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,
};

View file

@ -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) {

View file

@ -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)]

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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`.

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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;

View file

@ -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() {

View file

@ -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;

View file

@ -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,

View file

@ -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 {

View file

@ -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<ParseError<'a>>>;
type ParseResult<'a, O> = std::result::Result<O, nom::Err<ParseError<'a>>>;
@ -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)));
}

View file

@ -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<String>) {

View file

@ -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<String> {
#[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() {

View file

@ -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<T, D::Error>
@ -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)]

View file

@ -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,

Some files were not shown because too many files have changed in this diff Show more