From dc81a7fed07261e90672383ed147960065fc40a1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 27 Mar 2021 19:53:33 +1000 Subject: [PATCH] use mixed case for abbreviations in Rust code So, this is fun. Apparently "DeckId" is considered preferable to the "DeckID" were were using until now, and the latest clippy will start warning about it. We could of course disable the warning, but probably better to bite the bullet and switch to the naming that's generally considered best. --- rslib/src/adding.rs | 14 ++--- rslib/src/backend/card.rs | 14 ++--- rslib/src/backend/cardrendering.rs | 8 +-- rslib/src/backend/dbproxy.rs | 34 +++++------ rslib/src/backend/decks.rs | 18 +++--- rslib/src/backend/err.rs | 6 +- rslib/src/backend/generic.rs | 22 +++---- rslib/src/backend/notes.rs | 14 ++--- rslib/src/backend/scheduler/answering.rs | 2 +- rslib/src/backend/scheduler/mod.rs | 10 ++-- rslib/src/backend/search/mod.rs | 2 +- rslib/src/backend/search/search_node.rs | 4 +- rslib/src/browser_rows.rs | 10 ++-- rslib/src/card/mod.rs | 36 +++++------ rslib/src/card/undo.rs | 8 +-- rslib/src/collection.rs | 8 +-- rslib/src/config/deck.rs | 18 +++--- rslib/src/config/mod.rs | 8 +-- rslib/src/config/notetype.rs | 18 +++--- rslib/src/dbcheck.rs | 28 ++++----- rslib/src/deckconf/mod.rs | 12 ++-- rslib/src/deckconf/schema11.rs | 6 +- rslib/src/decks/counts.rs | 4 +- rslib/src/decks/filtered.rs | 2 +- rslib/src/decks/mod.rs | 42 ++++++------- rslib/src/decks/schema11.rs | 8 +-- rslib/src/decks/tree.rs | 48 +++++++-------- rslib/src/decks/undo.rs | 8 +-- rslib/src/err.rs | 36 +++++------ rslib/src/findreplace.rs | 14 ++--- rslib/src/media/changetracker.rs | 2 +- rslib/src/media/check.rs | 6 +- rslib/src/media/files.rs | 2 +- rslib/src/media/sync.rs | 36 +++++------ rslib/src/notes/mod.rs | 48 +++++++-------- rslib/src/notes/undo.rs | 10 ++-- rslib/src/notetype/cardgen.rs | 44 +++++++------- rslib/src/notetype/emptycards.rs | 12 ++-- rslib/src/notetype/mod.rs | 18 +++--- rslib/src/notetype/render.rs | 8 +-- rslib/src/notetype/schema11.rs | 18 +++--- rslib/src/notetype/schemachange.rs | 6 +- rslib/src/notetype/stock.rs | 2 +- rslib/src/notetype/templates.rs | 6 +- rslib/src/prelude.rs | 12 ++-- rslib/src/revlog/mod.rs | 16 ++--- rslib/src/revlog/undo.rs | 2 +- rslib/src/scheduler/answering/mod.rs | 10 ++-- rslib/src/scheduler/answering/preview.rs | 2 +- rslib/src/scheduler/answering/revlog.rs | 2 +- rslib/src/scheduler/answering/undo.rs | 8 +-- rslib/src/scheduler/bury_and_suspend.rs | 10 ++-- rslib/src/scheduler/filtered/card.rs | 2 +- rslib/src/scheduler/filtered/mod.rs | 20 +++---- rslib/src/scheduler/new.rs | 26 ++++---- .../src/scheduler/queue/builder/gathering.rs | 32 +++++----- rslib/src/scheduler/queue/builder/mod.rs | 14 ++--- rslib/src/scheduler/queue/entry.rs | 2 +- rslib/src/scheduler/queue/learning.rs | 6 +- rslib/src/scheduler/queue/limits.rs | 8 +-- rslib/src/scheduler/queue/main.rs | 4 +- rslib/src/scheduler/queue/mod.rs | 6 +- rslib/src/scheduler/queue/undo.rs | 2 +- rslib/src/scheduler/reviews.rs | 10 ++-- rslib/src/scheduler/upgrade.rs | 6 +- rslib/src/search/cards.rs | 4 +- rslib/src/search/notes.rs | 4 +- rslib/src/search/parser.rs | 24 ++++---- rslib/src/search/sqlwriter.rs | 20 +++---- rslib/src/search/writer.rs | 14 ++--- rslib/src/stats/card.rs | 10 ++-- rslib/src/storage/card/mod.rs | 40 ++++++------- rslib/src/storage/deck/mod.rs | 46 +++++++------- rslib/src/storage/deckconf/mod.rs | 12 ++-- rslib/src/storage/graves/mod.rs | 24 ++++---- rslib/src/storage/note/mod.rs | 24 ++++---- rslib/src/storage/notetype/mod.rs | 58 +++++++++--------- rslib/src/storage/revlog/mod.rs | 10 ++-- rslib/src/storage/sqlite.rs | 10 ++-- rslib/src/sync/http_client.rs | 14 ++--- rslib/src/sync/mod.rs | 60 +++++++++---------- rslib/src/sync/server.rs | 4 +- rslib/src/tags/bulkadd.rs | 4 +- rslib/src/tags/findreplace.rs | 8 +-- rslib/src/tags/register.rs | 4 +- rslib/src/tags/remove.rs | 6 +- rslib/src/tags/reparent.rs | 2 +- rslib/src/tags/tree.rs | 2 +- rslib/src/text.rs | 14 ++--- 89 files changed, 649 insertions(+), 649 deletions(-) diff --git a/rslib/src/adding.rs b/rslib/src/adding.rs index 090c54a2a..61559eefa 100644 --- a/rslib/src/adding.rs +++ b/rslib/src/adding.rs @@ -6,8 +6,8 @@ use std::sync::Arc; use crate::prelude::*; pub struct DeckAndNotetype { - pub deck_id: DeckID, - pub notetype_id: NoteTypeID, + pub deck_id: DeckId, + pub notetype_id: NoteTypeId, } impl Collection { @@ -23,7 +23,7 @@ impl Collection { /// Default otherwise. pub fn defaults_for_adding( &mut self, - home_deck_of_reviewer_card: DeckID, + home_deck_of_reviewer_card: DeckId, ) -> Result { let deck_id; let notetype_id; @@ -52,7 +52,7 @@ impl Collection { /// The currently selected deck, the home deck of the provided card, or the default deck. fn get_current_deck_for_adding( &mut self, - home_deck_of_reviewer_card: DeckID, + home_deck_of_reviewer_card: DeckId, ) -> Result> { // current deck, if not filtered if let Some(current) = self.get_deck(self.get_current_deck_id())? { @@ -65,7 +65,7 @@ impl Collection { return Ok(home_deck); } // default deck - self.get_deck(DeckID(1))?.ok_or(AnkiError::NotFound) + self.get_deck(DeckId(1))?.ok_or(AnkiError::NotFound) } fn get_current_notetype_for_adding(&mut self) -> Result> { @@ -83,7 +83,7 @@ impl Collection { } } - fn default_notetype_for_deck(&mut self, deck: DeckID) -> Result> { + fn default_notetype_for_deck(&mut self, deck: DeckId) -> Result> { // try last notetype used by deck if let Some(ntid) = self.get_last_notetype_for_deck(deck) { if let Some(nt) = self.get_notetype(ntid)? { @@ -99,7 +99,7 @@ impl Collection { /// This is optional due to the inconsistent handling, where changes in notetype /// may need to update the current deck, but not vice versa. If a previous deck is /// not set, we want to keep the current selection, instead of resetting it. - pub(crate) fn default_deck_for_notetype(&mut self, ntid: NoteTypeID) -> Result> { + pub(crate) fn default_deck_for_notetype(&mut self, ntid: NoteTypeId) -> Result> { if let Some(last_deck_id) = self.get_last_deck_added_to_for_notetype(ntid) { if let Some(deck) = self.get_deck(last_deck_id)? { if !deck.is_filtered() { diff --git a/rslib/src/backend/card.rs b/rslib/src/backend/card.rs index 53e286ea8..2e2b0973c 100644 --- a/rslib/src/backend/card.rs +++ b/rslib/src/backend/card.rs @@ -45,7 +45,7 @@ impl CardsService for Backend { } fn set_deck(&self, input: pb::SetDeckIn) -> Result { - let cids: Vec<_> = input.card_ids.into_iter().map(CardID).collect(); + let cids: Vec<_> = input.card_ids.into_iter().map(CardId).collect(); let deck_id = input.deck_id.into(); self.with_col(|col| col.set_deck(&cids, deck_id).map(Into::into)) } @@ -67,9 +67,9 @@ impl TryFrom for Card { let queue = CardQueue::try_from(c.queue as i8) .map_err(|_| AnkiError::invalid_input("invalid card queue"))?; Ok(Card { - id: CardID(c.id), - note_id: NoteID(c.note_id), - deck_id: DeckID(c.deck_id), + id: CardId(c.id), + note_id: NoteId(c.note_id), + deck_id: DeckId(c.deck_id), template_idx: c.template_idx as u16, mtime: TimestampSecs(c.mtime_secs), usn: Usn(c.usn), @@ -82,7 +82,7 @@ impl TryFrom for Card { lapses: c.lapses, remaining_steps: c.remaining_steps, original_due: c.original_due, - original_deck_id: DeckID(c.original_deck_id), + original_deck_id: DeckId(c.original_deck_id), flags: c.flags as u8, data: c.data, }) @@ -114,6 +114,6 @@ impl From for pb::Card { } } -fn to_card_ids(v: Vec) -> Vec { - v.into_iter().map(CardID).collect() +fn to_card_ids(v: Vec) -> Vec { + v.into_iter().map(CardId).collect() } diff --git a/rslib/src/backend/cardrendering.rs b/rslib/src/backend/cardrendering.rs index a245973af..a2a016b8e 100644 --- a/rslib/src/backend/cardrendering.rs +++ b/rslib/src/backend/cardrendering.rs @@ -9,7 +9,7 @@ use crate::{ notetype::{CardTemplateSchema11, RenderCardOutput}, prelude::*, template::RenderedNode, - text::{extract_av_tags, sanitize_html_no_images, strip_av_tags, AVTag}, + text::{extract_av_tags, sanitize_html_no_images, strip_av_tags, AvTag}, }; pub(super) use pb::cardrendering_service::Service as CardRenderingService; @@ -19,10 +19,10 @@ impl CardRenderingService for Backend { let pt_tags = tags .into_iter() .map(|avtag| match avtag { - AVTag::SoundOrVideo(file) => pb::AvTag { + AvTag::SoundOrVideo(file) => pb::AvTag { value: Some(pb::av_tag::Value::SoundOrVideo(file)), }, - AVTag::TextToSpeech { + AvTag::TextToSpeech { field_text, lang, voices, @@ -90,7 +90,7 @@ impl CardRenderingService for Backend { fn render_existing_card(&self, input: pb::RenderExistingCardIn) -> Result { self.with_col(|col| { - col.render_existing_card(CardID(input.card_id), input.browser) + col.render_existing_card(CardId(input.card_id), input.browser) .map(Into::into) }) } diff --git a/rslib/src/backend/dbproxy.rs b/rslib/src/backend/dbproxy.rs index d6d2b6f41..eae2ace94 100644 --- a/rslib/src/backend/dbproxy.rs +++ b/rslib/src/backend/dbproxy.rs @@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize}; #[derive(Deserialize)] #[serde(tag = "kind", rename_all = "lowercase")] -pub(super) enum DBRequest { +pub(super) enum DbRequest { Query { sql: String, args: Vec, @@ -26,7 +26,7 @@ pub(super) enum DBRequest { #[derive(Serialize)] #[serde(untagged)] -pub(super) enum DBResult { +pub(super) enum DbResult { Rows(Vec>), None, } @@ -68,9 +68,9 @@ impl FromSql for SqlValue { } pub(super) fn db_command_bytes(col: &mut Collection, input: &[u8]) -> Result> { - let req: DBRequest = serde_json::from_slice(input)?; + let req: DbRequest = serde_json::from_slice(input)?; let resp = match req { - DBRequest::Query { + DbRequest::Query { sql, args, first_row_only, @@ -82,24 +82,24 @@ pub(super) fn db_command_bytes(col: &mut Collection, input: &[u8]) -> Result { + DbRequest::Begin => { col.storage.begin_trx()?; - DBResult::None + DbResult::None } - DBRequest::Commit => { + DbRequest::Commit => { if col.state.modified_by_dbproxy { col.storage.set_modified()?; col.state.modified_by_dbproxy = false; } col.storage.commit_trx()?; - DBResult::None + DbResult::None } - DBRequest::Rollback => { + DbRequest::Rollback => { col.clear_caches(); col.storage.rollback_trx()?; - DBResult::None + DbResult::None } - DBRequest::ExecuteMany { sql, args } => { + DbRequest::ExecuteMany { sql, args } => { update_state_after_modification(col, &sql); db_execute_many(&col.storage, &sql, &args)? } @@ -125,7 +125,7 @@ fn is_dql(sql: &str) -> bool { head.starts_with("select ") } -pub(super) fn db_query_row(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> Result { +pub(super) fn db_query_row(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> Result { let mut stmt = ctx.db.prepare_cached(sql)?; let columns = stmt.column_count(); @@ -146,10 +146,10 @@ pub(super) fn db_query_row(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> vec![] }; - Ok(DBResult::Rows(rows)) + Ok(DbResult::Rows(rows)) } -pub(super) fn db_query(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> Result { +pub(super) fn db_query(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> Result { let mut stmt = ctx.db.prepare_cached(sql)?; let columns = stmt.column_count(); @@ -164,19 +164,19 @@ pub(super) fn db_query(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> Res })? .collect(); - Ok(DBResult::Rows(res?)) + Ok(DbResult::Rows(res?)) } pub(super) fn db_execute_many( ctx: &SqliteStorage, sql: &str, args: &[Vec], -) -> Result { +) -> Result { let mut stmt = ctx.db.prepare_cached(sql)?; for params in args { stmt.execute(params)?; } - Ok(DBResult::None) + Ok(DbResult::None) } diff --git a/rslib/src/backend/decks.rs b/rslib/src/backend/decks.rs index 901910652..0042c54c8 100644 --- a/rslib/src/backend/decks.rs +++ b/rslib/src/backend/decks.rs @@ -4,7 +4,7 @@ use super::Backend; use crate::{ backend_proto::{self as pb}, - decks::{Deck, DeckID, DeckSchema11}, + decks::{Deck, DeckId, DeckSchema11}, prelude::*, scheduler::filtered::FilteredDeckForUpdate, }; @@ -38,7 +38,7 @@ impl DecksService for Backend { fn deck_tree(&self, input: pb::DeckTreeIn) -> Result { let lim = if input.top_deck_id > 0 { - Some(DeckID(input.top_deck_id)) + Some(DeckId(input.top_deck_id)) } else { None }; @@ -120,7 +120,7 @@ impl DecksService for Backend { } fn remove_decks(&self, input: pb::DeckIDs) -> Result { - self.with_col(|col| col.remove_decks_and_child_decks(&Into::>::into(input))) + self.with_col(|col| col.remove_decks_and_child_decks(&Into::>::into(input))) .map(Into::into) } @@ -155,20 +155,20 @@ impl DecksService for Backend { } } -impl From for DeckID { +impl From for DeckId { fn from(did: pb::DeckId) -> Self { - DeckID(did.did) + DeckId(did.did) } } -impl From for Vec { +impl From for Vec { fn from(dids: pb::DeckIDs) -> Self { - dids.dids.into_iter().map(DeckID).collect() + dids.dids.into_iter().map(DeckId).collect() } } -impl From for pb::DeckId { - fn from(did: DeckID) -> Self { +impl From for pb::DeckId { + fn from(did: DeckId) -> Self { pb::DeckId { did: did.0 } } } diff --git a/rslib/src/backend/err.rs b/rslib/src/backend/err.rs index 6ed2c6d96..512278933 100644 --- a/rslib/src/backend/err.rs +++ b/rslib/src/backend/err.rs @@ -14,8 +14,8 @@ pub(super) fn anki_error_to_proto_error(err: AnkiError, tr: &I18n) -> pb::Backen let value = match err { AnkiError::InvalidInput { .. } => V::InvalidInput(pb::Empty {}), AnkiError::TemplateError { .. } => V::TemplateParse(pb::Empty {}), - AnkiError::IOError { .. } => V::IoError(pb::Empty {}), - AnkiError::DBError { .. } => V::DbError(pb::Empty {}), + AnkiError::IoError { .. } => V::IoError(pb::Empty {}), + AnkiError::DbError { .. } => V::DbError(pb::Empty {}), AnkiError::NetworkError { kind, .. } => { V::NetworkError(pb::NetworkError { kind: kind.into() }) } @@ -23,7 +23,7 @@ pub(super) fn anki_error_to_proto_error(err: AnkiError, tr: &I18n) -> pb::Backen AnkiError::Interrupted => V::Interrupted(pb::Empty {}), AnkiError::CollectionNotOpen => V::InvalidInput(pb::Empty {}), AnkiError::CollectionAlreadyOpen => V::InvalidInput(pb::Empty {}), - AnkiError::JSONError { info } => V::JsonError(info), + AnkiError::JsonError { info } => V::JsonError(info), AnkiError::ProtoError { info } => V::ProtoError(info), AnkiError::NotFound => V::NotFoundError(pb::Empty {}), AnkiError::Existing => V::Exists(pb::Empty {}), diff --git a/rslib/src/backend/generic.rs b/rslib/src/backend/generic.rs index 3aae3b721..a9075d050 100644 --- a/rslib/src/backend/generic.rs +++ b/rslib/src/backend/generic.rs @@ -45,33 +45,33 @@ impl From<()> for pb::Empty { } } -impl From for CardID { +impl From for CardId { fn from(cid: pb::CardId) -> Self { - CardID(cid.cid) + CardId(cid.cid) } } -impl Into> for pb::CardIDs { - fn into(self) -> Vec { - self.cids.into_iter().map(CardID).collect() +impl Into> for pb::CardIDs { + fn into(self) -> Vec { + self.cids.into_iter().map(CardId).collect() } } -impl From for NoteID { +impl From for NoteId { fn from(nid: pb::NoteId) -> Self { - NoteID(nid.nid) + NoteId(nid.nid) } } -impl From for NoteTypeID { +impl From for NoteTypeId { fn from(ntid: pb::NoteTypeId) -> Self { - NoteTypeID(ntid.ntid) + NoteTypeId(ntid.ntid) } } -impl From for DeckConfID { +impl From for DeckConfId { fn from(dcid: pb::DeckConfigId) -> Self { - DeckConfID(dcid.dcid) + DeckConfId(dcid.dcid) } } diff --git a/rslib/src/backend/notes.rs b/rslib/src/backend/notes.rs index f147d14cd..f29f91242 100644 --- a/rslib/src/backend/notes.rs +++ b/rslib/src/backend/notes.rs @@ -22,7 +22,7 @@ impl NotesService for Backend { fn add_note(&self, input: pb::AddNoteIn) -> Result { self.with_col(|col| { let mut note: Note = input.note.ok_or(AnkiError::NotFound)?.into(); - let changes = col.add_note(&mut note, DeckID(input.deck_id))?; + let changes = col.add_note(&mut note, DeckId(input.deck_id))?; Ok(pb::AddNoteOut { note_id: note.id.0, changes: Some(changes.into()), @@ -32,7 +32,7 @@ impl NotesService for Backend { fn defaults_for_adding(&self, input: pb::DefaultsForAddingIn) -> Result { self.with_col(|col| { - let home_deck: DeckID = input.home_deck_of_current_review_card.into(); + let home_deck: DeckId = input.home_deck_of_current_review_card.into(); col.defaults_for_adding(home_deck).map(Into::into) }) } @@ -41,7 +41,7 @@ impl NotesService for Backend { self.with_col(|col| { Ok(col .default_deck_for_notetype(input.into())? - .unwrap_or(DeckID(0)) + .unwrap_or(DeckId(0)) .into()) }) } @@ -113,7 +113,7 @@ impl NotesService for Backend { input: pb::FieldNamesForNotesIn, ) -> Result { self.with_col(|col| { - let nids: Vec<_> = input.nids.into_iter().map(NoteID).collect(); + let nids: Vec<_> = input.nids.into_iter().map(NoteId).collect(); col.storage .field_names_for_notes(&nids) .map(|fields| pb::FieldNamesForNotesOut { fields }) @@ -131,7 +131,7 @@ impl NotesService for Backend { fn cards_of_note(&self, input: pb::NoteId) -> Result { self.with_col(|col| { col.storage - .all_card_ids_of_note(NoteID(input.nid)) + .all_card_ids_of_note(NoteId(input.nid)) .map(|v| pb::CardIDs { cids: v.into_iter().map(Into::into).collect(), }) @@ -139,6 +139,6 @@ impl NotesService for Backend { } } -pub(super) fn to_note_ids(ids: Vec) -> Vec { - ids.into_iter().map(NoteID).collect() +pub(super) fn to_note_ids(ids: Vec) -> Vec { + ids.into_iter().map(NoteId).collect() } diff --git a/rslib/src/backend/scheduler/answering.rs b/rslib/src/backend/scheduler/answering.rs index d8f15a900..dde53ad92 100644 --- a/rslib/src/backend/scheduler/answering.rs +++ b/rslib/src/backend/scheduler/answering.rs @@ -13,7 +13,7 @@ use crate::{ impl From for CardAnswer { fn from(answer: pb::AnswerCardIn) -> Self { CardAnswer { - card_id: CardID(answer.card_id), + card_id: CardId(answer.card_id), rating: answer.rating().into(), current_state: answer.current_state.unwrap_or_default().into(), new_state: answer.new_state.unwrap_or_default().into(), diff --git a/rslib/src/backend/scheduler/mod.rs b/rslib/src/backend/scheduler/mod.rs index 11ab3c0d6..03d0b78d5 100644 --- a/rslib/src/backend/scheduler/mod.rs +++ b/rslib/src/backend/scheduler/mod.rs @@ -90,7 +90,7 @@ impl SchedulingService for Backend { fn bury_or_suspend_cards(&self, input: pb::BuryOrSuspendCardsIn) -> Result { self.with_col(|col| { let mode = input.mode(); - let cids: Vec<_> = input.card_ids.into_iter().map(CardID).collect(); + let cids: Vec<_> = input.card_ids.into_iter().map(CardId).collect(); col.bury_or_suspend_cards(&cids, mode).map(Into::into) }) } @@ -105,7 +105,7 @@ impl SchedulingService for Backend { fn schedule_cards_as_new(&self, input: pb::ScheduleCardsAsNewIn) -> Result { self.with_col(|col| { - let cids: Vec<_> = input.card_ids.into_iter().map(CardID).collect(); + let cids: Vec<_> = input.card_ids.into_iter().map(CardId).collect(); let log = input.log; col.reschedule_cards_as_new(&cids, log).map(Into::into) }) @@ -114,12 +114,12 @@ impl SchedulingService for Backend { fn set_due_date(&self, input: pb::SetDueDateIn) -> Result { let config = input.config_key.map(Into::into); let days = input.days; - let cids: Vec<_> = input.card_ids.into_iter().map(CardID).collect(); + let cids: Vec<_> = input.card_ids.into_iter().map(CardId).collect(); self.with_col(|col| col.set_due_date(&cids, &days, config).map(Into::into)) } fn sort_cards(&self, input: pb::SortCardsIn) -> Result { - let cids: Vec<_> = input.card_ids.into_iter().map(CardID).collect(); + let cids: Vec<_> = input.card_ids.into_iter().map(CardId).collect(); let (start, step, random, shift) = ( input.starting_from, input.step_size, @@ -145,7 +145,7 @@ impl SchedulingService for Backend { } fn get_next_card_states(&self, input: pb::CardId) -> Result { - let cid: CardID = input.into(); + let cid: CardId = input.into(); self.with_col(|col| col.get_next_card_states(cid)) .map(Into::into) } diff --git a/rslib/src/backend/search/mod.rs b/rslib/src/backend/search/mod.rs index e52948567..cf89afb3d 100644 --- a/rslib/src/backend/search/mod.rs +++ b/rslib/src/backend/search/mod.rs @@ -75,7 +75,7 @@ impl SearchService for Backend { if !input.match_case { search = format!("(?i){}", search); } - let nids = input.nids.into_iter().map(NoteID).collect(); + let nids = input.nids.into_iter().map(NoteId).collect(); let field_name = if input.field_name.is_empty() { None } else { diff --git a/rslib/src/backend/search/search_node.rs b/rslib/src/backend/search/search_node.rs index e166e4ddf..351a8dfb4 100644 --- a/rslib/src/backend/search/search_node.rs +++ b/rslib/src/backend/search/search_node.rs @@ -33,8 +33,8 @@ impl TryFrom for Node { Filter::Template(u) => { Node::Search(SearchNode::CardTemplate(TemplateKind::Ordinal(u as u16))) } - Filter::Nid(nid) => Node::Search(SearchNode::NoteIDs(nid.to_string())), - Filter::Nids(nids) => Node::Search(SearchNode::NoteIDs(nids.into_id_string())), + Filter::Nid(nid) => Node::Search(SearchNode::NoteIds(nid.to_string())), + Filter::Nids(nids) => Node::Search(SearchNode::NoteIds(nids.into_id_string())), Filter::Dupe(dupe) => Node::Search(SearchNode::Duplicates { note_type_id: dupe.notetype_id.into(), text: dupe.first_field, diff --git a/rslib/src/browser_rows.rs b/rslib/src/browser_rows.rs index 5156aaf1b..79162a7aa 100644 --- a/rslib/src/browser_rows.rs +++ b/rslib/src/browser_rows.rs @@ -8,9 +8,9 @@ use itertools::Itertools; use crate::err::{AnkiError, Result}; use crate::i18n::I18n; use crate::{ - card::{Card, CardID, CardQueue, CardType}, + card::{Card, CardId, CardQueue, CardType}, collection::Collection, - decks::{Deck, DeckID}, + decks::{Deck, DeckId}, notes::Note, notetype::{CardTemplate, NoteType, NoteTypeKind}, scheduler::{timespan::time_span, timing::SchedTimingToday}, @@ -77,7 +77,7 @@ fn card_render_required(columns: &[String]) -> bool { } impl Collection { - pub fn browser_row_for_card(&mut self, id: CardID) -> Result { + pub fn browser_row_for_card(&mut self, id: CardId) -> Result { // this is inefficient; we may want to use an enum in the future let columns = self.get_desktop_browser_card_columns(); let mut context = RowContext::new(self, id, card_render_required(&columns))?; @@ -124,7 +124,7 @@ impl RenderContext { } impl<'a> RowContext<'a> { - fn new(col: &'a mut Collection, id: CardID, with_card_render: bool) -> Result { + fn new(col: &'a mut Collection, id: CardId, with_card_render: bool) -> Result { let card = col.storage.get_card(id)?.ok_or(AnkiError::NotFound)?; // todo: After note.sort_field has been modified so it can be displayed in the browser, // we can update note_field_str() and only load the note with fields if a card render is @@ -235,7 +235,7 @@ impl<'a> RowContext<'a> { } fn card_due_str(&mut self) -> String { - let due = if self.card.original_deck_id != DeckID(0) { + let due = if self.card.original_deck_id != DeckId(0) { self.tr.browsing_filtered() } else if self.card.queue == CardQueue::New || self.card.ctype == CardType::New { self.tr.statistics_due_for_new_card(self.card.due) diff --git a/rslib/src/card/mod.rs b/rslib/src/card/mod.rs index d6fa34a85..037cbd1eb 100644 --- a/rslib/src/card/mod.rs +++ b/rslib/src/card/mod.rs @@ -4,21 +4,21 @@ pub(crate) mod undo; use crate::err::{AnkiError, Result}; -use crate::notes::NoteID; +use crate::notes::NoteId; use crate::{ collection::Collection, config::SchedulerVersion, prelude::*, timestamp::TimestampSecs, types::Usn, }; use crate::{define_newtype, ops::StateChanges}; -use crate::{deckconf::DeckConf, decks::DeckID}; +use crate::{deckconf::DeckConf, decks::DeckId}; use num_enum::TryFromPrimitive; use serde_repr::{Deserialize_repr, Serialize_repr}; use std::collections::HashSet; -define_newtype!(CardID, i64); +define_newtype!(CardId, i64); -impl CardID { +impl CardId { pub fn as_secs(self) -> TimestampSecs { TimestampSecs(self.0 / 1000) } @@ -54,9 +54,9 @@ pub enum CardQueue { #[derive(Debug, Clone, PartialEq)] pub struct Card { - pub(crate) id: CardID, - pub(crate) note_id: NoteID, - pub(crate) deck_id: DeckID, + pub(crate) id: CardId, + pub(crate) note_id: NoteId, + pub(crate) deck_id: DeckId, pub(crate) template_idx: u16, pub(crate) mtime: TimestampSecs, pub(crate) usn: Usn, @@ -69,7 +69,7 @@ pub struct Card { pub(crate) lapses: u32, pub(crate) remaining_steps: u32, pub(crate) original_due: i32, - pub(crate) original_deck_id: DeckID, + pub(crate) original_deck_id: DeckId, pub(crate) flags: u8, pub(crate) data: String, } @@ -77,9 +77,9 @@ pub struct Card { impl Default for Card { fn default() -> Self { Self { - id: CardID(0), - note_id: NoteID(0), - deck_id: DeckID(0), + id: CardId(0), + note_id: NoteId(0), + deck_id: DeckId(0), template_idx: 0, mtime: TimestampSecs(0), usn: Usn(0), @@ -92,7 +92,7 @@ impl Default for Card { lapses: 0, remaining_steps: 0, original_due: 0, - original_deck_id: DeckID(0), + original_deck_id: DeckId(0), flags: 0, data: "".to_string(), } @@ -106,7 +106,7 @@ impl Card { } /// Caller must ensure provided deck exists and is not filtered. - fn set_deck(&mut self, deck: DeckID, sched: SchedulerVersion) { + fn set_deck(&mut self, deck: DeckId, sched: SchedulerVersion) { self.remove_from_filtered_deck_restoring_queue(sched); self.deck_id = deck; } @@ -137,7 +137,7 @@ impl Card { } impl Card { - pub fn new(note_id: NoteID, template_idx: u16, deck_id: DeckID, due: i32) -> Self { + pub fn new(note_id: NoteId, template_idx: u16, deck_id: DeckId, due: i32) -> Self { Card { note_id, template_idx, @@ -177,7 +177,7 @@ impl Collection { } #[cfg(test)] - pub(crate) fn get_and_update_card(&mut self, cid: CardID, func: F) -> Result + pub(crate) fn get_and_update_card(&mut self, cid: CardId, func: F) -> Result where F: FnOnce(&mut Card) -> Result, { @@ -213,7 +213,7 @@ impl Collection { /// Remove cards and any resulting orphaned notes. /// Expects a transaction. - pub(crate) fn remove_cards_and_orphaned_notes(&mut self, cids: &[CardID]) -> Result<()> { + pub(crate) fn remove_cards_and_orphaned_notes(&mut self, cids: &[CardId]) -> Result<()> { let usn = self.usn()?; let mut nids = HashSet::new(); for cid in cids { @@ -231,7 +231,7 @@ impl Collection { Ok(()) } - pub fn set_deck(&mut self, cards: &[CardID], deck_id: DeckID) -> Result> { + pub fn set_deck(&mut self, cards: &[CardId], deck_id: DeckId) -> Result> { let deck = self.get_deck(deck_id)?.ok_or(AnkiError::NotFound)?; if deck.is_filtered() { return Err(AnkiError::DeckIsFiltered); @@ -252,7 +252,7 @@ impl Collection { }) } - pub fn set_card_flag(&mut self, cards: &[CardID], flag: u32) -> Result> { + pub fn set_card_flag(&mut self, cards: &[CardId], flag: u32) -> Result> { if flag > 4 { return Err(AnkiError::invalid_input("invalid flag")); } diff --git a/rslib/src/card/undo.rs b/rslib/src/card/undo.rs index fc23da733..c0bb0a035 100644 --- a/rslib/src/card/undo.rs +++ b/rslib/src/card/undo.rs @@ -8,8 +8,8 @@ pub(crate) enum UndoableCardChange { Added(Box), Updated(Box), Removed(Box), - GraveAdded(Box<(CardID, Usn)>), - GraveRemoved(Box<(CardID, Usn)>), + GraveAdded(Box<(CardId, Usn)>), + GraveRemoved(Box<(CardId, Usn)>), } impl Collection { @@ -66,12 +66,12 @@ impl Collection { Ok(()) } - fn add_card_grave_undoable(&mut self, cid: CardID, usn: Usn) -> Result<()> { + fn add_card_grave_undoable(&mut self, cid: CardId, usn: Usn) -> Result<()> { self.save_undo(UndoableCardChange::GraveAdded(Box::new((cid, usn)))); self.storage.add_card_grave(cid, usn) } - fn remove_card_grave(&mut self, cid: CardID, usn: Usn) -> Result<()> { + fn remove_card_grave(&mut self, cid: CardId, usn: Usn) -> Result<()> { self.save_undo(UndoableCardChange::GraveRemoved(Box::new((cid, usn)))); self.storage.remove_card_grave(cid) } diff --git a/rslib/src/collection.rs b/rslib/src/collection.rs index e1d5caee1..627665c9c 100644 --- a/rslib/src/collection.rs +++ b/rslib/src/collection.rs @@ -4,8 +4,8 @@ use crate::log::Logger; use crate::types::Usn; use crate::{ - decks::{Deck, DeckID}, - notetype::{NoteType, NoteTypeID}, + decks::{Deck, DeckId}, + notetype::{NoteType, NoteTypeId}, prelude::*, storage::SqliteStorage, undo::UndoManager, @@ -62,8 +62,8 @@ pub fn open_test_collection_with_server(server: bool) -> Collection { #[derive(Debug, Default)] pub struct CollectionState { pub(crate) undo: UndoManager, - pub(crate) notetype_cache: HashMap>, - pub(crate) deck_cache: HashMap>, + pub(crate) notetype_cache: HashMap>, + pub(crate) deck_cache: HashMap>, pub(crate) card_queues: Option, /// True if legacy Python code has executed SQL that has modified the /// database, requiring modification time to be bumped. diff --git a/rslib/src/config/deck.rs b/rslib/src/config/deck.rs index 22c7b8694..f851896ee 100644 --- a/rslib/src/config/deck.rs +++ b/rslib/src/config/deck.rs @@ -14,36 +14,36 @@ enum DeckConfigKey { } impl DeckConfigKey { - fn for_deck(self, did: DeckID) -> String { + fn for_deck(self, did: DeckId) -> String { build_aux_deck_key(did, <&'static str>::from(self)) } } impl Collection { - pub(crate) fn get_current_deck_id(&self) -> DeckID { - self.get_config_optional(ConfigKey::CurrentDeckID) - .unwrap_or(DeckID(1)) + pub(crate) fn get_current_deck_id(&self) -> DeckId { + self.get_config_optional(ConfigKey::CurrentDeckId) + .unwrap_or(DeckId(1)) } - pub(crate) fn clear_aux_config_for_deck(&self, ntid: DeckID) -> Result<()> { + pub(crate) fn clear_aux_config_for_deck(&self, ntid: DeckId) -> Result<()> { self.remove_config_prefix(&build_aux_deck_key(ntid, "")) } - pub(crate) fn get_last_notetype_for_deck(&self, id: DeckID) -> Option { + pub(crate) fn get_last_notetype_for_deck(&self, id: DeckId) -> Option { let key = DeckConfigKey::LastNotetype.for_deck(id); self.get_config_optional(key.as_str()) } pub(crate) fn set_last_notetype_for_deck( &mut self, - did: DeckID, - ntid: NoteTypeID, + did: DeckId, + ntid: NoteTypeId, ) -> Result<()> { let key = DeckConfigKey::LastNotetype.for_deck(did); self.set_config(key.as_str(), &ntid) } } -fn build_aux_deck_key(deck: DeckID, key: &str) -> String { +fn build_aux_deck_key(deck: DeckId, key: &str) -> String { format!("_deck_{deck}_{key}", deck = deck, key = key) } diff --git a/rslib/src/config/mod.rs b/rslib/src/config/mod.rs index 244013976..f8b1df70e 100644 --- a/rslib/src/config/mod.rs +++ b/rslib/src/config/mod.rs @@ -49,9 +49,9 @@ pub(crate) enum ConfigKey { #[strum(to_string = "sortType")] BrowserSortKind, #[strum(to_string = "curDeck")] - CurrentDeckID, + CurrentDeckId, #[strum(to_string = "curModel")] - CurrentNoteTypeID, + CurrentNoteTypeId, #[strum(to_string = "lastUnburied")] LastUnburiedDay, #[strum(to_string = "collapseTime")] @@ -304,12 +304,12 @@ pub(crate) enum Weekday { mod test { use super::SortKind; use crate::collection::open_test_collection; - use crate::decks::DeckID; + use crate::decks::DeckId; #[test] fn defaults() { let col = open_test_collection(); - assert_eq!(col.get_current_deck_id(), DeckID(1)); + assert_eq!(col.get_current_deck_id(), DeckId(1)); assert_eq!(col.get_browser_sort_kind(), SortKind::NoteField); } diff --git a/rslib/src/config/notetype.rs b/rslib/src/config/notetype.rs index acda970da..b1f50dfe1 100644 --- a/rslib/src/config/notetype.rs +++ b/rslib/src/config/notetype.rs @@ -17,36 +17,36 @@ enum NoteTypeConfigKey { } impl NoteTypeConfigKey { - fn for_notetype(self, ntid: NoteTypeID) -> String { + fn for_notetype(self, ntid: NoteTypeId) -> String { build_aux_notetype_key(ntid, <&'static str>::from(self)) } } impl Collection { #[allow(dead_code)] - pub(crate) fn get_current_notetype_id(&self) -> Option { - self.get_config_optional(ConfigKey::CurrentNoteTypeID) + pub(crate) fn get_current_notetype_id(&self) -> Option { + self.get_config_optional(ConfigKey::CurrentNoteTypeId) } - pub(crate) fn set_current_notetype_id(&mut self, ntid: NoteTypeID) -> Result<()> { - self.set_config(ConfigKey::CurrentNoteTypeID, &ntid) + pub(crate) fn set_current_notetype_id(&mut self, ntid: NoteTypeId) -> Result<()> { + self.set_config(ConfigKey::CurrentNoteTypeId, &ntid) } - pub(crate) fn clear_aux_config_for_notetype(&self, ntid: NoteTypeID) -> Result<()> { + pub(crate) fn clear_aux_config_for_notetype(&self, ntid: NoteTypeId) -> Result<()> { self.remove_config_prefix(&build_aux_notetype_key(ntid, "")) } - pub(crate) fn get_last_deck_added_to_for_notetype(&self, id: NoteTypeID) -> Option { + pub(crate) fn get_last_deck_added_to_for_notetype(&self, id: NoteTypeId) -> Option { let key = NoteTypeConfigKey::LastDeckAddedTo.for_notetype(id); self.get_config_optional(key.as_str()) } - pub(crate) fn set_last_deck_for_notetype(&mut self, id: NoteTypeID, did: DeckID) -> Result<()> { + pub(crate) fn set_last_deck_for_notetype(&mut self, id: NoteTypeId, did: DeckId) -> Result<()> { let key = NoteTypeConfigKey::LastDeckAddedTo.for_notetype(id); self.set_config(key.as_str(), &did) } } -fn build_aux_notetype_key(ntid: NoteTypeID, key: &str) -> String { +fn build_aux_notetype_key(ntid: NoteTypeId, key: &str) -> String { format!("_nt_{ntid}_{key}", ntid = ntid, key = key) } diff --git a/rslib/src/dbcheck.rs b/rslib/src/dbcheck.rs index 93f67c68b..a81553828 100644 --- a/rslib/src/dbcheck.rs +++ b/rslib/src/dbcheck.rs @@ -4,10 +4,10 @@ use crate::{ collection::Collection, config::SchedulerVersion, - err::{AnkiError, DBErrorKind, Result}, + err::{AnkiError, DbErrorKind, Result}, i18n::I18n, notetype::{ - all_stock_notetypes, AlreadyGeneratedCardInfo, CardGenContext, NoteType, NoteTypeID, + all_stock_notetypes, AlreadyGeneratedCardInfo, CardGenContext, NoteType, NoteTypeId, NoteTypeKind, }, prelude::*, @@ -90,9 +90,9 @@ impl Collection { debug!(self.log, "quick check"); if self.storage.quick_check_corrupt() { debug!(self.log, "quick check failed"); - return Err(AnkiError::DBError { + return Err(AnkiError::DbError { info: self.tr.database_check_corrupt().into(), - kind: DBErrorKind::Corrupt, + kind: DbErrorKind::Corrupt, }); } @@ -283,14 +283,14 @@ impl Collection { fn get_note_fixing_invalid_utf8( &self, - nid: NoteID, + nid: NoteId, out: &mut CheckDatabaseOutput, ) -> Result { match self.storage.get_note(nid) { Ok(note) => Ok(note.unwrap()), Err(err) => match err { - AnkiError::DBError { - kind: DBErrorKind::Utf8, + AnkiError::DbError { + kind: DbErrorKind::Utf8, .. } => { // fix note then fetch again @@ -343,7 +343,7 @@ impl Collection { &mut self, stamp: TimestampMillis, field_count: usize, - previous_id: NoteTypeID, + previous_id: NoteTypeId, ) -> Result> { debug!(self.log, "create recovery notetype"); let extra_cards_required = self @@ -390,7 +390,7 @@ impl Collection { #[cfg(test)] mod test { use super::*; - use crate::{collection::open_test_collection, decks::DeckID, search::SortMode}; + use crate::{collection::open_test_collection, decks::DeckId, search::SortMode}; fn progress_fn(_progress: DatabaseCheckProgress, _throttle: bool) {} @@ -399,7 +399,7 @@ mod test { let mut col = open_test_collection(); let nt = col.get_notetype_by_name("Basic")?.unwrap(); let mut note = nt.new_note(); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; // card properties col.storage @@ -430,7 +430,7 @@ mod test { } ); assert_eq!( - col.storage.get_deck(DeckID(123))?.unwrap().name, + col.storage.get_deck(DeckId(123))?.unwrap().name, "recovered123" ); @@ -484,7 +484,7 @@ mod test { let mut col = open_test_collection(); let nt = col.get_notetype_by_name("Basic")?.unwrap(); let mut note = nt.new_note(); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; // duplicate ordinals let cid = col.search_cards("", SortMode::NoOrder)?[0]; @@ -533,7 +533,7 @@ mod test { let mut col = open_test_collection(); let nt = col.get_notetype_by_name("Basic")?.unwrap(); let mut note = nt.new_note(); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; // excess fields get joined into the last one col.storage @@ -609,7 +609,7 @@ mod test { let mut note = nt.new_note(); note.tags.push("one".into()); note.tags.push("two".into()); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; col.set_tag_expanded("one", true)?; diff --git a/rslib/src/deckconf/mod.rs b/rslib/src/deckconf/mod.rs index 23c13abeb..491354fbc 100644 --- a/rslib/src/deckconf/mod.rs +++ b/rslib/src/deckconf/mod.rs @@ -20,11 +20,11 @@ pub(crate) const INITIAL_EASE_FACTOR_THOUSANDS: u16 = (INITIAL_EASE_FACTOR * 100 mod schema11; -define_newtype!(DeckConfID, i64); +define_newtype!(DeckConfId, i64); #[derive(Debug, PartialEq, Clone)] pub struct DeckConf { - pub id: DeckConfID, + pub id: DeckConfId, pub name: String, pub mtime_secs: TimestampSecs, pub usn: Usn, @@ -34,7 +34,7 @@ pub struct DeckConf { impl Default for DeckConf { fn default() -> Self { DeckConf { - id: DeckConfID(0), + id: DeckConfId(0), name: "".to_string(), mtime_secs: Default::default(), usn: Default::default(), @@ -73,12 +73,12 @@ impl Default for DeckConf { impl Collection { /// If fallback is true, guaranteed to return a deck config. - pub fn get_deck_config(&self, dcid: DeckConfID, fallback: bool) -> Result> { + pub fn get_deck_config(&self, dcid: DeckConfId, fallback: bool) -> Result> { if let Some(conf) = self.storage.get_deck_config(dcid)? { return Ok(Some(conf)); } if fallback { - if let Some(conf) = self.storage.get_deck_config(DeckConfID(1))? { + if let Some(conf) = self.storage.get_deck_config(DeckConfId(1))? { return Ok(Some(conf)); } // if even the default deck config is missing, just return the defaults @@ -109,7 +109,7 @@ impl Collection { } /// Remove a deck configuration. This will force a full sync. - pub(crate) fn remove_deck_config(&self, dcid: DeckConfID) -> Result<()> { + pub(crate) fn remove_deck_config(&self, dcid: DeckConfId) -> Result<()> { if dcid.0 == 1 { return Err(AnkiError::invalid_input("can't delete default conf")); } diff --git a/rslib/src/deckconf/schema11.rs b/rslib/src/deckconf/schema11.rs index 7ed5fedab..34693626d 100644 --- a/rslib/src/deckconf/schema11.rs +++ b/rslib/src/deckconf/schema11.rs @@ -1,7 +1,7 @@ // 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::{DeckConf, DeckConfId, INITIAL_EASE_FACTOR_THOUSANDS}; use crate::backend_proto::deck_config_inner::NewCardOrder; use crate::backend_proto::DeckConfigInner; use crate::{serde::default_on_invalid, timestamp::TimestampSecs, types::Usn}; @@ -16,7 +16,7 @@ use std::collections::HashMap; #[serde(rename_all = "camelCase")] pub struct DeckConfSchema11 { #[serde(deserialize_with = "deserialize_number_from_string")] - pub(crate) id: DeckConfID, + pub(crate) id: DeckConfId, #[serde(rename = "mod", deserialize_with = "deserialize_number_from_string")] pub(crate) mtime: TimestampSecs, pub(crate) name: String, @@ -191,7 +191,7 @@ impl Default for LapseConfSchema11 { impl Default for DeckConfSchema11 { fn default() -> Self { DeckConfSchema11 { - id: DeckConfID(0), + id: DeckConfId(0), mtime: TimestampSecs(0), name: "Default".to_string(), usn: Usn(0), diff --git a/rslib/src/decks/counts.rs b/rslib/src/decks/counts.rs index 80c153daa..7c13302de 100644 --- a/rslib/src/decks/counts.rs +++ b/rslib/src/decks/counts.rs @@ -1,7 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{collection::Collection, decks::DeckID, err::Result}; +use crate::{collection::Collection, decks::DeckId, err::Result}; use std::collections::HashMap; #[derive(Debug)] @@ -18,7 +18,7 @@ impl Collection { days_elapsed: u32, learn_cutoff: u32, limit_to: Option<&str>, - ) -> Result> { + ) -> Result> { self.storage.due_counts( self.scheduler_version(), days_elapsed, diff --git a/rslib/src/decks/filtered.rs b/rslib/src/decks/filtered.rs index 47f5f3efb..c4dc68c28 100644 --- a/rslib/src/decks/filtered.rs +++ b/rslib/src/decks/filtered.rs @@ -24,7 +24,7 @@ impl Deck { filt.preview_delay = 10; filt.reschedule = true; Deck { - id: DeckID(0), + id: DeckId(0), name: "".into(), mtime_secs: TimestampSecs(0), usn: Usn(0), diff --git a/rslib/src/decks/mod.rs b/rslib/src/decks/mod.rs index a60102ed5..6e754c96c 100644 --- a/rslib/src/decks/mod.rs +++ b/rslib/src/decks/mod.rs @@ -15,7 +15,7 @@ pub use crate::backend_proto::{ use crate::{backend_proto as pb, markdown::render_markdown, text::sanitize_html_no_images}; use crate::{ collection::Collection, - deckconf::DeckConfID, + deckconf::DeckConfId, define_newtype, err::{AnkiError, Result}, prelude::*, @@ -27,11 +27,11 @@ pub(crate) use counts::DueCounts; pub use schema11::DeckSchema11; use std::{borrow::Cow, sync::Arc}; -define_newtype!(DeckID, i64); +define_newtype!(DeckId, i64); #[derive(Debug, Clone, PartialEq)] pub struct Deck { - pub id: DeckID, + pub id: DeckId, pub name: String, pub mtime_secs: TimestampSecs, pub usn: Usn, @@ -42,7 +42,7 @@ pub struct Deck { impl Deck { pub fn new_normal() -> Deck { Deck { - id: DeckID(0), + id: DeckId(0), name: "".into(), mtime_secs: TimestampSecs(0), usn: Usn(0), @@ -72,9 +72,9 @@ impl Deck { } /// Returns deck config ID if deck is a normal deck. - pub(crate) fn config_id(&self) -> Option { + pub(crate) fn config_id(&self) -> Option { if let DeckKind::Normal(ref norm) = self.kind { - Some(DeckConfID(norm.config_id)) + Some(DeckConfId(norm.config_id)) } else { None } @@ -197,7 +197,7 @@ pub(crate) fn human_deck_name_to_native(name: &str) -> String { } impl Collection { - pub(crate) fn get_deck(&mut self, did: DeckID) -> Result>> { + pub(crate) fn get_deck(&mut self, did: DeckId) -> Result>> { if let Some(deck) = self.state.deck_cache.get(&did) { return Ok(Some(deck.clone())); } @@ -259,7 +259,7 @@ pub(crate) fn reparented_name(dragged: &str, dropped: Option<&str>) -> Option Result { - self.storage.deck_is_empty(DeckID(1)) + self.storage.deck_is_empty(DeckId(1)) } /// Normalize deck name and rename if not unique. Bumps mtime and usn if @@ -307,7 +307,7 @@ impl Collection { }) } - pub fn rename_deck(&mut self, did: DeckID, new_human_name: &str) -> Result> { + pub fn rename_deck(&mut self, did: DeckId, new_human_name: &str) -> Result> { self.transact(Op::RenameDeck, |col| { let existing_deck = col.storage.get_deck(did)?.ok_or(AnkiError::NotFound)?; let mut deck = existing_deck.clone(); @@ -368,7 +368,7 @@ impl Collection { Ok(()) } - pub(crate) fn recover_missing_deck(&mut self, did: DeckID, usn: Usn) -> Result<()> { + pub(crate) fn recover_missing_deck(&mut self, did: DeckId, usn: Usn) -> Result<()> { let mut deck = Deck::new_normal(); deck.id = did; deck.name = format!("recovered{}", did); @@ -474,12 +474,12 @@ impl Collection { /// Get a deck based on its human name. If you have a machine name, /// use the method in storage instead. - pub(crate) fn get_deck_id(&self, human_name: &str) -> Result> { + pub(crate) fn get_deck_id(&self, human_name: &str) -> Result> { let machine_name = human_deck_name_to_native(&human_name); self.storage.get_deck_id(&machine_name) } - pub fn remove_decks_and_child_decks(&mut self, dids: &[DeckID]) -> Result> { + pub fn remove_decks_and_child_decks(&mut self, dids: &[DeckId]) -> Result> { self.transact(Op::RemoveDeck, |col| { let mut card_count = 0; let usn = col.usn()?; @@ -521,13 +521,13 @@ impl Collection { Ok(card_count) } - fn delete_all_cards_in_normal_deck(&mut self, did: DeckID) -> Result { + fn delete_all_cards_in_normal_deck(&mut self, did: DeckId) -> Result { let cids = self.storage.all_cards_in_single_deck(did)?; self.remove_cards_and_orphaned_notes(&cids)?; Ok(cids.len()) } - pub fn get_all_deck_names(&self, skip_empty_default: bool) -> Result> { + pub fn get_all_deck_names(&self, skip_empty_default: bool) -> Result> { if skip_empty_default && self.default_deck_is_empty()? { Ok(self .storage @@ -540,7 +540,7 @@ impl Collection { } } - pub fn get_all_normal_deck_names(&mut self) -> Result> { + pub fn get_all_normal_deck_names(&mut self) -> Result> { Ok(self .storage .get_all_deck_names()? @@ -582,7 +582,7 @@ impl Collection { &mut self, today: u32, usn: Usn, - did: DeckID, + did: DeckId, new_delta: i32, review_delta: i32, ) -> Result<()> { @@ -605,7 +605,7 @@ impl Collection { pub(crate) fn counts_for_deck_today( &mut self, - did: DeckID, + did: DeckId, ) -> Result { let today = self.current_due_day(0)?; let mut deck = self.storage.get_deck(did)?.ok_or(AnkiError::NotFound)?; @@ -635,8 +635,8 @@ impl Collection { pub fn reparent_decks( &mut self, - deck_ids: &[DeckID], - new_parent: Option, + deck_ids: &[DeckId], + new_parent: Option, ) -> Result> { self.transact(Op::ReparentDeck, |col| { col.reparent_decks_inner(deck_ids, new_parent) @@ -645,8 +645,8 @@ impl Collection { pub fn reparent_decks_inner( &mut self, - deck_ids: &[DeckID], - new_parent: Option, + deck_ids: &[DeckId], + new_parent: Option, ) -> Result { let usn = self.usn()?; let target_deck; diff --git a/rslib/src/decks/schema11.rs b/rslib/src/decks/schema11.rs index 45879dc6b..6b28352ff 100644 --- a/rslib/src/decks/schema11.rs +++ b/rslib/src/decks/schema11.rs @@ -1,7 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use super::DeckID; +use super::DeckId; use super::{ human_deck_name_to_native, Deck, DeckCommon, DeckKind, FilteredDeck, FilteredSearchTerm, NormalDeck, @@ -82,7 +82,7 @@ fn is_false(b: &bool) -> bool { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct DeckCommonSchema11 { #[serde(deserialize_with = "deserialize_number_from_string")] - pub(crate) id: DeckID, + pub(crate) id: DeckId, #[serde( rename = "mod", deserialize_with = "deserialize_number_from_string", @@ -195,7 +195,7 @@ impl DeckSchema11 { // } // } - pub fn id(&self) -> DeckID { + pub fn id(&self) -> DeckId { self.common().id } @@ -214,7 +214,7 @@ impl Default for NormalDeckSchema11 { fn default() -> Self { NormalDeckSchema11 { common: DeckCommonSchema11 { - id: DeckID(0), + id: DeckId(0), mtime: TimestampSecs(0), name: "".to_string(), usn: Usn(0), diff --git a/rslib/src/decks/tree.rs b/rslib/src/decks/tree.rs index 683e18f9b..01d729613 100644 --- a/rslib/src/decks/tree.rs +++ b/rslib/src/decks/tree.rs @@ -6,8 +6,8 @@ use crate::{ backend_proto::DeckTreeNode, collection::Collection, config::{BoolKey, SchedulerVersion}, - deckconf::{DeckConf, DeckConfID}, - decks::DeckID, + deckconf::{DeckConf, DeckConfId}, + decks::DeckId, err::Result, timestamp::TimestampSecs, }; @@ -18,7 +18,7 @@ use std::{ }; use unicase::UniCase; -fn deck_names_to_tree(names: Vec<(DeckID, String)>) -> DeckTreeNode { +fn deck_names_to_tree(names: Vec<(DeckId, String)>) -> DeckTreeNode { let mut top = DeckTreeNode::default(); let mut it = names.into_iter().peekable(); @@ -28,7 +28,7 @@ fn deck_names_to_tree(names: Vec<(DeckID, String)>) -> DeckTreeNode { } fn add_child_nodes( - names: &mut Peekable>, + names: &mut Peekable>, parent: &mut DeckTreeNode, ) { while let Some((id, name)) = names.peek() { @@ -64,10 +64,10 @@ fn add_child_nodes( fn add_collapsed_and_filtered( node: &mut DeckTreeNode, - decks: &HashMap, + decks: &HashMap, browser: bool, ) { - if let Some(deck) = decks.get(&DeckID(node.deck_id)) { + if let Some(deck) = decks.get(&DeckId(node.deck_id)) { node.collapsed = if browser { deck.common.browser_collapsed } else { @@ -80,8 +80,8 @@ fn add_collapsed_and_filtered( } } -fn add_counts(node: &mut DeckTreeNode, counts: &HashMap) { - if let Some(counts) = counts.get(&DeckID(node.deck_id)) { +fn add_counts(node: &mut DeckTreeNode, counts: &HashMap) { + if let Some(counts) = counts.get(&DeckId(node.deck_id)) { node.new_count = counts.new; node.review_count = counts.review; node.learn_count = counts.learning; @@ -96,12 +96,12 @@ fn add_counts(node: &mut DeckTreeNode, counts: &HashMap) { fn apply_limits( node: &mut DeckTreeNode, today: u32, - decks: &HashMap, - dconf: &HashMap, + decks: &HashMap, + dconf: &HashMap, parent_limits: (u32, u32), ) { let (mut remaining_new, mut remaining_rev) = - remaining_counts_for_deck(DeckID(node.deck_id), today, decks, dconf); + remaining_counts_for_deck(DeckId(node.deck_id), today, decks, dconf); // cap remaining to parent limits remaining_new = remaining_new.min(parent_limits.0); @@ -130,14 +130,14 @@ fn apply_limits( fn apply_limits_v2_old( node: &mut DeckTreeNode, today: u32, - decks: &HashMap, - dconf: &HashMap, + decks: &HashMap, + dconf: &HashMap, parent_limits: (u32, u32), ) -> u32 { let original_rev_count = node.review_count; let (mut remaining_new, remaining_rev) = - remaining_counts_for_deck(DeckID(node.deck_id), today, decks, dconf); + remaining_counts_for_deck(DeckId(node.deck_id), today, decks, dconf); // cap remaining to parent limits remaining_new = remaining_new.min(parent_limits.0); @@ -161,18 +161,18 @@ fn apply_limits_v2_old( } fn remaining_counts_for_deck( - did: DeckID, + did: DeckId, today: u32, - decks: &HashMap, - dconf: &HashMap, + decks: &HashMap, + dconf: &HashMap, ) -> (u32, u32) { if let Some(deck) = decks.get(&did) { match &deck.kind { DeckKind::Normal(norm) => { let (new_today, rev_today) = deck.new_rev_counts(today); if let Some(conf) = dconf - .get(&DeckConfID(norm.config_id)) - .or_else(|| dconf.get(&DeckConfID(1))) + .get(&DeckConfId(norm.config_id)) + .or_else(|| dconf.get(&DeckConfId(1))) { let new = (conf.inner.new_per_day as i32) .saturating_sub(new_today) @@ -212,7 +212,7 @@ fn hide_default_deck(node: &mut DeckTreeNode) { } } -fn get_subnode(top: DeckTreeNode, target: DeckID) -> Option { +fn get_subnode(top: DeckTreeNode, target: DeckId) -> Option { if top.deck_id == target.0 { return Some(top); } @@ -257,7 +257,7 @@ impl Collection { pub fn deck_tree( &mut self, now: Option, - top_deck_id: Option, + top_deck_id: Option, ) -> Result { let names = self.storage.get_all_deck_names()?; let mut tree = deck_names_to_tree(names); @@ -317,7 +317,7 @@ impl Collection { Ok(LegacyDueCounts::from(tree)) } - pub(crate) fn add_missing_deck_names(&mut self, names: &[(DeckID, String)]) -> Result { + pub(crate) fn add_missing_deck_names(&mut self, names: &[(DeckId, String)]) -> Result { let mut parents = HashSet::new(); let mut missing = 0; for (_id, name) in names { @@ -338,7 +338,7 @@ impl Collection { #[cfg(test)] mod test { use super::*; - use crate::{collection::open_test_collection, deckconf::DeckConfID, err::Result}; + use crate::{collection::open_test_collection, deckconf::DeckConfId, err::Result}; #[test] fn wellformed() -> Result<()> { @@ -410,7 +410,7 @@ mod test { assert_eq!(tree.children[0].children[0].new_count, 4); // set the limit to 4, which should mean 3 are left - let mut conf = col.get_deck_config(DeckConfID(1), false)?.unwrap(); + let mut conf = col.get_deck_config(DeckConfId(1), false)?.unwrap(); conf.inner.new_per_day = 4; col.add_or_update_deck_config(&mut conf, false)?; diff --git a/rslib/src/decks/undo.rs b/rslib/src/decks/undo.rs index 8d019ffb2..39cdfaf14 100644 --- a/rslib/src/decks/undo.rs +++ b/rslib/src/decks/undo.rs @@ -9,8 +9,8 @@ pub(crate) enum UndoableDeckChange { Added(Box), Updated(Box), Removed(Box), - GraveAdded(Box<(DeckID, Usn)>), - GraveRemoved(Box<(DeckID, Usn)>), + GraveAdded(Box<(DeckId, Usn)>), + GraveRemoved(Box<(DeckId, Usn)>), } impl Collection { @@ -84,12 +84,12 @@ impl Collection { Ok(()) } - fn add_deck_grave_undoable(&mut self, did: DeckID, usn: Usn) -> Result<()> { + fn add_deck_grave_undoable(&mut self, did: DeckId, usn: Usn) -> Result<()> { self.save_undo(UndoableDeckChange::GraveAdded(Box::new((did, usn)))); self.storage.add_deck_grave(did, usn) } - fn remove_deck_grave(&mut self, did: DeckID, usn: Usn) -> Result<()> { + fn remove_deck_grave(&mut self, did: DeckId, usn: Usn) -> Result<()> { self.save_undo(UndoableDeckChange::GraveRemoved(Box::new((did, usn)))); self.storage.remove_deck_grave(did) } diff --git a/rslib/src/err.rs b/rslib/src/err.rs index 8162576a0..f09b0203d 100644 --- a/rslib/src/err.rs +++ b/rslib/src/err.rs @@ -22,10 +22,10 @@ pub enum AnkiError { TemplateSaveError { ordinal: usize }, #[fail(display = "I/O error: {}", info)] - IOError { info: String }, + IoError { info: String }, #[fail(display = "DB error: {}", info)] - DBError { info: String, kind: DBErrorKind }, + DbError { info: String, kind: DbErrorKind }, #[fail(display = "Network error: {:?} {}", kind, info)] NetworkError { @@ -37,7 +37,7 @@ pub enum AnkiError { SyncError { info: String, kind: SyncErrorKind }, #[fail(display = "JSON encode/decode error: {}", info)] - JSONError { info: String }, + JsonError { info: String }, #[fail(display = "Protobuf encode/decode error: {}", info)] ProtoError { info: String }, @@ -123,9 +123,9 @@ impl AnkiError { AnkiError::TemplateSaveError { ordinal } => tr .card_templates_invalid_template_number(ordinal + 1) .into(), - AnkiError::DBError { info, kind } => match kind { - DBErrorKind::Corrupt => info.clone(), - DBErrorKind::Locked => "Anki already open, or media currently syncing.".into(), + AnkiError::DbError { info, kind } => match kind { + DbErrorKind::Corrupt => info.clone(), + DbErrorKind::Locked => "Anki already open, or media currently syncing.".into(), _ => format!("{:?}", self), }, AnkiError::SearchError(kind) => { @@ -220,7 +220,7 @@ pub enum TemplateError { impl From for AnkiError { fn from(err: io::Error) -> Self { - AnkiError::IOError { + AnkiError::IoError { info: format!("{:?}", err), } } @@ -230,18 +230,18 @@ impl From for AnkiError { fn from(err: rusqlite::Error) -> Self { if let rusqlite::Error::SqliteFailure(error, Some(reason)) = &err { if error.code == rusqlite::ErrorCode::DatabaseBusy { - return AnkiError::DBError { + return AnkiError::DbError { info: "".to_string(), - kind: DBErrorKind::Locked, + kind: DbErrorKind::Locked, }; } if reason.contains("regex parse error") { return AnkiError::SearchError(SearchErrorKind::Regex(reason.to_owned())); } } - AnkiError::DBError { + AnkiError::DbError { info: format!("{:?}", err), - kind: DBErrorKind::Other, + kind: DbErrorKind::Other, } } } @@ -250,15 +250,15 @@ impl From for AnkiError { fn from(err: rusqlite::types::FromSqlError) -> Self { if let rusqlite::types::FromSqlError::Other(ref err) = err { if let Some(_err) = err.downcast_ref::() { - return AnkiError::DBError { + return AnkiError::DbError { info: "".to_string(), - kind: DBErrorKind::Utf8, + kind: DbErrorKind::Utf8, }; } } - AnkiError::DBError { + AnkiError::DbError { info: format!("{:?}", err), - kind: DBErrorKind::Other, + kind: DbErrorKind::Other, } } } @@ -373,7 +373,7 @@ impl From for AnkiError { impl From for AnkiError { fn from(err: serde_json::Error) -> Self { - AnkiError::JSONError { + AnkiError::JsonError { info: err.to_string(), } } @@ -396,7 +396,7 @@ impl From for AnkiError { } #[derive(Debug, PartialEq)] -pub enum DBErrorKind { +pub enum DbErrorKind { FileTooNew, FileTooOld, MissingEntity, @@ -408,7 +408,7 @@ pub enum DBErrorKind { impl From for AnkiError { fn from(e: PathPersistError) -> Self { - AnkiError::IOError { + AnkiError::IoError { info: e.to_string(), } } diff --git a/rslib/src/findreplace.rs b/rslib/src/findreplace.rs index a52ef2307..84fd2e519 100644 --- a/rslib/src/findreplace.rs +++ b/rslib/src/findreplace.rs @@ -4,7 +4,7 @@ use crate::{ collection::Collection, err::{AnkiError, Result}, - notes::{NoteID, TransformNoteOutput}, + notes::{NoteId, TransformNoteOutput}, prelude::*, text::normalize_to_nfc, }; @@ -12,7 +12,7 @@ use regex::Regex; use std::borrow::Cow; pub struct FindReplaceContext { - nids: Vec, + nids: Vec, search: Regex, replacement: String, field_name: Option, @@ -20,7 +20,7 @@ pub struct FindReplaceContext { impl FindReplaceContext { pub fn new( - nids: Vec, + nids: Vec, search_re: &str, repl: impl Into, field_name: Option, @@ -41,7 +41,7 @@ impl FindReplaceContext { impl Collection { pub fn find_and_replace( &mut self, - nids: Vec, + nids: Vec, search_re: &str, repl: &str, field_name: Option, @@ -101,7 +101,7 @@ impl Collection { #[cfg(test)] mod test { use super::*; - use crate::{collection::open_test_collection, decks::DeckID}; + use crate::{collection::open_test_collection, decks::DeckId}; #[test] fn findreplace() -> Result<()> { @@ -111,12 +111,12 @@ mod test { let mut note = nt.new_note(); note.set_field(0, "one aaa")?; note.set_field(1, "two aaa")?; - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; let nt = col.get_notetype_by_name("Cloze")?.unwrap(); let mut note2 = nt.new_note(); note2.set_field(0, "three aaa")?; - col.add_note(&mut note2, DeckID(1))?; + col.add_note(&mut note2, DeckId(1))?; let nids = col.search_notes("")?; let out = col.find_and_replace(nids.clone(), "(?i)AAA", "BBB", None)?; diff --git a/rslib/src/media/changetracker.rs b/rslib/src/media/changetracker.rs index 9dac17115..642d1c6f7 100644 --- a/rslib/src/media/changetracker.rs +++ b/rslib/src/media/changetracker.rs @@ -151,7 +151,7 @@ where } // add entry to the list - let data = sha1_of_file(&dentry.path()).map_err(|e| AnkiError::IOError { + let data = sha1_of_file(&dentry.path()).map_err(|e| AnkiError::IoError { info: format!("unable to read {}: {}", fname, e), })?; let sha1 = Some(data); diff --git a/rslib/src/media/check.rs b/rslib/src/media/check.rs index 0cb32e5ee..8d5037d02 100644 --- a/rslib/src/media/check.rs +++ b/rslib/src/media/check.rs @@ -2,7 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use crate::collection::Collection; -use crate::err::{AnkiError, DBErrorKind, Result}; +use crate::err::{AnkiError, DbErrorKind, Result}; use crate::latex::extract_latex_expanding_clozes; use crate::log::debug; use crate::media::database::MediaDatabaseContext; @@ -362,9 +362,9 @@ where let mut note = self.ctx.storage.get_note(nid)?.unwrap(); let nt = note_types .get(¬e.notetype_id) - .ok_or_else(|| AnkiError::DBError { + .ok_or_else(|| AnkiError::DbError { info: "missing note type".to_string(), - kind: DBErrorKind::MissingEntity, + kind: DbErrorKind::MissingEntity, })?; if fix_and_extract_media_refs( &mut note, diff --git a/rslib/src/media/files.rs b/rslib/src/media/files.rs index 0ef45a7af..46b588b10 100644 --- a/rslib/src/media/files.rs +++ b/rslib/src/media/files.rs @@ -412,7 +412,7 @@ pub(super) fn data_for_file(media_folder: &Path, fname: &str) -> Result R::None, + ("", "", L::NotInDb) => R::None, // both deleted, in local DB ("", "", _) => R::Delete, // added on server, add even if local deletion pending ("", _, _) => R::Download, // deleted on server but added locally; upload later - (_, "", L::InDBAndPending) => R::None, + (_, "", L::InDbAndPending) => R::None, // deleted on server and not pending sync (_, "", _) => R::Delete, // if pending but the same as server, don't need to upload - (lsum, rsum, L::InDBAndPending) if lsum == rsum => R::RemovePending, + (lsum, rsum, L::InDbAndPending) if lsum == rsum => R::RemovePending, (lsum, rsum, _) => { if lsum == rsum { // not pending and same as server, nothing to do @@ -510,12 +510,12 @@ fn determine_required_changes<'a>( None => "".to_string(), }, if entry.sync_required { - LocalState::InDBAndPending + LocalState::InDbAndPending } else { - LocalState::InDBNotPending + LocalState::InDbNotPending }, ), - None => ("".to_string(), LocalState::NotInDB), + None => ("".to_string(), LocalState::NotInDb), }; let req_change = determine_required_change(&local_sha1, &remote.sha1, local_state); @@ -855,14 +855,14 @@ mod test { use determine_required_change as d; use LocalState as L; use RequiredChange as R; - assert_eq!(d("", "", L::NotInDB), R::None); - assert_eq!(d("", "", L::InDBNotPending), R::Delete); - assert_eq!(d("", "1", L::InDBAndPending), R::Download); - assert_eq!(d("1", "", L::InDBAndPending), R::None); - assert_eq!(d("1", "", L::InDBNotPending), R::Delete); - assert_eq!(d("1", "1", L::InDBNotPending), R::None); - assert_eq!(d("1", "1", L::InDBAndPending), R::RemovePending); - assert_eq!(d("a", "b", L::InDBAndPending), R::Download); - assert_eq!(d("a", "b", L::InDBNotPending), R::Download); + assert_eq!(d("", "", L::NotInDb), R::None); + assert_eq!(d("", "", L::InDbNotPending), R::Delete); + assert_eq!(d("", "1", L::InDbAndPending), R::Download); + assert_eq!(d("1", "", L::InDbAndPending), R::None); + assert_eq!(d("1", "", L::InDbNotPending), R::Delete); + assert_eq!(d("1", "1", L::InDbNotPending), R::None); + assert_eq!(d("1", "1", L::InDbAndPending), R::RemovePending); + assert_eq!(d("a", "b", L::InDbAndPending), R::Download); + assert_eq!(d("a", "b", L::InDbNotPending), R::Download); } } diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index 4522400f6..b80b83879 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -5,10 +5,10 @@ pub(crate) mod undo; use crate::{ backend_proto as pb, - decks::DeckID, + decks::DeckId, define_newtype, err::{AnkiError, Result}, - notetype::{CardGenContext, NoteField, NoteType, NoteTypeID}, + notetype::{CardGenContext, NoteField, NoteType, NoteTypeId}, prelude::*, template::field_is_empty, text::{ensure_string_in_nfc, normalize_to_nfc, strip_html_preserving_media_filenames}, @@ -26,7 +26,7 @@ use std::{ convert::TryInto, }; -define_newtype!(NoteID, i64); +define_newtype!(NoteId, i64); #[derive(Default)] pub(crate) struct TransformNoteOutput { @@ -37,9 +37,9 @@ pub(crate) struct TransformNoteOutput { #[derive(Debug, PartialEq, Clone)] pub struct Note { - pub id: NoteID, + pub id: NoteId, pub guid: String, - pub notetype_id: NoteTypeID, + pub notetype_id: NoteTypeId, pub mtime: TimestampSecs, pub usn: Usn, pub tags: Vec, @@ -52,7 +52,7 @@ pub struct Note { /// Tags are stored in their DB form, separated by spaces. #[derive(Debug, PartialEq, Clone)] pub(crate) struct NoteTags { - pub id: NoteID, + pub id: NoteId, pub mtime: TimestampSecs, pub usn: Usn, pub tags: String, @@ -68,7 +68,7 @@ impl NoteTags { impl Note { pub(crate) fn new(notetype: &NoteType) -> Self { Note { - id: NoteID(0), + id: NoteId(0), guid: guid(), notetype_id: notetype.id, mtime: TimestampSecs(0), @@ -82,9 +82,9 @@ impl Note { #[allow(clippy::clippy::too_many_arguments)] pub(crate) fn new_from_storage( - id: NoteID, + id: NoteId, guid: String, - notetype_id: NoteTypeID, + notetype_id: NoteTypeId, mtime: TimestampSecs, usn: Usn, tags: Vec, @@ -241,9 +241,9 @@ impl From for pb::Note { impl From for Note { fn from(n: pb::Note) -> Self { Note { - id: NoteID(n.id), + id: NoteId(n.id), guid: n.guid, - notetype_id: NoteTypeID(n.notetype_id), + notetype_id: NoteTypeId(n.notetype_id), mtime: TimestampSecs(n.mtime_secs as i64), usn: Usn(n.usn), tags: n.tags, @@ -291,7 +291,7 @@ impl Collection { Ok(()) } - pub fn add_note(&mut self, note: &mut Note, did: DeckID) -> Result> { + pub fn add_note(&mut self, note: &mut Note, did: DeckId) -> Result> { self.transact(Op::AddNote, |col| { let nt = col .get_notetype(note.notetype_id)? @@ -306,7 +306,7 @@ impl Collection { &mut self, ctx: &CardGenContext, note: &mut Note, - did: DeckID, + did: DeckId, normalize_text: bool, ) -> Result<()> { self.canonify_note_tags(note, ctx.usn)?; @@ -402,7 +402,7 @@ impl Collection { } /// Remove provided notes, and any cards that use them. - pub(crate) fn remove_notes(&mut self, nids: &[NoteID]) -> Result> { + pub(crate) fn remove_notes(&mut self, nids: &[NoteId]) -> Result> { let usn = self.usn()?; self.transact(Op::RemoveNote, |col| { for nid in nids { @@ -422,7 +422,7 @@ impl Collection { /// If gencards is false, skip card generation. pub fn after_note_updates( &mut self, - nids: &[NoteID], + nids: &[NoteId], generate_cards: bool, mark_notes_modified: bool, ) -> Result> { @@ -440,7 +440,7 @@ impl Collection { pub(crate) fn transform_notes( &mut self, - nids: &[NoteID], + nids: &[NoteId], mut transformer: F, ) -> Result where @@ -528,7 +528,7 @@ impl Collection { /// Fixme: this currently pulls in the note type, and does more work than necessary. We /// could add a separate method to the storage layer to just update the tags in the future, /// though it does slightly complicate the undo story. - pub(crate) fn update_note_tags(&mut self, nid: NoteID, mutator: F) -> Result<()> + pub(crate) fn update_note_tags(&mut self, nid: NoteId, mutator: F) -> Result<()> where F: Fn(&mut Vec), { @@ -570,7 +570,7 @@ fn note_differs_from_db(existing_note: &mut Note, note: &mut Note) -> bool { mod test { use super::{anki_base91, field_checksum}; use crate::{ - collection::open_test_collection, config::BoolKey, decks::DeckID, err::Result, prelude::*, + collection::open_test_collection, config::BoolKey, decks::DeckId, err::Result, prelude::*, search::SortMode, }; @@ -598,7 +598,7 @@ mod test { let mut note = nt.new_note(); // if no cards are generated, 1 card is added - col.add_note(&mut note, DeckID(1)).unwrap(); + col.add_note(&mut note, DeckId(1)).unwrap(); let existing = col.storage.existing_cards_for_note(note.id)?; assert_eq!(existing.len(), 1); assert_eq!(existing[0].ord, 0); @@ -620,11 +620,11 @@ mod test { // cloze cards also generate card 0 if no clozes are found let nt = col.get_notetype_by_name("cloze")?.unwrap(); let mut note = nt.new_note(); - col.add_note(&mut note, DeckID(1)).unwrap(); + col.add_note(&mut note, DeckId(1)).unwrap(); let existing = col.storage.existing_cards_for_note(note.id)?; assert_eq!(existing.len(), 1); assert_eq!(existing[0].ord, 0); - assert_eq!(existing[0].original_deck_id, DeckID(1)); + assert_eq!(existing[0].original_deck_id, DeckId(1)); // and generate cards for any cloze deletions note.fields[0] = "{{c1::foo}} {{c2::bar}} {{c3::baz}} {{c0::quux}} {{c501::over}}".into(); @@ -644,7 +644,7 @@ mod test { let nt = col.get_notetype_by_name("Basic")?.unwrap(); let mut note = nt.new_note(); note.fields[0] = "\u{fa47}".into(); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; assert_eq!(note.fields[0], "\u{6f22}"); // non-normalized searches should be converted assert_eq!(col.search_cards("\u{fa47}", SortMode::NoOrder)?.len(), 1); @@ -659,7 +659,7 @@ mod test { let mut note = nt.new_note(); note.fields[0] = "\u{fa47}".into(); col.set_config(BoolKey::NormalizeNoteText, &false).unwrap(); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; assert_eq!(note.fields[0], "\u{fa47}"); // normalized searches won't match assert_eq!(col.search_cards("\u{6f22}", SortMode::NoOrder)?.len(), 0); @@ -704,7 +704,7 @@ mod test { note.set_field(0, "a")?; note.set_field(1, "b")?; - col.add_note(&mut note, DeckID(1)).unwrap(); + col.add_note(&mut note, DeckId(1)).unwrap(); assert_after_add(&mut col)?; col.undo()?; diff --git a/rslib/src/notes/undo.rs b/rslib/src/notes/undo.rs index c79ebceda..0bea9912f 100644 --- a/rslib/src/notes/undo.rs +++ b/rslib/src/notes/undo.rs @@ -10,8 +10,8 @@ pub(crate) enum UndoableNoteChange { Added(Box), Updated(Box), Removed(Box), - GraveAdded(Box<(NoteID, Usn)>), - GraveRemoved(Box<(NoteID, Usn)>), + GraveAdded(Box<(NoteId, Usn)>), + GraveRemoved(Box<(NoteId, Usn)>), TagsUpdated(Box), } @@ -49,7 +49,7 @@ impl Collection { } /// Remove a note. Cards must already have been deleted. - pub(crate) fn remove_note_only_undoable(&mut self, nid: NoteID, usn: Usn) -> Result<()> { + pub(crate) fn remove_note_only_undoable(&mut self, nid: NoteId, usn: Usn) -> Result<()> { if let Some(note) = self.storage.get_note(nid)? { self.save_undo(UndoableNoteChange::Removed(Box::new(note))); self.storage.remove_note(nid)?; @@ -112,12 +112,12 @@ impl Collection { Ok(()) } - fn add_note_grave(&mut self, nid: NoteID, usn: Usn) -> Result<()> { + fn add_note_grave(&mut self, nid: NoteId, usn: Usn) -> Result<()> { self.save_undo(UndoableNoteChange::GraveAdded(Box::new((nid, usn)))); self.storage.add_note_grave(nid, usn) } - fn remove_note_grave(&mut self, nid: NoteID, usn: Usn) -> Result<()> { + fn remove_note_grave(&mut self, nid: NoteId, usn: Usn) -> Result<()> { self.save_undo(UndoableNoteChange::GraveRemoved(Box::new((nid, usn)))); self.storage.remove_note_grave(nid) } diff --git a/rslib/src/notetype/cardgen.rs b/rslib/src/notetype/cardgen.rs index e89e37ffa..aeaa2ccae 100644 --- a/rslib/src/notetype/cardgen.rs +++ b/rslib/src/notetype/cardgen.rs @@ -3,13 +3,13 @@ use super::NoteType; use crate::{ - card::{Card, CardID}, + card::{Card, CardId}, cloze::add_cloze_numbers_in_string, collection::Collection, - deckconf::{DeckConf, DeckConfID}, - decks::DeckID, + deckconf::{DeckConf, DeckConfId}, + decks::DeckId, err::{AnkiError, Result}, - notes::{Note, NoteID}, + notes::{Note, NoteId}, notetype::NoteTypeKind, template::ParsedTemplate, types::Usn, @@ -21,17 +21,17 @@ use std::collections::{HashMap, HashSet}; /// Info about an existing card required when generating new cards #[derive(Debug, PartialEq)] pub(crate) struct AlreadyGeneratedCardInfo { - pub id: CardID, - pub nid: NoteID, + pub id: CardId, + pub nid: NoteId, pub ord: u32, - pub original_deck_id: DeckID, + pub original_deck_id: DeckId, pub position_if_new: Option, } #[derive(Debug)] pub(crate) struct CardToGenerate { pub ord: u32, - pub did: Option, + pub did: Option, pub due: Option, } @@ -39,7 +39,7 @@ pub(crate) struct CardToGenerate { /// and which deck it should be placed in. pub(crate) struct SingleCardGenContext { template: Option, - target_deck_id: Option, + target_deck_id: Option, } /// Info required to determine which cards should be generated when note added/updated, @@ -54,7 +54,7 @@ pub(crate) struct CardGenContext<'a> { #[derive(Default)] pub(crate) struct CardGenCache { next_position: Option, - deck_configs: HashMap, + deck_configs: HashMap, } impl CardGenContext<'_> { @@ -169,7 +169,7 @@ impl CardGenContext<'_> { // this could be reworked in the future to avoid the extra vec allocation pub(super) fn group_generated_cards_by_note( items: Vec, -) -> Vec<(NoteID, Vec)> { +) -> Vec<(NoteId, Vec)> { let mut out = vec![]; for (key, group) in &items.into_iter().group_by(|c| c.nid) { out.push((key, group.collect())); @@ -182,7 +182,7 @@ pub(crate) struct ExtractedCardInfo { // if set, the due position new cards should be given pub due: Option, // if set, the deck all current cards are in - pub deck_id: Option, + pub deck_id: Option, pub existing_ords: HashSet, } @@ -214,7 +214,7 @@ impl Collection { &mut self, ctx: &CardGenContext, note: &Note, - target_deck_id: DeckID, + target_deck_id: DeckId, ) -> Result<()> { self.generate_cards_for_note( ctx, @@ -245,7 +245,7 @@ impl Collection { ctx: &CardGenContext, note: &Note, existing: &[AlreadyGeneratedCardInfo], - target_deck_id: Option, + target_deck_id: Option, cache: &mut CardGenCache, ) -> Result<()> { let cards = ctx.new_cards_required(note, &existing, true); @@ -277,9 +277,9 @@ impl Collection { pub(crate) fn add_generated_cards( &mut self, - nid: NoteID, + nid: NoteId, cards: &[CardToGenerate], - target_deck_id: Option, + target_deck_id: Option, cache: &mut CardGenCache, ) -> Result<()> { for c in cards { @@ -301,8 +301,8 @@ impl Collection { #[allow(clippy::map_entry)] fn due_for_deck( &mut self, - did: DeckID, - dcid: DeckConfID, + did: DeckId, + dcid: DeckConfId, cache: &mut CardGenCache, ) -> Result { if !cache.deck_configs.contains_key(&did) { @@ -322,7 +322,7 @@ impl Collection { } /// If deck ID does not exist or points to a filtered deck, fall back on default. - fn deck_for_adding(&mut self, did: Option) -> Result<(DeckID, DeckConfID)> { + fn deck_for_adding(&mut self, did: Option) -> Result<(DeckId, DeckConfId)> { if let Some(did) = did { if let Some(deck) = self.deck_conf_if_normal(did)? { return Ok(deck); @@ -332,15 +332,15 @@ impl Collection { self.default_deck_conf() } - fn default_deck_conf(&mut self) -> Result<(DeckID, DeckConfID)> { + fn default_deck_conf(&mut self) -> Result<(DeckId, DeckConfId)> { // currently hard-coded to 1, we could create this as needed in the future Ok(self - .deck_conf_if_normal(DeckID(1))? + .deck_conf_if_normal(DeckId(1))? .ok_or_else(|| AnkiError::invalid_input("invalid default deck"))?) } /// If deck exists and and is a normal deck, return its ID and config - fn deck_conf_if_normal(&mut self, did: DeckID) -> Result> { + fn deck_conf_if_normal(&mut self, did: DeckId) -> Result> { Ok(self.get_deck(did)?.and_then(|d| { if let Some(conf_id) = d.config_id() { Some((did, conf_id)) diff --git a/rslib/src/notetype/emptycards.rs b/rslib/src/notetype/emptycards.rs index 0d2c55a37..0960d93df 100644 --- a/rslib/src/notetype/emptycards.rs +++ b/rslib/src/notetype/emptycards.rs @@ -2,16 +2,16 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::{ - cardgen::group_generated_cards_by_note, CardGenContext, NoteType, NoteTypeID, NoteTypeKind, + cardgen::group_generated_cards_by_note, CardGenContext, NoteType, NoteTypeId, NoteTypeKind, }; -use crate::{card::CardID, collection::Collection, err::Result, notes::NoteID}; +use crate::{card::CardId, collection::Collection, err::Result, notes::NoteId}; use std::collections::HashSet; use std::fmt::Write; pub struct EmptyCardsForNote { - pub nid: NoteID, + pub nid: NoteId, // (ordinal, card id) - pub empty: Vec<(u32, CardID)>, + pub empty: Vec<(u32, CardId)>, pub current_count: usize, } @@ -49,7 +49,7 @@ impl Collection { Ok(out) } - pub fn empty_cards(&mut self) -> Result)>> { + pub fn empty_cards(&mut self) -> Result)>> { self.storage .get_all_notetype_names()? .into_iter() @@ -63,7 +63,7 @@ impl Collection { /// Create a report on empty cards. Mutates the provided data to sort ordinals. pub fn empty_cards_report( &mut self, - empty: &mut [(NoteTypeID, Vec)], + empty: &mut [(NoteTypeId, Vec)], ) -> Result { let nts = self.get_all_notetypes()?; let mut buf = String::new(); diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index 7c9498b2d..f3d9d6bc9 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -24,7 +24,7 @@ pub use templates::CardTemplate; use crate::{ collection::Collection, - decks::DeckID, + decks::DeckId, define_newtype, err::{AnkiError, Result}, notes::Note, @@ -40,7 +40,7 @@ use std::{ }; use unicase::UniCase; -define_newtype!(NoteTypeID, i64); +define_newtype!(NoteTypeId, i64); pub(crate) const DEFAULT_CSS: &str = include_str!("styling.css"); pub(crate) const DEFAULT_LATEX_HEADER: &str = include_str!("header.tex"); @@ -48,7 +48,7 @@ pub(crate) const DEFAULT_LATEX_FOOTER: &str = r"\end{document}"; #[derive(Debug, PartialEq)] pub struct NoteType { - pub id: NoteTypeID, + pub id: NoteTypeId, pub name: String, pub mtime_secs: TimestampSecs, pub usn: Usn, @@ -60,7 +60,7 @@ pub struct NoteType { impl Default for NoteType { fn default() -> Self { NoteType { - id: NoteTypeID(0), + id: NoteTypeId(0), name: "".into(), mtime_secs: TimestampSecs(0), usn: Usn(0), @@ -324,8 +324,8 @@ impl NoteType { Note::new(&self) } - pub fn target_deck_id(&self) -> DeckID { - DeckID(self.config.target_deck_id) + pub fn target_deck_id(&self) -> DeckId { + DeckId(self.config.target_deck_id) } fn fix_field_names(&mut self) -> Result<()> { @@ -455,7 +455,7 @@ impl Collection { } } - pub fn get_notetype(&mut self, ntid: NoteTypeID) -> Result>> { + pub fn get_notetype(&mut self, ntid: NoteTypeId) -> Result>> { if let Some(nt) = self.state.notetype_cache.get(&ntid) { return Ok(Some(nt.clone())); } @@ -468,7 +468,7 @@ impl Collection { } } - pub fn get_all_notetypes(&mut self) -> Result>> { + pub fn get_all_notetypes(&mut self) -> Result>> { self.storage .get_all_notetype_names()? .into_iter() @@ -481,7 +481,7 @@ impl Collection { .collect() } - pub fn remove_notetype(&mut self, ntid: NoteTypeID) -> Result<()> { + pub fn remove_notetype(&mut self, ntid: NoteTypeId) -> Result<()> { // fixme: currently the storage layer is taking care of removing the notes and cards, // but we need to do it in this layer in the future for undo handling self.transact_no_undo(|col| { diff --git a/rslib/src/notetype/render.rs b/rslib/src/notetype/render.rs index f0e7334c1..18e55719f 100644 --- a/rslib/src/notetype/render.rs +++ b/rslib/src/notetype/render.rs @@ -3,11 +3,11 @@ use super::{CardTemplate, NoteType, NoteTypeKind}; use crate::{ - card::{Card, CardID}, + card::{Card, CardId}, collection::Collection, err::{AnkiError, Result}, i18n::I18n, - notes::{Note, NoteID}, + notes::{Note, NoteId}, template::{field_is_empty, render_card, ParsedTemplate, RenderedNode}, }; use std::{borrow::Cow, collections::HashMap}; @@ -19,7 +19,7 @@ pub struct RenderCardOutput { impl Collection { /// Render an existing card saved in the database. - pub fn render_existing_card(&mut self, cid: CardID, browser: bool) -> Result { + pub fn render_existing_card(&mut self, cid: CardId, browser: bool) -> Result { let card = self .storage .get_card(cid)? @@ -64,7 +64,7 @@ impl Collection { fn existing_or_synthesized_card( &self, - nid: NoteID, + nid: NoteId, template_ord: Option, card_ord: u16, ) -> Result { diff --git a/rslib/src/notetype/schema11.rs b/rslib/src/notetype/schema11.rs index 79f29a1f2..02f25e5bb 100644 --- a/rslib/src/notetype/schema11.rs +++ b/rslib/src/notetype/schema11.rs @@ -2,7 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use crate::{ - decks::DeckID, + decks::DeckId, notetype::{ CardRequirement, CardTemplate, CardTemplateConfig, NoteField, NoteFieldConfig, NoteType, NoteTypeConfig, @@ -17,7 +17,7 @@ use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_tuple::Serialize_tuple; use std::collections::HashMap; -use super::{CardRequirementKind, NoteTypeID}; +use super::{CardRequirementKind, NoteTypeId}; #[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)] #[repr(u8)] @@ -30,7 +30,7 @@ pub enum NoteTypeKind { #[serde(rename_all = "camelCase")] pub struct NoteTypeSchema11 { #[serde(deserialize_with = "deserialize_number_from_string")] - pub(crate) id: NoteTypeID, + pub(crate) id: NoteTypeId, pub(crate) name: String, #[serde(rename = "type")] pub(crate) kind: NoteTypeKind, @@ -39,7 +39,7 @@ pub struct NoteTypeSchema11 { pub(crate) usn: Usn, pub(crate) sortf: u16, #[serde(deserialize_with = "default_on_invalid")] - pub(crate) did: Option, + pub(crate) did: Option, pub(crate) tmpls: Vec, pub(crate) flds: Vec, #[serde(deserialize_with = "default_on_invalid")] @@ -97,7 +97,7 @@ impl From for NoteType { kind: nt.kind as i32, sort_field_idx: nt.sortf as u32, css: nt.css, - target_deck_id: nt.did.unwrap_or(DeckID(0)).0, + target_deck_id: nt.did.unwrap_or(DeckId(0)).0, latex_pre: nt.latex_pre, latex_post: nt.latex_post, latex_svg: nt.latexsvg, @@ -150,7 +150,7 @@ impl From for NoteTypeSchema11 { did: if c.target_deck_id == 0 { None } else { - Some(DeckID(c.target_deck_id)) + Some(DeckId(c.target_deck_id)) }, tmpls: p.templates.into_iter().map(Into::into).collect(), flds: p.fields.into_iter().map(Into::into).collect(), @@ -265,7 +265,7 @@ pub struct CardTemplateSchema11 { #[serde(default)] pub(crate) bafmt: String, #[serde(deserialize_with = "default_on_invalid", default)] - pub(crate) did: Option, + pub(crate) did: Option, #[serde(default, deserialize_with = "default_on_invalid")] pub(crate) bfont: String, #[serde(default, deserialize_with = "default_on_invalid")] @@ -286,7 +286,7 @@ impl From for CardTemplate { a_format: t.afmt, q_format_browser: t.bqfmt, a_format_browser: t.bafmt, - target_deck_id: t.did.unwrap_or(DeckID(0)).0, + target_deck_id: t.did.unwrap_or(DeckId(0)).0, browser_font_name: t.bfont, browser_font_size: t.bsize as u32, other: other_to_bytes(&t.other), @@ -308,7 +308,7 @@ impl From for CardTemplateSchema11 { bqfmt: conf.q_format_browser, bafmt: conf.a_format_browser, did: if conf.target_deck_id > 0 { - Some(DeckID(conf.target_deck_id)) + Some(DeckId(conf.target_deck_id)) } else { None }, diff --git a/rslib/src/notetype/schemachange.rs b/rslib/src/notetype/schemachange.rs index 2eba11818..48c974d52 100644 --- a/rslib/src/notetype/schemachange.rs +++ b/rslib/src/notetype/schemachange.rs @@ -137,7 +137,7 @@ impl Collection { #[cfg(test)] mod test { use super::{ords_changed, TemplateOrdChanges}; - use crate::{collection::open_test_collection, decks::DeckID, err::Result, search::SortMode}; + use crate::{collection::open_test_collection, decks::DeckId, err::Result, search::SortMode}; #[test] fn ord_changes() { @@ -205,7 +205,7 @@ mod test { assert_eq!(note.fields().len(), 2); note.set_field(0, "one")?; note.set_field(1, "two")?; - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; nt.add_field("three"); col.update_notetype(&mut nt, false)?; @@ -254,7 +254,7 @@ mod test { assert_eq!(note.fields().len(), 2); note.set_field(0, "one")?; note.set_field(1, "two")?; - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; assert_eq!( col.search_cards(&format!("nid:{}", note.id), SortMode::NoOrder) diff --git a/rslib/src/notetype/stock.rs b/rslib/src/notetype/stock.rs index 79f7262f4..c49989105 100644 --- a/rslib/src/notetype/stock.rs +++ b/rslib/src/notetype/stock.rs @@ -19,7 +19,7 @@ impl SqliteStorage { self.add_new_notetype(&mut nt)?; if idx == Kind::Basic as usize { self.set_config_entry(&ConfigEntry::boxed( - ConfigKey::CurrentNoteTypeID.into(), + ConfigKey::CurrentNoteTypeId.into(), serde_json::to_vec(&nt.id)?, self.usn(false)?, TimestampSecs::now(), diff --git a/rslib/src/notetype/templates.rs b/rslib/src/notetype/templates.rs index 1da7c81d0..e7e9434ff 100644 --- a/rslib/src/notetype/templates.rs +++ b/rslib/src/notetype/templates.rs @@ -3,7 +3,7 @@ use crate::{ backend_proto::{CardTemplate as CardTemplateProto, CardTemplateConfig, OptionalUInt32}, - decks::DeckID, + decks::DeckId, err::{AnkiError, Result}, template::ParsedTemplate, timestamp::TimestampSecs, @@ -44,9 +44,9 @@ impl CardTemplate { } } - pub(crate) fn target_deck_id(&self) -> Option { + pub(crate) fn target_deck_id(&self) -> Option { if self.config.target_deck_id > 0 { - Some(DeckID(self.config.target_deck_id)) + Some(DeckId(self.config.target_deck_id)) } else { None } diff --git a/rslib/src/prelude.rs b/rslib/src/prelude.rs index 0def3f554..810616f68 100644 --- a/rslib/src/prelude.rs +++ b/rslib/src/prelude.rs @@ -2,17 +2,17 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html pub use crate::{ - card::{Card, CardID}, + card::{Card, CardId}, collection::Collection, config::BoolKey, - deckconf::{DeckConf, DeckConfID}, - decks::{Deck, DeckID, DeckKind}, + deckconf::{DeckConf, DeckConfId}, + decks::{Deck, DeckId, DeckKind}, err::{AnkiError, Result}, i18n::I18n, - notes::{Note, NoteID}, - notetype::{NoteType, NoteTypeID}, + notes::{Note, NoteId}, + notetype::{NoteType, NoteTypeId}, ops::{Op, OpChanges, OpOutput}, - revlog::RevlogID, + revlog::RevlogId, timestamp::{TimestampMillis, TimestampSecs}, types::Usn, }; diff --git a/rslib/src/revlog/mod.rs b/rslib/src/revlog/mod.rs index 79f73f99f..170e8ac7e 100644 --- a/rslib/src/revlog/mod.rs +++ b/rslib/src/revlog/mod.rs @@ -10,11 +10,11 @@ use serde::Deserialize; use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_tuple::Serialize_tuple; -define_newtype!(RevlogID, i64); +define_newtype!(RevlogId, i64); -impl RevlogID { +impl RevlogId { pub fn new() -> Self { - RevlogID(TimestampMillis::now().0) + RevlogId(TimestampMillis::now().0) } pub fn as_secs(self) -> TimestampSecs { @@ -22,16 +22,16 @@ impl RevlogID { } } -impl From for RevlogID { +impl From for RevlogId { fn from(m: TimestampMillis) -> Self { - RevlogID(m.0) + RevlogId(m.0) } } #[derive(Serialize_tuple, Deserialize, Debug, Default, PartialEq)] pub struct RevlogEntry { - pub id: RevlogID, - pub cid: CardID, + pub id: RevlogId, + pub cid: CardId, pub usn: Usn, /// - In the V1 scheduler, 3 represents easy in the learning case. /// - 0 represents manual rescheduling. @@ -88,7 +88,7 @@ impl Collection { usn: Usn, ) -> Result<()> { let entry = RevlogEntry { - id: RevlogID::new(), + id: RevlogId::new(), cid: card.id, usn, button_chosen: 0, diff --git a/rslib/src/revlog/undo.rs b/rslib/src/revlog/undo.rs index daa3ce50f..24ea6f61a 100644 --- a/rslib/src/revlog/undo.rs +++ b/rslib/src/revlog/undo.rs @@ -27,7 +27,7 @@ impl Collection { } /// Add the provided revlog entry, modifying the ID if it is not unique. - pub(crate) fn add_revlog_entry_undoable(&mut self, mut entry: RevlogEntry) -> Result { + pub(crate) fn add_revlog_entry_undoable(&mut self, mut entry: RevlogEntry) -> Result { entry.id = self.storage.add_revlog_entry(&entry, true)?; let id = entry.id; self.save_undo(UndoableRevlogChange::Added(Box::new(entry))); diff --git a/rslib/src/scheduler/answering/mod.rs b/rslib/src/scheduler/answering/mod.rs index e66460db0..9159f06fe 100644 --- a/rslib/src/scheduler/answering/mod.rs +++ b/rslib/src/scheduler/answering/mod.rs @@ -36,7 +36,7 @@ pub enum Rating { } pub struct CardAnswer { - pub card_id: CardID, + pub card_id: CardId, pub current_state: CardState, pub new_state: CardState, pub rating: Rating, @@ -184,7 +184,7 @@ impl Rating { impl Collection { /// Return the next states that will be applied for each answer button. - pub fn get_next_card_states(&mut self, cid: CardID) -> Result { + pub fn get_next_card_states(&mut self, cid: CardId) -> Result { let card = self.storage.get_card(cid)?.ok_or(AnkiError::NotFound)?; let ctx = self.card_state_updater(card)?; let current = ctx.current_card_state(); @@ -355,8 +355,8 @@ impl Collection { fn home_deck_config( &self, - config_id: Option, - home_deck_id: DeckID, + config_id: Option, + home_deck_id: DeckId, ) -> Result { let config_id = if let Some(config_id) = config_id { config_id @@ -371,7 +371,7 @@ impl Collection { Ok(self.storage.get_deck_config(config_id)?.unwrap_or_default()) } - fn add_leech_tag(&mut self, nid: NoteID) -> Result<()> { + fn add_leech_tag(&mut self, nid: NoteId) -> Result<()> { self.update_note_tags(nid, |tags| tags.push("leech".into())) } } diff --git a/rslib/src/scheduler/answering/preview.rs b/rslib/src/scheduler/answering/preview.rs index b35b87bb9..a7c39c77f 100644 --- a/rslib/src/scheduler/answering/preview.rs +++ b/rslib/src/scheduler/answering/preview.rs @@ -63,7 +63,7 @@ mod test { fn preview() -> Result<()> { let mut col = open_test_collection(); let mut c = Card { - deck_id: DeckID(1), + deck_id: DeckId(1), ctype: CardType::Learn, queue: CardQueue::DayLearn, remaining_steps: 2, diff --git a/rslib/src/scheduler/answering/revlog.rs b/rslib/src/scheduler/answering/revlog.rs index a14f12b12..159cba23e 100644 --- a/rslib/src/scheduler/answering/revlog.rs +++ b/rslib/src/scheduler/answering/revlog.rs @@ -38,7 +38,7 @@ impl RevlogEntryPartial { pub(super) fn into_revlog_entry( self, usn: Usn, - cid: CardID, + cid: CardId, button_chosen: u8, answered_at: TimestampMillis, taken_millis: u32, diff --git a/rslib/src/scheduler/answering/undo.rs b/rslib/src/scheduler/answering/undo.rs index 41ae50815..52f1885db 100644 --- a/rslib/src/scheduler/answering/undo.rs +++ b/rslib/src/scheduler/answering/undo.rs @@ -21,10 +21,10 @@ mod test { let mut note = nt.new_note(); note.set_field(0, "one")?; note.set_field(1, "two")?; - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; // turn burying and leech suspension on - let mut conf = col.storage.get_deck_config(DeckConfID(1))?.unwrap(); + let mut conf = col.storage.get_deck_config(DeckConfId(1))?.unwrap(); conf.inner.bury_new = true; conf.inner.leech_action = LeechAction::Suspend as i32; col.storage.update_deck_conf(&conf)?; @@ -94,7 +94,7 @@ mod test { assert_eq!(note.tags, vec!["leech".to_string()]); assert_eq!(col.storage.all_tags()?.is_empty(), false); - let deck = col.get_deck(DeckID(1))?.unwrap(); + let deck = col.get_deck(DeckId(1))?.unwrap(); assert_eq!(deck.common.review_studied, 1); dbg!(&col.next_card()?); @@ -121,7 +121,7 @@ mod test { assert_eq!(note.tags.is_empty(), true); assert_eq!(col.storage.all_tags()?.is_empty(), true); - let deck = col.get_deck(DeckID(1))?.unwrap(); + let deck = col.get_deck(DeckId(1))?.unwrap(); assert_eq!(deck.common.review_studied, 0); assert_eq!(col.next_card()?.is_some(), true); diff --git a/rslib/src/scheduler/bury_and_suspend.rs b/rslib/src/scheduler/bury_and_suspend.rs index 011589caa..bdc221a19 100644 --- a/rslib/src/scheduler/bury_and_suspend.rs +++ b/rslib/src/scheduler/bury_and_suspend.rs @@ -3,7 +3,7 @@ use crate::{ backend_proto as pb, - card::{Card, CardID, CardQueue}, + card::{Card, CardId, CardQueue}, collection::Collection, config::SchedulerVersion, err::Result, @@ -68,7 +68,7 @@ impl Collection { self.storage.clear_searched_cards_table() } - pub fn unbury_or_unsuspend_cards(&mut self, cids: &[CardID]) -> Result> { + pub fn unbury_or_unsuspend_cards(&mut self, cids: &[CardId]) -> Result> { self.transact(Op::UnburyUnsuspend, |col| { col.storage.set_search_table_to_card_ids(cids, false)?; col.unsuspend_or_unbury_searched_cards() @@ -122,7 +122,7 @@ impl Collection { pub fn bury_or_suspend_cards( &mut self, - cids: &[CardID], + cids: &[CardId], mode: BuryOrSuspendMode, ) -> Result> { let op = match mode { @@ -137,8 +137,8 @@ impl Collection { pub(crate) fn bury_siblings( &mut self, - cid: CardID, - nid: NoteID, + cid: CardId, + nid: NoteId, include_new: bool, include_reviews: bool, ) -> Result<()> { diff --git a/rslib/src/scheduler/filtered/card.rs b/rslib/src/scheduler/filtered/card.rs index 7b2d353b1..0fb5caeea 100644 --- a/rslib/src/scheduler/filtered/card.rs +++ b/rslib/src/scheduler/filtered/card.rs @@ -72,7 +72,7 @@ impl Card { } } - pub(crate) fn original_or_current_deck_id(&self) -> DeckID { + pub(crate) fn original_or_current_deck_id(&self) -> DeckId { if self.original_deck_id.0 > 0 { self.original_deck_id } else { diff --git a/rslib/src/scheduler/filtered/mod.rs b/rslib/src/scheduler/filtered/mod.rs index 6ce8b899d..7d5bd341c 100644 --- a/rslib/src/scheduler/filtered/mod.rs +++ b/rslib/src/scheduler/filtered/mod.rs @@ -18,13 +18,13 @@ use crate::{ /// Contains the parts of a filtered deck required for modifying its settings in /// the UI. pub struct FilteredDeckForUpdate { - pub id: DeckID, + pub id: DeckId, pub human_name: String, pub config: FilteredDeck, } pub(crate) struct DeckFilterContext<'a> { - pub target_deck: DeckID, + pub target_deck: DeckId, pub config: &'a FilteredDeck, pub scheduler: SchedulerVersion, pub usn: Usn, @@ -36,7 +36,7 @@ impl Collection { /// will not be added to the DB. pub fn get_or_create_filtered_deck( &mut self, - deck_id: DeckID, + deck_id: DeckId, ) -> Result { let deck = if deck_id.0 == 0 { self.new_filtered_deck_for_adding()? @@ -55,20 +55,20 @@ impl Collection { pub fn add_or_update_filtered_deck( &mut self, deck: FilteredDeckForUpdate, - ) -> Result> { + ) -> Result> { self.transact(Op::BuildFilteredDeck, |col| { col.add_or_update_filtered_deck_inner(deck) }) } - pub fn empty_filtered_deck(&mut self, did: DeckID) -> Result> { + pub fn empty_filtered_deck(&mut self, did: DeckId) -> Result> { self.transact(Op::EmptyFilteredDeck, |col| { col.return_all_cards_in_filtered_deck(did) }) } // Unlike the old Python code, this also marks the cards as modified. - pub fn rebuild_filtered_deck(&mut self, did: DeckID) -> Result> { + pub fn rebuild_filtered_deck(&mut self, did: DeckId) -> Result> { self.transact(Op::RebuildFilteredDeck, |col| { let deck = col.get_deck(did)?.ok_or(AnkiError::NotFound)?; col.rebuild_filtered_deck_inner(&deck, col.usn()?) @@ -77,13 +77,13 @@ impl Collection { } impl Collection { - pub(crate) fn return_all_cards_in_filtered_deck(&mut self, did: DeckID) -> Result<()> { + pub(crate) fn return_all_cards_in_filtered_deck(&mut self, did: DeckId) -> Result<()> { let cids = self.storage.all_cards_in_single_deck(did)?; self.return_cards_to_home_deck(&cids) } // Unlike the old Python code, this also marks the cards as modified. - fn return_cards_to_home_deck(&mut self, cids: &[CardID]) -> Result<()> { + fn return_cards_to_home_deck(&mut self, cids: &[CardId]) -> Result<()> { let sched = self.scheduler_version(); let usn = self.usn()?; for cid in cids { @@ -150,7 +150,7 @@ impl Collection { fn add_or_update_filtered_deck_inner( &mut self, mut update: FilteredDeckForUpdate, - ) -> Result { + ) -> Result { let usn = self.usn()?; // check the searches are valid, and normalize them @@ -182,7 +182,7 @@ impl Collection { Err(AnkiError::FilteredDeckEmpty) } else { // update current deck and return id - self.set_config(ConfigKey::CurrentDeckID, &deck.id)?; + self.set_config(ConfigKey::CurrentDeckId, &deck.id)?; Ok(deck.id) } } diff --git a/rslib/src/scheduler/new.rs b/rslib/src/scheduler/new.rs index c01913f40..cf2b2e66e 100644 --- a/rslib/src/scheduler/new.rs +++ b/rslib/src/scheduler/new.rs @@ -2,11 +2,11 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use crate::{ - card::{Card, CardID, CardQueue, CardType}, + card::{Card, CardId, CardQueue, CardType}, collection::Collection, - decks::DeckID, + decks::DeckId, err::Result, - notes::NoteID, + notes::NoteId, prelude::*, search::SortMode, types::Usn, @@ -35,7 +35,7 @@ impl Card { } } pub(crate) struct NewCardSorter { - position: HashMap, + position: HashMap, } #[derive(PartialEq)] @@ -71,7 +71,7 @@ impl NewCardSorter { } } -fn nids_in_desired_order(cards: &[Card], order: NewCardSortOrder) -> Vec { +fn nids_in_desired_order(cards: &[Card], order: NewCardSortOrder) -> Vec { if order == NewCardSortOrder::Preserve { nids_in_preserved_order(cards) } else { @@ -90,7 +90,7 @@ fn nids_in_desired_order(cards: &[Card], order: NewCardSortOrder) -> Vec } } -fn nids_in_preserved_order(cards: &[Card]) -> Vec { +fn nids_in_preserved_order(cards: &[Card]) -> Vec { let mut seen = HashSet::new(); cards .iter() @@ -105,7 +105,7 @@ fn nids_in_preserved_order(cards: &[Card]) -> Vec { } impl Collection { - pub fn reschedule_cards_as_new(&mut self, cids: &[CardID], log: bool) -> Result> { + pub fn reschedule_cards_as_new(&mut self, cids: &[CardId], log: bool) -> Result> { let usn = self.usn()?; let mut position = self.get_next_card_position(); self.transact(Op::ScheduleAsNew, |col| { @@ -127,7 +127,7 @@ impl Collection { pub fn sort_cards( &mut self, - cids: &[CardID], + cids: &[CardId], starting_from: u32, step: u32, order: NewCardSortOrder, @@ -141,7 +141,7 @@ impl Collection { fn sort_cards_inner( &mut self, - cids: &[CardID], + cids: &[CardId], starting_from: u32, step: u32, order: NewCardSortOrder, @@ -168,7 +168,7 @@ impl Collection { /// This creates a transaction - we probably want to split it out /// in the future if calling it as part of a deck options update. - pub fn sort_deck(&mut self, deck: DeckID, random: bool) -> Result> { + pub fn sort_deck(&mut self, deck: DeckId, random: bool) -> Result> { let cids = self.search_cards(&format!("did:{} is:new", deck), SortMode::NoOrder)?; let order = if random { NewCardSortOrder::Random @@ -196,11 +196,11 @@ mod test { #[test] fn new_order() { - let mut c1 = Card::new(NoteID(6), 0, DeckID(0), 0); + let mut c1 = Card::new(NoteId(6), 0, DeckId(0), 0); c1.id.0 = 2; - let mut c2 = Card::new(NoteID(5), 0, DeckID(0), 0); + let mut c2 = Card::new(NoteId(5), 0, DeckId(0), 0); c2.id.0 = 3; - let mut c3 = Card::new(NoteID(4), 0, DeckID(0), 0); + let mut c3 = Card::new(NoteId(4), 0, DeckId(0), 0); c3.id.0 = 1; let cards = vec![c1.clone(), c2.clone(), c3.clone()]; diff --git a/rslib/src/scheduler/queue/builder/gathering.rs b/rslib/src/scheduler/queue/builder/gathering.rs index 06838f479..b3e527763 100644 --- a/rslib/src/scheduler/queue/builder/gathering.rs +++ b/rslib/src/scheduler/queue/builder/gathering.rs @@ -100,12 +100,12 @@ impl QueueBuilder { limit.new != 0 } - fn should_add_review_card(&mut self, note_id: NoteID) -> bool { + fn should_add_review_card(&mut self, note_id: NoteId) -> bool { !self.have_seen_note_id(note_id) || !self.bury_reviews } /// Mark note seen, and return true if seen before. - fn have_seen_note_id(&mut self, note_id: NoteID) -> bool { + fn have_seen_note_id(&mut self, note_id: NoteId) -> bool { !self.seen_note_ids.insert(note_id) } } @@ -127,26 +127,26 @@ mod test { let cards = vec![ NewCard { - id: CardID(1), - note_id: NoteID(1), + id: CardId(1), + note_id: NoteId(1), extra: 0, ..Default::default() }, NewCard { - id: CardID(2), - note_id: NoteID(2), + id: CardId(2), + note_id: NoteId(2), extra: 1, ..Default::default() }, NewCard { - id: CardID(3), - note_id: NoteID(2), + id: CardId(3), + note_id: NoteId(2), extra: 2, ..Default::default() }, NewCard { - id: CardID(4), - note_id: NoteID(2), + id: CardId(4), + note_id: NoteId(2), extra: 0, ..Default::default() }, @@ -156,8 +156,8 @@ mod test { builder.add_new_card(&mut limits, card.clone()); } - assert_eq!(builder.new[0].id, CardID(1)); - assert_eq!(builder.new[1].id, CardID(4)); + assert_eq!(builder.new[0].id, CardId(1)); + assert_eq!(builder.new[1].id, CardId(4)); assert_eq!(builder.new.len(), 2); // with burying disabled, we should get all siblings in order @@ -168,9 +168,9 @@ mod test { builder.add_new_card(&mut limits, card.clone()); } - assert_eq!(builder.new[0].id, CardID(1)); - assert_eq!(builder.new[1].id, CardID(4)); - assert_eq!(builder.new[2].id, CardID(2)); - assert_eq!(builder.new[3].id, CardID(3)); + assert_eq!(builder.new[0].id, CardId(1)); + assert_eq!(builder.new[1].id, CardId(4)); + assert_eq!(builder.new[2].id, CardId(2)); + assert_eq!(builder.new[3].id, CardId(3)); } } diff --git a/rslib/src/scheduler/queue/builder/mod.rs b/rslib/src/scheduler/queue/builder/mod.rs index af7d3491e..396479ae8 100644 --- a/rslib/src/scheduler/queue/builder/mod.rs +++ b/rslib/src/scheduler/queue/builder/mod.rs @@ -22,8 +22,8 @@ use {intersperser::Intersperser, sized_chain::SizedChain}; /// Temporary holder for review cards that will be built into a queue. #[derive(Debug, Default, Clone)] pub(crate) struct DueCard { - pub id: CardID, - pub note_id: NoteID, + pub id: CardId, + pub note_id: NoteId, pub mtime: TimestampSecs, pub due: i32, pub interval: u32, @@ -33,8 +33,8 @@ pub(crate) struct DueCard { /// Temporary holder for new cards that will be built into a queue. #[derive(Debug, Default, Clone)] pub(crate) struct NewCard { - pub id: CardID, - pub note_id: NoteID, + pub id: CardId, + pub note_id: NoteId, pub mtime: TimestampSecs, pub due: i32, /// Used to store template_idx, and for shuffling @@ -77,7 +77,7 @@ pub(super) struct QueueBuilder { pub(super) review: Vec, pub(super) learning: Vec, pub(super) day_learning: Vec, - pub(super) seen_note_ids: HashSet, + pub(super) seen_note_ids: HashSet, pub(super) new_order: NewCardOrder, pub(super) review_order: ReviewCardOrder, pub(super) day_learn_mix: ReviewMix, @@ -91,7 +91,7 @@ impl QueueBuilder { mut self, top_deck_limits: RemainingLimits, learn_ahead_secs: u32, - selected_deck: DeckID, + selected_deck: DeckId, current_day: u32, ) -> CardQueues { self.sort_new(); @@ -189,7 +189,7 @@ fn split_learning( } impl Collection { - pub(crate) fn build_queues(&mut self, deck_id: DeckID) -> Result { + pub(crate) fn build_queues(&mut self, deck_id: DeckId) -> Result { let now = TimestampSecs::now(); let timing = self.timing_for_timestamp(now)?; let (decks, parent_count) = self.storage.deck_with_parents_and_children(deck_id)?; diff --git a/rslib/src/scheduler/queue/entry.rs b/rslib/src/scheduler/queue/entry.rs index ec80b083f..e33a73ebf 100644 --- a/rslib/src/scheduler/queue/entry.rs +++ b/rslib/src/scheduler/queue/entry.rs @@ -12,7 +12,7 @@ pub(crate) enum QueueEntry { } impl QueueEntry { - pub fn card_id(&self) -> CardID { + pub fn card_id(&self) -> CardId { match self { QueueEntry::IntradayLearning(e) => e.id, QueueEntry::Main(e) => e.id, diff --git a/rslib/src/scheduler/queue/learning.rs b/rslib/src/scheduler/queue/learning.rs index e00764b8a..3d2cea37b 100644 --- a/rslib/src/scheduler/queue/learning.rs +++ b/rslib/src/scheduler/queue/learning.rs @@ -13,7 +13,7 @@ use crate::{prelude::*, scheduler::timing::SchedTimingToday}; pub(crate) struct LearningQueueEntry { // due comes first, so the derived ordering sorts by due pub due: TimestampSecs, - pub id: CardID, + pub id: CardId, pub mtime: TimestampSecs, } @@ -37,7 +37,7 @@ impl CardQueues { self.due_learning.front().copied() } - pub(super) fn pop_learning_entry(&mut self, id: CardID) -> Option { + pub(super) fn pop_learning_entry(&mut self, id: CardId) -> Option { if let Some(top) = self.due_learning.front() { if top.id == id { self.counts.learning -= 1; @@ -135,7 +135,7 @@ impl CardQueues { } } - pub(super) fn remove_requeued_learning_card_after_undo(&mut self, id: CardID) { + pub(super) fn remove_requeued_learning_card_after_undo(&mut self, id: CardId) { let due_idx = self .due_learning .iter() diff --git a/rslib/src/scheduler/queue/limits.rs b/rslib/src/scheduler/queue/limits.rs index 744f72dec..f5252e36c 100644 --- a/rslib/src/scheduler/queue/limits.rs +++ b/rslib/src/scheduler/queue/limits.rs @@ -2,7 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use super::{Deck, DeckKind}; -use crate::deckconf::{DeckConf, DeckConfID}; +use crate::deckconf::{DeckConf, DeckConfId}; use std::collections::HashMap; #[derive(Clone, Copy, Debug, PartialEq)] @@ -35,7 +35,7 @@ impl RemainingLimits { pub(super) fn remaining_limits_capped_to_parents( decks: &[Deck], - config: &HashMap, + config: &HashMap, today: u32, ) -> Vec { let mut limits = get_remaining_limits(decks, config, today); @@ -47,7 +47,7 @@ pub(super) fn remaining_limits_capped_to_parents( /// the provided deck order. fn get_remaining_limits( decks: &[Deck], - config: &HashMap, + config: &HashMap, today: u32, ) -> Vec { decks @@ -55,7 +55,7 @@ fn get_remaining_limits( .map(move |deck| { // get deck config if not filtered let config = if let DeckKind::Normal(normal) = &deck.kind { - config.get(&DeckConfID(normal.config_id)) + config.get(&DeckConfId(normal.config_id)) } else { None }; diff --git a/rslib/src/scheduler/queue/main.rs b/rslib/src/scheduler/queue/main.rs index 718ba9e5a..c42cc60b6 100644 --- a/rslib/src/scheduler/queue/main.rs +++ b/rslib/src/scheduler/queue/main.rs @@ -6,7 +6,7 @@ use crate::prelude::*; #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct MainQueueEntry { - pub id: CardID, + pub id: CardId, pub mtime: TimestampSecs, pub kind: MainQueueEntryKind, } @@ -22,7 +22,7 @@ impl CardQueues { self.main.front().copied() } - pub(super) fn pop_main_entry(&mut self, id: CardID) -> Option { + pub(super) fn pop_main_entry(&mut self, id: CardId) -> Option { if let Some(last) = self.main.front() { if last.id == id { match last.kind { diff --git a/rslib/src/scheduler/queue/mod.rs b/rslib/src/scheduler/queue/mod.rs index 717120748..7fa4d66e4 100644 --- a/rslib/src/scheduler/queue/mod.rs +++ b/rslib/src/scheduler/queue/mod.rs @@ -38,7 +38,7 @@ pub(crate) struct CardQueues { later_learning: BinaryHeap>, - selected_deck: DeckID, + selected_deck: DeckId, current_day: u32, learn_ahead_secs: i64, } @@ -76,7 +76,7 @@ impl CardQueues { /// Remove the provided card from the top of the queues. /// If it was not at the top, return an error. - fn pop_answered(&mut self, id: CardID) -> Result { + fn pop_answered(&mut self, id: CardId) -> Result { if let Some(entry) = self.pop_undo_entry(id) { Ok(entry) } else if let Some(entry) = self.pop_main_entry(id) { @@ -92,7 +92,7 @@ impl CardQueues { self.counts } - fn is_stale(&self, deck: DeckID, current_day: u32) -> bool { + fn is_stale(&self, deck: DeckId, current_day: u32) -> bool { self.selected_deck != deck || self.current_day != current_day } diff --git a/rslib/src/scheduler/queue/undo.rs b/rslib/src/scheduler/queue/undo.rs index 865a30d7c..5fe5bccf2 100644 --- a/rslib/src/scheduler/queue/undo.rs +++ b/rslib/src/scheduler/queue/undo.rs @@ -51,7 +51,7 @@ impl CardQueues { self.undo.last().copied() } - pub(super) fn pop_undo_entry(&mut self, id: CardID) -> Option { + pub(super) fn pop_undo_entry(&mut self, id: CardId) -> Option { if let Some(last) = self.undo.last() { if last.card_id() == id { match last.kind() { diff --git a/rslib/src/scheduler/reviews.rs b/rslib/src/scheduler/reviews.rs index fdb929438..6dc25c437 100644 --- a/rslib/src/scheduler/reviews.rs +++ b/rslib/src/scheduler/reviews.rs @@ -2,7 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use crate::{ - card::{Card, CardID, CardQueue, CardType}, + card::{Card, CardId, CardQueue, CardType}, collection::Collection, config::StringKey, deckconf::INITIAL_EASE_FACTOR_THOUSANDS, @@ -90,7 +90,7 @@ impl Collection { /// value of `days`. pub fn set_due_date( &mut self, - cids: &[CardID], + cids: &[CardId], days: &str, context: Option, ) -> Result> { @@ -165,7 +165,7 @@ mod test { #[test] fn due_date() { - let mut c = Card::new(NoteID(0), 0, DeckID(0), 0); + let mut c = Card::new(NoteId(0), 0, DeckId(0), 0); // setting the due date of a new card will convert it c.set_due_date(5, 2, false); @@ -191,7 +191,7 @@ mod test { // should work in a filtered deck c.interval = 2; c.original_due = 7; - c.original_deck_id = DeckID(1); + c.original_deck_id = DeckId(1); c.due = -10000; c.queue = CardQueue::New; c.set_due_date(6, 1, false); @@ -199,7 +199,7 @@ mod test { assert_eq!(c.interval, 2); assert_eq!(c.queue, CardQueue::Review); assert_eq!(c.original_due, 0); - assert_eq!(c.original_deck_id, DeckID(0)); + assert_eq!(c.original_deck_id, DeckId(0)); // relearning treated like review c.ctype = CardType::Relearn; diff --git a/rslib/src/scheduler/upgrade.rs b/rslib/src/scheduler/upgrade.rs index f981943dc..9700d1dac 100644 --- a/rslib/src/scheduler/upgrade.rs +++ b/rslib/src/scheduler/upgrade.rs @@ -63,8 +63,8 @@ impl Card { fn get_filter_info_for_card( card: &Card, - decks: &HashMap, - configs: &HashMap, + decks: &HashMap, + configs: &HashMap, ) -> Option { if card.original_deck_id.0 == 0 { None @@ -85,7 +85,7 @@ fn get_filter_info_for_card( let home_conf_id = decks .get(&card.original_deck_id) .and_then(|deck| deck.config_id()) - .unwrap_or(DeckConfID(1)); + .unwrap_or(DeckConfId(1)); Some( configs .get(&home_conf_id) diff --git a/rslib/src/search/cards.rs b/rslib/src/search/cards.rs index f4bc802eb..e5d0cbd7f 100644 --- a/rslib/src/search/cards.rs +++ b/rslib/src/search/cards.rs @@ -6,7 +6,7 @@ use super::{ sqlwriter::{RequiredTable, SqlWriter}, }; use crate::{ - card::CardID, + card::CardId, card::CardType, collection::Collection, config::{BoolKey, SortKind}, @@ -60,7 +60,7 @@ impl SortKind { } impl Collection { - pub fn search_cards(&mut self, search: &str, mut mode: SortMode) -> Result> { + pub fn search_cards(&mut self, search: &str, mut mode: SortMode) -> Result> { let top_node = Node::Group(parse(search)?); self.resolve_config_sort(&mut mode); let writer = SqlWriter::new(self); diff --git a/rslib/src/search/notes.rs b/rslib/src/search/notes.rs index 2f486176c..a646a8300 100644 --- a/rslib/src/search/notes.rs +++ b/rslib/src/search/notes.rs @@ -4,11 +4,11 @@ use super::{parser::Node, sqlwriter::SqlWriter}; use crate::collection::Collection; use crate::err::Result; -use crate::notes::NoteID; +use crate::notes::NoteId; use crate::search::parser::parse; impl Collection { - pub fn search_notes(&mut self, search: &str) -> Result> { + pub fn search_notes(&mut self, search: &str) -> Result> { let top_node = Node::Group(parse(search)?); let writer = SqlWriter::new(self); let (sql, args) = writer.build_notes_query(&top_node)?; diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 971ffdb8d..06a748544 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -2,9 +2,9 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use crate::{ - decks::DeckID, + decks::DeckId, err::{ParseError, Result, SearchErrorKind as FailKind}, - notetype::NoteTypeID, + notetype::NoteTypeId, }; use lazy_static::lazy_static; use nom::{ @@ -72,8 +72,8 @@ pub enum SearchNode { EditedInDays(u32), CardTemplate(TemplateKind), Deck(String), - DeckID(DeckID), - NoteTypeID(NoteTypeID), + DeckId(DeckId), + NoteTypeId(NoteTypeId), NoteType(String), Rated { days: u32, @@ -81,13 +81,13 @@ pub enum SearchNode { }, Tag(String), Duplicates { - note_type_id: NoteTypeID, + note_type_id: NoteTypeId, text: String, }, State(StateKind), Flag(u8), - NoteIDs(String), - CardIDs(String), + NoteIds(String), + CardIds(String), Property { operator: String, kind: PropertyKind, @@ -337,8 +337,8 @@ fn search_node_for_text_with_argument<'a>( "is" => parse_state(val)?, "did" => parse_did(val)?, "mid" => parse_mid(val)?, - "nid" => SearchNode::NoteIDs(check_id_list(val, key)?.into()), - "cid" => SearchNode::CardIDs(check_id_list(val, key)?.into()), + "nid" => SearchNode::NoteIds(check_id_list(val, key)?.into()), + "cid" => SearchNode::CardIds(check_id_list(val, key)?.into()), "re" => SearchNode::Regex(unescape_quotes(val)), "nc" => SearchNode::NoCombining(unescape(val)?), "w" => SearchNode::WordBoundary(unescape(val)?), @@ -553,11 +553,11 @@ fn parse_state(s: &str) -> ParseResult { } fn parse_did(s: &str) -> ParseResult { - parse_i64(s, "did:").map(|n| SearchNode::DeckID(n.into())) + parse_i64(s, "did:").map(|n| SearchNode::DeckId(n.into())) } fn parse_mid(s: &str) -> ParseResult { - parse_i64(s, "mid:").map(|n| SearchNode::NoteTypeID(n.into())) + parse_i64(s, "mid:").map(|n| SearchNode::NoteTypeId(n.into())) } /// ensure a list of ids contains only numbers and commas, returning unchanged if true @@ -833,7 +833,7 @@ mod test { assert_eq!(parse("tag:hard")?, vec![Search(Tag("hard".into()))]); assert_eq!( parse("nid:1237123712,2,3")?, - vec![Search(NoteIDs("1237123712,2,3".into()))] + vec![Search(NoteIds("1237123712,2,3".into()))] ); assert_eq!(parse("is:due")?, vec![Search(State(StateKind::Due))]); assert_eq!(parse("flag:3")?, vec![Search(Flag(3))]); diff --git a/rslib/src/search/sqlwriter.rs b/rslib/src/search/sqlwriter.rs index 5699753f2..ed1577327 100644 --- a/rslib/src/search/sqlwriter.rs +++ b/rslib/src/search/sqlwriter.rs @@ -8,7 +8,7 @@ use crate::{ decks::human_deck_name_to_native, err::Result, notes::field_checksum, - notetype::NoteTypeID, + notetype::NoteTypeId, prelude::*, storage::ids_to_string, text::{ @@ -140,10 +140,10 @@ impl SqlWriter<'_> { } }, SearchNode::Deck(deck) => self.write_deck(&norm(deck))?, - SearchNode::NoteTypeID(ntid) => { + SearchNode::NoteTypeId(ntid) => { write!(self.sql, "n.mid = {}", ntid).unwrap(); } - SearchNode::DeckID(did) => { + SearchNode::DeckId(did) => { write!(self.sql, "c.did = {}", did).unwrap(); } SearchNode::NoteType(notetype) => self.write_note_type(&norm(notetype))?, @@ -154,10 +154,10 @@ impl SqlWriter<'_> { SearchNode::Flag(flag) => { write!(self.sql, "(c.flags & 7) == {}", flag).unwrap(); } - SearchNode::NoteIDs(nids) => { + SearchNode::NoteIds(nids) => { write!(self.sql, "{} in ({})", self.note_id_column(), nids).unwrap(); } - SearchNode::CardIDs(cids) => { + SearchNode::CardIds(cids) => { write!(self.sql, "c.id in ({})", cids).unwrap(); } SearchNode::Property { operator, kind } => self.write_prop(operator, kind)?, @@ -461,7 +461,7 @@ impl SqlWriter<'_> { Ok(()) } - fn write_dupe(&mut self, ntid: NoteTypeID, text: &str) -> Result<()> { + fn write_dupe(&mut self, ntid: NoteTypeId, text: &str) -> Result<()> { let text_nohtml = strip_html_preserving_media_filenames(text); let csum = field_checksum(text_nohtml.as_ref()); @@ -554,11 +554,11 @@ impl SearchNode { match self { SearchNode::AddedInDays(_) => RequiredTable::Cards, SearchNode::Deck(_) => RequiredTable::Cards, - SearchNode::DeckID(_) => RequiredTable::Cards, + SearchNode::DeckId(_) => RequiredTable::Cards, SearchNode::Rated { .. } => RequiredTable::Cards, SearchNode::State(_) => RequiredTable::Cards, SearchNode::Flag(_) => RequiredTable::Cards, - SearchNode::CardIDs(_) => RequiredTable::Cards, + SearchNode::CardIds(_) => RequiredTable::Cards, SearchNode::Property { .. } => RequiredTable::Cards, SearchNode::UnqualifiedText(_) => RequiredTable::Notes, @@ -568,11 +568,11 @@ impl SearchNode { SearchNode::Regex(_) => RequiredTable::Notes, SearchNode::NoCombining(_) => RequiredTable::Notes, SearchNode::WordBoundary(_) => RequiredTable::Notes, - SearchNode::NoteTypeID(_) => RequiredTable::Notes, + SearchNode::NoteTypeId(_) => RequiredTable::Notes, SearchNode::NoteType(_) => RequiredTable::Notes, SearchNode::EditedInDays(_) => RequiredTable::Notes, - SearchNode::NoteIDs(_) => RequiredTable::CardsOrNotes, + SearchNode::NoteIds(_) => RequiredTable::CardsOrNotes, SearchNode::WholeCollection => RequiredTable::CardsOrNotes, SearchNode::CardTemplate(_) => RequiredTable::CardsAndNotes, diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index 623928160..e660cc6ab 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -2,8 +2,8 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use crate::{ - decks::DeckID as DeckIDType, - notetype::NoteTypeID as NoteTypeIDType, + decks::DeckId as DeckIdType, + notetype::NoteTypeId as NoteTypeIdType, prelude::*, search::parser::{parse, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind}, text::escape_anki_wildcards, @@ -85,16 +85,16 @@ fn write_search_node(node: &SearchNode) -> String { EditedInDays(u) => format!("\"edited:{}\"", u), CardTemplate(t) => write_template(t), Deck(s) => quote(&format!("deck:{}", s)), - DeckID(DeckIDType(i)) => format!("\"did:{}\"", i), - NoteTypeID(NoteTypeIDType(i)) => format!("\"mid:{}\"", i), + DeckId(DeckIdType(i)) => format!("\"did:{}\"", i), + NoteTypeId(NoteTypeIdType(i)) => format!("\"mid:{}\"", i), NoteType(s) => quote(&format!("note:{}", s)), Rated { days, ease } => write_rated(days, ease), Tag(s) => quote(&format!("tag:{}", s)), Duplicates { note_type_id, text } => write_dupe(note_type_id, text), State(k) => write_state(k), Flag(u) => format!("\"flag:{}\"", u), - NoteIDs(s) => format!("\"nid:{}\"", s), - CardIDs(s) => format!("\"cid:{}\"", s), + NoteIds(s) => format!("\"nid:{}\"", s), + CardIds(s) => format!("\"cid:{}\"", s), Property { operator, kind } => write_property(operator, kind), WholeCollection => "\"deck:*\"".to_string(), Regex(s) => quote(&format!("re:{}", s)), @@ -135,7 +135,7 @@ fn write_rated(days: &u32, ease: &RatingKind) -> String { } /// Escape double quotes and backslashes: \" -fn write_dupe(note_type_id: &NoteTypeIDType, text: &str) -> String { +fn write_dupe(note_type_id: &NoteTypeId, text: &str) -> String { let esc = text.replace(r"\", r"\\").replace('"', r#"\""#); format!("\"dupe:{},{}\"", note_type_id, esc) } diff --git a/rslib/src/stats/card.rs b/rslib/src/stats/card.rs index b7c85bd52..8bb7323a5 100644 --- a/rslib/src/stats/card.rs +++ b/rslib/src/stats/card.rs @@ -25,8 +25,8 @@ struct CardStats { card_type: String, note_type: String, deck: String, - nid: NoteID, - cid: CardID, + nid: NoteId, + cid: CardId, revlog: Vec, } @@ -56,12 +56,12 @@ struct RevlogText { } impl Collection { - pub fn card_stats(&mut self, cid: CardID) -> Result { + pub fn card_stats(&mut self, cid: CardId) -> Result { let stats = self.gather_card_stats(cid)?; self.card_stats_to_string(stats) } - fn gather_card_stats(&mut self, cid: CardID) -> Result { + fn gather_card_stats(&mut self, cid: CardId) -> Result { let card = self.storage.get_card(cid)?.ok_or(AnkiError::NotFound)?; let note = self .storage @@ -265,7 +265,7 @@ mod test { let nt = col.get_notetype_by_name("Basic")?.unwrap(); let mut note = nt.new_note(); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; let cid = col.search_cards("", SortMode::NoOrder)?[0]; let _report = col.card_stats(cid)?; diff --git a/rslib/src/storage/card/mod.rs b/rslib/src/storage/card/mod.rs index 46e65904b..0df7b3720 100644 --- a/rslib/src/storage/card/mod.rs +++ b/rslib/src/storage/card/mod.rs @@ -4,11 +4,11 @@ pub(crate) mod filtered; use crate::{ - card::{Card, CardID, CardQueue, CardType}, - deckconf::DeckConfID, - decks::{Deck, DeckID, DeckKind}, + card::{Card, CardId, CardQueue, CardType}, + deckconf::DeckConfId, + decks::{Deck, DeckId, DeckKind}, err::Result, - notes::NoteID, + notes::NoteId, scheduler::{ congrats::CongratsInfo, queue::{DueCard, NewCard}, @@ -70,7 +70,7 @@ fn row_to_card(row: &Row) -> result::Result { } impl super::SqliteStorage { - pub fn get_card(&self, cid: CardID) -> Result> { + pub fn get_card(&self, cid: CardId) -> Result> { self.db .prepare_cached(concat!(include_str!("get_card.sql"), " where id = ?"))? .query_row(params![cid], row_to_card) @@ -126,7 +126,7 @@ impl super::SqliteStorage { card.flags, card.data, ])?; - card.id = CardID(self.db.last_insert_rowid()); + card.id = CardId(self.db.last_insert_rowid()); Ok(()) } @@ -157,7 +157,7 @@ impl super::SqliteStorage { Ok(()) } - pub(crate) fn remove_card(&self, cid: CardID) -> Result<()> { + pub(crate) fn remove_card(&self, cid: CardId) -> Result<()> { self.db .prepare_cached("delete from cards where id = ?")? .execute(&[cid])?; @@ -170,7 +170,7 @@ impl super::SqliteStorage { &self, day_cutoff: u32, learn_cutoff: i64, - deck: DeckID, + deck: DeckId, mut func: F, ) -> Result<()> where @@ -205,7 +205,7 @@ impl super::SqliteStorage { /// Call func() for each new card, stopping when it returns false /// or no more cards found. Cards will arrive in (deck_id, due) order. - pub(crate) fn for_each_new_card_in_deck(&self, deck: DeckID, mut func: F) -> Result<()> + pub(crate) fn for_each_new_card_in_deck(&self, deck: DeckId, mut func: F) -> Result<()> where F: FnMut(NewCard) -> bool, { @@ -260,7 +260,7 @@ impl super::SqliteStorage { .map_err(Into::into) } - pub(crate) fn all_filtered_cards_by_deck(&self) -> Result> { + pub(crate) fn all_filtered_cards_by_deck(&self) -> Result> { self.db .prepare("select id, did from cards where odid > 0")? .query_and_then(NO_PARAMS, |r| -> Result<_> { Ok((r.get(0)?, r.get(1)?)) })? @@ -274,7 +274,7 @@ impl super::SqliteStorage { .map_err(Into::into) } - pub(crate) fn get_card_by_ordinal(&self, nid: NoteID, ord: u16) -> Result> { + pub(crate) fn get_card_by_ordinal(&self, nid: NoteId, ord: u16) -> Result> { self.db .prepare_cached(concat!( include_str!("get_card.sql"), @@ -301,25 +301,25 @@ impl super::SqliteStorage { .map_err(Into::into) } - pub(crate) fn all_cards_of_note(&self, nid: NoteID) -> Result> { + pub(crate) fn all_cards_of_note(&self, nid: NoteId) -> Result> { self.db .prepare_cached(concat!(include_str!("get_card.sql"), " where nid = ?"))? .query_and_then(&[nid], |r| row_to_card(r).map_err(Into::into))? .collect() } - pub(crate) fn all_card_ids_of_note(&self, nid: NoteID) -> Result> { + pub(crate) fn all_card_ids_of_note(&self, nid: NoteId) -> Result> { self.db .prepare_cached("select id from cards where nid = ? order by ord")? - .query_and_then(&[nid], |r| Ok(CardID(r.get(0)?)))? + .query_and_then(&[nid], |r| Ok(CardId(r.get(0)?)))? .collect() } /// Place matching card ids into the search table. pub(crate) fn search_siblings_for_bury( &self, - cid: CardID, - nid: NoteID, + cid: CardId, + nid: NoteId, include_new: bool, include_reviews: bool, ) -> Result<()> { @@ -337,14 +337,14 @@ impl super::SqliteStorage { Ok(()) } - pub(crate) fn note_ids_of_cards(&self, cids: &[CardID]) -> Result> { + pub(crate) fn note_ids_of_cards(&self, cids: &[CardId]) -> Result> { let mut stmt = self .db .prepare_cached("select nid from cards where id = ?")?; let mut nids = HashSet::new(); for cid in cids { if let Some(nid) = stmt - .query_row(&[cid], |r| r.get::<_, NoteID>(0)) + .query_row(&[cid], |r| r.get::<_, NoteId>(0)) .optional()? { nids.insert(nid); @@ -451,7 +451,7 @@ impl super::SqliteStorage { /// Clear with clear_searched_cards_table(). pub(crate) fn set_search_table_to_card_ids( &mut self, - cards: &[CardID], + cards: &[CardId], preserve_order: bool, ) -> Result<()> { if preserve_order { @@ -474,7 +474,7 @@ impl super::SqliteStorage { /// 130% when the deck options were edited for the first time. pub(crate) fn fix_low_card_eases_for_configs( &self, - configs: &[DeckConfID], + configs: &[DeckConfId], server: bool, ) -> Result<()> { let mut affected_decks = vec![]; diff --git a/rslib/src/storage/deck/mod.rs b/rslib/src/storage/deck/mod.rs index b26a0ccd0..0a6fbaec8 100644 --- a/rslib/src/storage/deck/mod.rs +++ b/rslib/src/storage/deck/mod.rs @@ -3,12 +3,12 @@ use super::SqliteStorage; use crate::{ - card::CardID, + card::CardId, card::CardQueue, config::SchedulerVersion, decks::immediate_parent_name, - decks::{Deck, DeckCommon, DeckID, DeckKindProto, DeckSchema11, DueCounts}, - err::{AnkiError, DBErrorKind, Result}, + decks::{Deck, DeckCommon, DeckId, DeckKindProto, DeckSchema11, DueCounts}, + err::{AnkiError, DbErrorKind, Result}, i18n::I18n, timestamp::TimestampMillis, }; @@ -27,14 +27,14 @@ fn row_to_deck(row: &Row) -> Result { mtime_secs: row.get(2)?, usn: row.get(3)?, common, - kind: kind.kind.ok_or_else(|| AnkiError::DBError { - kind: DBErrorKind::MissingEntity, + kind: kind.kind.ok_or_else(|| AnkiError::DbError { + kind: DbErrorKind::MissingEntity, info: format!("invalid deck kind: {}", id), })?, }) } -fn row_to_due_counts(row: &Row) -> Result<(DeckID, DueCounts)> { +fn row_to_due_counts(row: &Row) -> Result<(DeckId, DueCounts)> { Ok(( row.get(0)?, DueCounts { @@ -46,12 +46,12 @@ fn row_to_due_counts(row: &Row) -> Result<(DeckID, DueCounts)> { } impl SqliteStorage { - pub(crate) fn get_all_decks_as_schema11(&self) -> Result> { + pub(crate) fn get_all_decks_as_schema11(&self) -> Result> { self.get_all_decks() .map(|r| r.into_iter().map(|d| (d.id, d.into())).collect()) } - pub(crate) fn get_deck(&self, did: DeckID) -> Result> { + pub(crate) fn get_deck(&self, did: DeckId) -> Result> { self.db .prepare_cached(concat!(include_str!("get_deck.sql"), " where id = ?"))? .query_and_then(&[did], row_to_deck)? @@ -66,7 +66,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_decks_map(&self) -> Result> { + pub(crate) fn get_decks_map(&self) -> Result> { self.db .prepare(include_str!("get_deck.sql"))? .query_and_then(NO_PARAMS, row_to_deck)? @@ -75,7 +75,7 @@ impl SqliteStorage { } /// Get all deck names in sorted, human-readable form (::) - pub(crate) fn get_all_deck_names(&self) -> Result> { + pub(crate) fn get_all_deck_names(&self) -> Result> { self.db .prepare("select id, name from decks order by name")? .query_and_then(NO_PARAMS, |row| { @@ -84,7 +84,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_deck_id(&self, machine_name: &str) -> Result> { + pub(crate) fn get_deck_id(&self, machine_name: &str) -> Result> { self.db .prepare("select id from decks where name = ?")? .query_and_then(&[machine_name], |row| row.get(0))? @@ -166,14 +166,14 @@ impl SqliteStorage { Ok(()) } - pub(crate) fn remove_deck(&self, did: DeckID) -> Result<()> { + pub(crate) fn remove_deck(&self, did: DeckId) -> Result<()> { self.db .prepare_cached("delete from decks where id = ?")? .execute(&[did])?; Ok(()) } - pub(crate) fn all_cards_in_single_deck(&self, did: DeckID) -> Result> { + pub(crate) fn all_cards_in_single_deck(&self, did: DeckId) -> Result> { self.db .prepare_cached(include_str!("cards_for_deck.sql"))? .query_and_then(&[did], |r| r.get(0).map_err(Into::into))? @@ -196,7 +196,7 @@ impl SqliteStorage { /// the number of parent decks that need to be skipped to get to the chosen deck. pub(crate) fn deck_with_parents_and_children( &self, - deck_id: DeckID, + deck_id: DeckId, ) -> Result<(Vec, usize)> { let deck = self.get_deck(deck_id)?.ok_or(AnkiError::NotFound)?; let mut parents = self.parent_decks(&deck)?; @@ -247,7 +247,7 @@ impl SqliteStorage { day_cutoff: u32, learn_cutoff: u32, top_deck: Option<&str>, - ) -> Result> { + ) -> Result> { let sched_ver = sched as u8; let mut params = named_params! { ":new_queue": CardQueue::New as u8, @@ -292,14 +292,14 @@ impl SqliteStorage { } /// Decks referenced by cards but missing. - pub(crate) fn missing_decks(&self) -> Result> { + pub(crate) fn missing_decks(&self) -> Result> { self.db .prepare(include_str!("missing-decks.sql"))? .query_and_then(NO_PARAMS, |r| r.get(0).map_err(Into::into))? .collect() } - pub(crate) fn deck_is_empty(&self, did: DeckID) -> Result { + pub(crate) fn deck_is_empty(&self, did: DeckId) -> Result { self.db .prepare_cached("select null from cards where did=?")? .query(&[did])? @@ -373,23 +373,23 @@ impl SqliteStorage { self.set_schema11_decks(decks) } - fn get_schema11_decks(&self) -> Result> { + fn get_schema11_decks(&self) -> Result> { let mut stmt = self.db.prepare("select decks from col")?; let decks = stmt - .query_and_then(NO_PARAMS, |row| -> Result> { - let v: HashMap = + .query_and_then(NO_PARAMS, |row| -> Result> { + let v: HashMap = serde_json::from_str(row.get_raw(0).as_str()?)?; Ok(v) })? .next() - .ok_or_else(|| AnkiError::DBError { + .ok_or_else(|| AnkiError::DbError { info: "col table empty".to_string(), - kind: DBErrorKind::MissingEntity, + kind: DbErrorKind::MissingEntity, })??; Ok(decks) } - pub(crate) fn set_schema11_decks(&self, decks: HashMap) -> Result<()> { + pub(crate) fn set_schema11_decks(&self, decks: HashMap) -> Result<()> { let json = serde_json::to_string(&decks)?; self.db.execute("update col set decks = ?", &[json])?; Ok(()) diff --git a/rslib/src/storage/deckconf/mod.rs b/rslib/src/storage/deckconf/mod.rs index 9a405fc31..ee952af52 100644 --- a/rslib/src/storage/deckconf/mod.rs +++ b/rslib/src/storage/deckconf/mod.rs @@ -3,7 +3,7 @@ use super::SqliteStorage; use crate::{ - deckconf::{DeckConf, DeckConfID, DeckConfSchema11, DeckConfigInner}, + deckconf::{DeckConf, DeckConfId, DeckConfSchema11, DeckConfigInner}, err::Result, i18n::I18n, }; @@ -31,7 +31,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_deck_config_map(&self) -> Result> { + pub(crate) fn get_deck_config_map(&self) -> Result> { self.db .prepare_cached(include_str!("get.sql"))? .query_and_then(NO_PARAMS, row_to_deckconf)? @@ -39,7 +39,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_deck_config(&self, dcid: DeckConfID) -> Result> { + pub(crate) fn get_deck_config(&self, dcid: DeckConfId) -> Result> { self.db .prepare_cached(concat!(include_str!("get.sql"), " where id = ?"))? .query_and_then(params![dcid], row_to_deckconf)? @@ -97,7 +97,7 @@ impl SqliteStorage { Ok(()) } - pub(crate) fn remove_deck_conf(&self, dcid: DeckConfID) -> Result<()> { + pub(crate) fn remove_deck_conf(&self, dcid: DeckConfId) -> Result<()> { self.db .prepare_cached("delete from deck_config where id=?")? .execute(params![dcid])?; @@ -140,7 +140,7 @@ impl SqliteStorage { } pub(super) fn upgrade_deck_conf_to_schema14(&self) -> Result<()> { - let conf: HashMap = + let conf: HashMap = self.db .query_row_and_then("select dconf from col", NO_PARAMS, |row| -> Result<_> { let text = row.get_raw(0).as_str()?; @@ -208,7 +208,7 @@ impl SqliteStorage { pub(super) fn downgrade_deck_conf_from_schema16(&self) -> Result<()> { let allconf = self.all_deck_config()?; - let confmap: HashMap = allconf + let confmap: HashMap = allconf .into_iter() .map(|c| -> DeckConfSchema11 { c.into() }) .map(|c| (c.id, c)) diff --git a/rslib/src/storage/graves/mod.rs b/rslib/src/storage/graves/mod.rs index 468ea2811..aebcd845c 100644 --- a/rslib/src/storage/graves/mod.rs +++ b/rslib/src/storage/graves/mod.rs @@ -3,10 +3,10 @@ use super::SqliteStorage; use crate::{ - card::CardID, - decks::DeckID, + card::CardId, + decks::DeckId, err::{AnkiError, Result}, - notes::NoteID, + notes::NoteId, sync::Graves, types::Usn, }; @@ -28,27 +28,27 @@ impl SqliteStorage { Ok(()) } - pub(crate) fn add_card_grave(&self, cid: CardID, usn: Usn) -> Result<()> { + pub(crate) fn add_card_grave(&self, cid: CardId, usn: Usn) -> Result<()> { self.add_grave(cid.0, GraveKind::Card, usn) } - pub(crate) fn add_note_grave(&self, nid: NoteID, usn: Usn) -> Result<()> { + pub(crate) fn add_note_grave(&self, nid: NoteId, usn: Usn) -> Result<()> { self.add_grave(nid.0, GraveKind::Note, usn) } - pub(crate) fn add_deck_grave(&self, did: DeckID, usn: Usn) -> Result<()> { + pub(crate) fn add_deck_grave(&self, did: DeckId, usn: Usn) -> Result<()> { self.add_grave(did.0, GraveKind::Deck, usn) } - pub(crate) fn remove_card_grave(&self, cid: CardID) -> Result<()> { + pub(crate) fn remove_card_grave(&self, cid: CardId) -> Result<()> { self.remove_grave(cid.0, GraveKind::Card) } - pub(crate) fn remove_note_grave(&self, nid: NoteID) -> Result<()> { + pub(crate) fn remove_note_grave(&self, nid: NoteId) -> Result<()> { self.remove_grave(nid.0, GraveKind::Note) } - pub(crate) fn remove_deck_grave(&self, did: DeckID) -> Result<()> { + pub(crate) fn remove_deck_grave(&self, did: DeckId) -> Result<()> { self.remove_grave(did.0, GraveKind::Deck) } @@ -64,9 +64,9 @@ impl SqliteStorage { let kind = GraveKind::try_from(row.get::<_, u8>(1)?) .map_err(|_| AnkiError::invalid_input("invalid grave kind"))?; match kind { - GraveKind::Card => graves.cards.push(CardID(oid)), - GraveKind::Note => graves.notes.push(NoteID(oid)), - GraveKind::Deck => graves.decks.push(DeckID(oid)), + GraveKind::Card => graves.cards.push(CardId(oid)), + GraveKind::Note => graves.notes.push(NoteId(oid)), + GraveKind::Deck => graves.decks.push(DeckId(oid)), } } Ok(graves) diff --git a/rslib/src/storage/note/mod.rs b/rslib/src/storage/note/mod.rs index 5d6e680b5..cd32e8802 100644 --- a/rslib/src/storage/note/mod.rs +++ b/rslib/src/storage/note/mod.rs @@ -5,8 +5,8 @@ use std::collections::HashSet; use crate::{ err::Result, - notes::{Note, NoteID, NoteTags}, - notetype::NoteTypeID, + notes::{Note, NoteId, NoteTags}, + notetype::NoteTypeId, tags::{join_tags, split_tags}, timestamp::TimestampMillis, }; @@ -21,7 +21,7 @@ pub(crate) fn join_fields(fields: &[String]) -> String { } impl super::SqliteStorage { - pub fn get_note(&self, nid: NoteID) -> Result> { + pub fn get_note(&self, nid: NoteId) -> Result> { self.db .prepare_cached(concat!(include_str!("get.sql"), " where id = ?"))? .query_and_then(params![nid], row_to_note)? @@ -29,7 +29,7 @@ impl super::SqliteStorage { .transpose() } - pub fn get_note_without_fields(&self, nid: NoteID) -> Result> { + pub fn get_note_without_fields(&self, nid: NoteId) -> Result> { self.db .prepare_cached(concat!( include_str!("get_without_fields.sql"), @@ -93,14 +93,14 @@ impl super::SqliteStorage { Ok(()) } - pub(crate) fn remove_note(&self, nid: NoteID) -> Result<()> { + pub(crate) fn remove_note(&self, nid: NoteId) -> Result<()> { self.db .prepare_cached("delete from notes where id = ?")? .execute(&[nid])?; Ok(()) } - pub(crate) fn note_is_orphaned(&self, nid: NoteID) -> Result { + pub(crate) fn note_is_orphaned(&self, nid: NoteId) -> Result { self.db .prepare_cached(include_str!("is_orphaned.sql"))? .query_row(&[nid], |r| r.get(0)) @@ -114,7 +114,7 @@ impl super::SqliteStorage { Ok(()) } - pub(crate) fn fix_invalid_utf8_in_note(&self, nid: NoteID) -> Result<()> { + pub(crate) fn fix_invalid_utf8_in_note(&self, nid: NoteId) -> Result<()> { self.db .query_row( "select cast(flds as blob) from notes where id=?", @@ -137,9 +137,9 @@ impl super::SqliteStorage { /// match. pub(crate) fn note_fields_by_checksum( &self, - ntid: NoteTypeID, + ntid: NoteTypeId, csum: u32, - ) -> Result> { + ) -> Result> { self.db .prepare("select id, field_at_index(flds, 0) from notes where csum=? and mid=?")? .query_and_then(params![csum, ntid], |r| Ok((r.get(0)?, r.get(1)?)))? @@ -170,7 +170,7 @@ impl super::SqliteStorage { Ok(seen) } - pub(crate) fn get_note_tags_by_id(&mut self, note_id: NoteID) -> Result> { + pub(crate) fn get_note_tags_by_id(&mut self, note_id: NoteId) -> Result> { self.db .prepare_cached(&format!("{} where id = ?", include_str!("get_tags.sql")))? .query_and_then(&[note_id], row_to_note_tags)? @@ -180,7 +180,7 @@ impl super::SqliteStorage { pub(crate) fn get_note_tags_by_id_list( &mut self, - note_ids: &[NoteID], + note_ids: &[NoteId], ) -> Result> { self.set_search_table_to_note_ids(note_ids)?; let out = self @@ -233,7 +233,7 @@ impl super::SqliteStorage { /// Injects the provided card IDs into the search_nids table, for /// when ids have arrived outside of a search. /// Clear with clear_searched_notes_table(). - fn set_search_table_to_note_ids(&mut self, notes: &[NoteID]) -> Result<()> { + fn set_search_table_to_note_ids(&mut self, notes: &[NoteId]) -> Result<()> { self.setup_searched_notes_table()?; let mut stmt = self .db diff --git a/rslib/src/storage/notetype/mod.rs b/rslib/src/storage/notetype/mod.rs index 951b8314c..fbeeb3040 100644 --- a/rslib/src/storage/notetype/mod.rs +++ b/rslib/src/storage/notetype/mod.rs @@ -3,13 +3,13 @@ use super::{ids_to_string, SqliteStorage}; use crate::{ - err::{AnkiError, DBErrorKind, Result}, - notes::NoteID, + err::{AnkiError, DbErrorKind, Result}, + notes::NoteId, notetype::{ AlreadyGeneratedCardInfo, CardTemplate, CardTemplateConfig, NoteField, NoteFieldConfig, NoteTypeConfig, }, - notetype::{NoteType, NoteTypeID, NoteTypeSchema11}, + notetype::{NoteType, NoteTypeId, NoteTypeSchema11}, timestamp::TimestampMillis, }; use prost::Message; @@ -41,7 +41,7 @@ fn row_to_existing_card(row: &Row) -> Result { } impl SqliteStorage { - pub(crate) fn get_notetype(&self, ntid: NoteTypeID) -> Result> { + pub(crate) fn get_notetype(&self, ntid: NoteTypeId) -> Result> { match self.get_notetype_core(ntid)? { Some(mut nt) => { nt.fields = self.get_notetype_fields(ntid)?; @@ -52,7 +52,7 @@ impl SqliteStorage { } } - fn get_notetype_core(&self, ntid: NoteTypeID) -> Result> { + fn get_notetype_core(&self, ntid: NoteTypeId) -> Result> { self.db .prepare_cached(concat!(include_str!("get_notetype.sql"), " where id = ?"))? .query_and_then(&[ntid], row_to_notetype_core)? @@ -60,7 +60,7 @@ impl SqliteStorage { .transpose() } - fn get_notetype_fields(&self, ntid: NoteTypeID) -> Result> { + fn get_notetype_fields(&self, ntid: NoteTypeId) -> Result> { self.db .prepare_cached(include_str!("get_fields.sql"))? .query_and_then(&[ntid], |row| { @@ -74,7 +74,7 @@ impl SqliteStorage { .collect() } - fn get_notetype_templates(&self, ntid: NoteTypeID) -> Result> { + fn get_notetype_templates(&self, ntid: NoteTypeId) -> Result> { self.db .prepare_cached(include_str!("get_templates.sql"))? .query_and_then(&[ntid], |row| { @@ -90,7 +90,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_notetype_id(&self, name: &str) -> Result> { + pub(crate) fn get_notetype_id(&self, name: &str) -> Result> { self.db .prepare_cached("select id from notetypes where name = ?")? .query_row(params![name], |row| row.get(0)) @@ -98,7 +98,7 @@ impl SqliteStorage { .map_err(Into::into) } - pub fn get_all_notetype_names(&self) -> Result> { + pub fn get_all_notetype_names(&self) -> Result> { self.db .prepare_cached(include_str!("get_notetype_names.sql"))? .query_and_then(NO_PARAMS, |row| Ok((row.get(0)?, row.get(1)?)))? @@ -106,7 +106,7 @@ impl SqliteStorage { } /// Returns list of (id, name, use_count) - pub fn get_notetype_use_counts(&self) -> Result> { + pub fn get_notetype_use_counts(&self) -> Result> { self.db .prepare_cached(include_str!("get_use_counts.sql"))? .query_and_then(NO_PARAMS, |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))? @@ -115,7 +115,7 @@ impl SqliteStorage { pub(crate) fn update_notetype_fields( &self, - ntid: NoteTypeID, + ntid: NoteTypeId, fields: &[NoteField], ) -> Result<()> { self.db @@ -133,7 +133,7 @@ impl SqliteStorage { /// A sorted list of all field names used by provided notes, for use with /// the find&replace feature. - pub(crate) fn field_names_for_notes(&self, nids: &[NoteID]) -> Result> { + pub(crate) fn field_names_for_notes(&self, nids: &[NoteId]) -> Result> { let mut sql = include_str!("field_names_for_notes.sql").to_string(); sql.push(' '); ids_to_string(&mut sql, nids); @@ -146,8 +146,8 @@ impl SqliteStorage { pub(crate) fn note_ids_by_notetype( &self, - nids: &[NoteID], - ) -> Result> { + nids: &[NoteId], + ) -> Result> { let mut sql = String::from("select mid, id from notes where id in "); ids_to_string(&mut sql, nids); sql += " order by mid, id"; @@ -157,7 +157,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn all_note_ids_by_notetype(&self) -> Result> { + pub(crate) fn all_note_ids_by_notetype(&self) -> Result> { let sql = String::from("select mid, id from notes order by mid, id"); self.db .prepare(&sql)? @@ -167,7 +167,7 @@ impl SqliteStorage { pub(crate) fn update_notetype_templates( &self, - ntid: NoteTypeID, + ntid: NoteTypeId, templates: &[CardTemplate], ) -> Result<()> { self.db @@ -240,7 +240,7 @@ impl SqliteStorage { pub(crate) fn remove_cards_for_deleted_templates( &self, - ntid: NoteTypeID, + ntid: NoteTypeId, ords: &[u32], ) -> Result<()> { let mut stmt = self @@ -252,7 +252,7 @@ impl SqliteStorage { Ok(()) } - pub(crate) fn remove_notetype(&self, ntid: NoteTypeID) -> Result<()> { + pub(crate) fn remove_notetype(&self, ntid: NoteTypeId) -> Result<()> { self.db .prepare_cached("delete from cards where nid in (select id from notes where mid=?)")? .execute(&[ntid])?; @@ -274,7 +274,7 @@ impl SqliteStorage { pub(crate) fn move_cards_for_repositioned_templates( &self, - ntid: NoteTypeID, + ntid: NoteTypeId, changes: &[(u32, u32)], ) -> Result<()> { let case_clauses: Vec<_> = changes @@ -297,7 +297,7 @@ and ord in ", pub(crate) fn existing_cards_for_notetype( &self, - ntid: NoteTypeID, + ntid: NoteTypeId, ) -> Result> { self.db .prepare_cached(concat!( @@ -310,7 +310,7 @@ and ord in ", pub(crate) fn existing_cards_for_note( &self, - nid: NoteID, + nid: NoteId, ) -> Result> { self.db .prepare_cached(concat!( @@ -328,7 +328,7 @@ and ord in ", Ok(()) } - pub(crate) fn highest_card_ordinal_for_notetype(&self, ntid: NoteTypeID) -> Result { + pub(crate) fn highest_card_ordinal_for_notetype(&self, ntid: NoteTypeId) -> Result { self.db .prepare(include_str!("highest_card_ord.sql"))? .query_row(&[ntid], |row| row.get(0)) @@ -339,7 +339,7 @@ and ord in ", pub(crate) fn get_all_notetypes_as_schema11( &self, - ) -> Result> { + ) -> Result> { let mut nts = HashMap::new(); for (ntid, _name) in self.get_all_notetype_names()? { let full = self.get_notetype(ntid)?.unwrap(); @@ -381,28 +381,28 @@ and ord in ", self.set_schema11_notetypes(nts) } - fn get_schema11_notetypes(&self) -> Result> { + fn get_schema11_notetypes(&self) -> Result> { let mut stmt = self.db.prepare("select models from col")?; let note_types = stmt .query_and_then( NO_PARAMS, - |row| -> Result> { - let v: HashMap = + |row| -> Result> { + let v: HashMap = serde_json::from_str(row.get_raw(0).as_str()?)?; Ok(v) }, )? .next() - .ok_or_else(|| AnkiError::DBError { + .ok_or_else(|| AnkiError::DbError { info: "col table empty".to_string(), - kind: DBErrorKind::MissingEntity, + kind: DbErrorKind::MissingEntity, })??; Ok(note_types) } pub(crate) fn set_schema11_notetypes( &self, - notetypes: HashMap, + notetypes: HashMap, ) -> Result<()> { let json = serde_json::to_string(¬etypes)?; self.db.execute("update col set models = ?", &[json])?; diff --git a/rslib/src/storage/revlog/mod.rs b/rslib/src/storage/revlog/mod.rs index a93a5e299..4d403d9a5 100644 --- a/rslib/src/storage/revlog/mod.rs +++ b/rslib/src/storage/revlog/mod.rs @@ -64,7 +64,7 @@ impl SqliteStorage { &self, entry: &RevlogEntry, ensure_unique: bool, - ) -> Result { + ) -> Result { self.db .prepare_cached(include_str!("add.sql"))? .execute(params![ @@ -79,10 +79,10 @@ impl SqliteStorage { entry.taken_millis, entry.review_kind as u8 ])?; - Ok(RevlogID(self.db.last_insert_rowid())) + Ok(RevlogId(self.db.last_insert_rowid())) } - pub(crate) fn get_revlog_entry(&self, id: RevlogID) -> Result> { + pub(crate) fn get_revlog_entry(&self, id: RevlogId) -> Result> { self.db .prepare_cached(concat!(include_str!("get.sql"), " where id=?"))? .query_and_then(&[id], row_to_revlog_entry)? @@ -91,14 +91,14 @@ impl SqliteStorage { } /// Only intended to be used by the undo code, as Anki can not sync revlog deletions. - pub(crate) fn remove_revlog_entry(&self, id: RevlogID) -> Result<()> { + pub(crate) fn remove_revlog_entry(&self, id: RevlogId) -> Result<()> { self.db .prepare_cached("delete from revlog where id = ?")? .execute(&[id])?; Ok(()) } - pub(crate) fn get_revlog_entries_for_card(&self, cid: CardID) -> Result> { + pub(crate) fn get_revlog_entries_for_card(&self, cid: CardId) -> Result> { self.db .prepare_cached(concat!(include_str!("get.sql"), " where cid=?"))? .query_and_then(&[cid], row_to_revlog_entry)? diff --git a/rslib/src/storage/sqlite.rs b/rslib/src/storage/sqlite.rs index a348b6a4a..5da65970f 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -3,7 +3,7 @@ use crate::config::schema11::schema11_config_as_string; use crate::err::Result; -use crate::err::{AnkiError, DBErrorKind}; +use crate::err::{AnkiError, DbErrorKind}; use crate::timestamp::{TimestampMillis, TimestampSecs}; use crate::{i18n::I18n, scheduler::timing::v1_creation_date, text::without_combining}; use regex::Regex; @@ -141,17 +141,17 @@ impl SqliteStorage { let (create, ver) = schema_version(&db)?; let err = match ver { - v if v < SCHEMA_MIN_VERSION => Some(DBErrorKind::FileTooOld), - v if v > SCHEMA_MAX_VERSION => Some(DBErrorKind::FileTooNew), + v if v < SCHEMA_MIN_VERSION => Some(DbErrorKind::FileTooOld), + v if v > SCHEMA_MAX_VERSION => Some(DbErrorKind::FileTooNew), 12 | 13 => { // as schema definition changed, user must perform clean // shutdown to return to schema 11 prior to running this version - Some(DBErrorKind::FileTooNew) + Some(DbErrorKind::FileTooNew) } _ => None, }; if let Some(kind) = err { - return Err(AnkiError::DBError { + return Err(AnkiError::DbError { info: "".to_string(), kind, }); diff --git a/rslib/src/sync/http_client.rs b/rslib/src/sync/http_client.rs index bd1b47d9f..212d60f70 100644 --- a/rslib/src/sync/http_client.rs +++ b/rslib/src/sync/http_client.rs @@ -30,7 +30,7 @@ use tempfile::NamedTempFile; pub type FullSyncProgressFn = Box; -pub struct HTTPSyncClient { +pub struct HttpSyncClient { hkey: Option, skey: String, client: Client, @@ -62,7 +62,7 @@ impl Timeouts { } #[async_trait(?Send)] -impl SyncServer for HTTPSyncClient { +impl SyncServer for HttpSyncClient { async fn meta(&self) -> Result { let input = SyncRequest::Meta(MetaIn { sync_version: SYNC_VERSION_MAX, @@ -175,8 +175,8 @@ impl SyncServer for HTTPSyncClient { } } -impl HTTPSyncClient { - pub fn new(hkey: Option, host_number: u32) -> HTTPSyncClient { +impl HttpSyncClient { + pub fn new(hkey: Option, host_number: u32) -> HttpSyncClient { let timeouts = Timeouts::new(); let client = Client::builder() .connect_timeout(Duration::from_secs(timeouts.connect_secs)) @@ -186,7 +186,7 @@ impl HTTPSyncClient { .unwrap(); let skey = guid(); let endpoint = sync_endpoint(host_number); - HTTPSyncClient { + HttpSyncClient { hkey, skey, client, @@ -353,7 +353,7 @@ mod test { use tokio::runtime::Runtime; async fn http_client_inner(username: String, password: String) -> Result<()> { - let mut syncer = Box::new(HTTPSyncClient::new(None, 0)); + let mut syncer = Box::new(HttpSyncClient::new(None, 0)); assert!(matches!( syncer.login("nosuchuser", "nosuchpass").await, @@ -420,7 +420,7 @@ mod test { }))); let out_path = syncer.full_download(None).await?; - let mut syncer = Box::new(HTTPSyncClient::new(None, 0)); + let mut syncer = Box::new(HttpSyncClient::new(None, 0)); syncer.set_full_sync_progress_fn(Some(Box::new(|progress, _throttle| { println!("progress {:?}", progress); }))); diff --git a/rslib/src/sync/mod.rs b/rslib/src/sync/mod.rs index 101703b6e..3d29358c1 100644 --- a/rslib/src/sync/mod.rs +++ b/rslib/src/sync/mod.rs @@ -20,7 +20,7 @@ use crate::{ tags::{join_tags, split_tags, Tag}, }; pub use http_client::FullSyncProgressFn; -use http_client::HTTPSyncClient; +use http_client::HttpSyncClient; pub use http_client::Timeouts; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -75,9 +75,9 @@ pub struct SyncMeta { #[derive(Serialize, Deserialize, Debug, Default)] pub struct Graves { - pub(crate) cards: Vec, - pub(crate) decks: Vec, - pub(crate) notes: Vec, + pub(crate) cards: Vec, + pub(crate) decks: Vec, + pub(crate) notes: Vec, } #[derive(Serialize_tuple, Deserialize, Debug, Default)] @@ -113,18 +113,18 @@ pub struct Chunk { notes: Vec, } -struct ChunkableIDs { - revlog: Vec, - cards: Vec, - notes: Vec, +struct ChunkableIds { + revlog: Vec, + cards: Vec, + notes: Vec, } #[derive(Serialize_tuple, Deserialize, Debug)] pub struct NoteEntry { - pub id: NoteID, + pub id: NoteId, pub guid: String, #[serde(rename = "mid")] - pub ntid: NoteTypeID, + pub ntid: NoteTypeId, #[serde(rename = "mod")] pub mtime: TimestampSecs, pub usn: Usn, @@ -138,9 +138,9 @@ pub struct NoteEntry { #[derive(Serialize_tuple, Deserialize, Debug)] pub struct CardEntry { - pub id: CardID, - pub nid: NoteID, - pub did: DeckID, + pub id: CardId, + pub nid: NoteId, + pub did: DeckId, pub ord: u16, #[serde(deserialize_with = "deserialize_int_from_number")] pub mtime: TimestampSecs, @@ -157,7 +157,7 @@ pub struct CardEntry { pub left: u32, #[serde(deserialize_with = "deserialize_int_from_number")] pub odue: i32, - pub odid: DeckID, + pub odid: DeckId, pub flags: u8, pub data: String, } @@ -593,7 +593,7 @@ impl Graves { } pub async fn sync_login(username: &str, password: &str) -> Result { - let mut remote = HTTPSyncClient::new(None, 0); + let mut remote = HttpSyncClient::new(None, 0); remote.login(username, password).await?; Ok(SyncAuth { hkey: remote.hkey().to_string(), @@ -602,12 +602,12 @@ pub async fn sync_login(username: &str, password: &str) -> Result { } pub async fn sync_abort(hkey: String, host_number: u32) -> Result<()> { - let mut remote = HTTPSyncClient::new(Some(hkey), host_number); + let mut remote = HttpSyncClient::new(Some(hkey), host_number); remote.abort().await } pub(crate) async fn get_remote_sync_meta(auth: SyncAuth) -> Result { - let remote = HTTPSyncClient::new(Some(auth.hkey), auth.host_number); + let remote = HttpSyncClient::new(Some(auth.hkey), auth.host_number); remote.meta().await } @@ -638,7 +638,7 @@ impl Collection { { NormalSyncer::new( self, - Box::new(HTTPSyncClient::new(Some(auth.hkey), auth.host_number)), + Box::new(HttpSyncClient::new(Some(auth.hkey), auth.host_number)), progress_fn, ) .sync() @@ -647,7 +647,7 @@ impl Collection { /// Upload collection to AnkiWeb. Caller must re-open afterwards. pub async fn full_upload(self, auth: SyncAuth, progress_fn: FullSyncProgressFn) -> Result<()> { - let mut server = HTTPSyncClient::new(Some(auth.hkey), auth.host_number); + let mut server = HttpSyncClient::new(Some(auth.hkey), auth.host_number); server.set_full_sync_progress_fn(Some(progress_fn)); self.full_upload_inner(Box::new(server)).await // remote.upload(&col_path, progress_fn).await?; @@ -666,7 +666,7 @@ impl Collection { auth: SyncAuth, progress_fn: FullSyncProgressFn, ) -> Result<()> { - let mut server = HTTPSyncClient::new(Some(auth.hkey), auth.host_number); + let mut server = HttpSyncClient::new(Some(auth.hkey), auth.host_number); server.set_full_sync_progress_fn(Some(progress_fn)); self.full_download_inner(Box::new(server)).await } @@ -685,7 +685,7 @@ impl Collection { // overwrite existing collection atomically out_file .persist(&col_path) - .map_err(|e| AnkiError::IOError { + .map_err(|e| AnkiError::IoError { info: format!("download save failed: {}", e), })?; Ok(()) @@ -978,8 +978,8 @@ impl Collection { // Local->remote chunks //---------------------------------------------------------------- - fn get_chunkable_ids(&self, pending_usn: Usn) -> Result { - Ok(ChunkableIDs { + fn get_chunkable_ids(&self, pending_usn: Usn) -> Result { + Ok(ChunkableIds { revlog: self.storage.objects_pending_sync("revlog", pending_usn)?, cards: self.storage.objects_pending_sync("cards", pending_usn)?, notes: self.storage.objects_pending_sync("notes", pending_usn)?, @@ -987,7 +987,7 @@ impl Collection { } /// Fetch a chunk of ids from `ids`, returning the referenced objects. - fn get_chunk(&self, ids: &mut ChunkableIDs, new_usn: Option) -> Result { + fn get_chunk(&self, ids: &mut ChunkableIds, new_usn: Option) -> Result { // get a bunch of IDs let mut limit = CHUNK_SIZE as i32; let mut revlog_ids = vec![]; @@ -1295,9 +1295,9 @@ mod test { } impl RemoteTestContext { - fn server_inner(&self) -> HTTPSyncClient { + fn server_inner(&self) -> HttpSyncClient { let auth = self.auth.clone(); - HTTPSyncClient::new(Some(auth.hkey), auth.host_number) + HttpSyncClient::new(Some(auth.hkey), auth.host_number) } } @@ -1327,7 +1327,7 @@ mod test { let nt = col.get_notetype_by_name("Basic").unwrap().unwrap(); let mut note = nt.new_note(); note.set_field(0, "1").unwrap(); - col.add_note(&mut note, DeckID(1)).unwrap(); + col.add_note(&mut note, DeckId(1)).unwrap(); // // set our schema time back, so when initial server // // col is created, it's not identical @@ -1405,8 +1405,8 @@ mod test { // mock revlog entry col1.storage.add_revlog_entry( &RevlogEntry { - id: RevlogID(123), - cid: CardID(456), + id: RevlogId(123), + cid: CardId(456), usn: Usn(-1), interval: 10, ..Default::default() @@ -1436,7 +1436,7 @@ mod test { let dconfid = dconf.id; let noteid = note.id; let cardid = col1.search_cards(&format!("nid:{}", note.id), SortMode::NoOrder)?[0]; - let revlogid = RevlogID(123); + let revlogid = RevlogId(123); let compare_sides = |col1: &mut Collection, col2: &mut Collection| -> Result<()> { assert_eq!( diff --git a/rslib/src/sync/server.rs b/rslib/src/sync/server.rs index 9406ed78a..79d6adba7 100644 --- a/rslib/src/sync/server.rs +++ b/rslib/src/sync/server.rs @@ -14,7 +14,7 @@ use crate::{ use async_trait::async_trait; use tempfile::NamedTempFile; -use super::ChunkableIDs; +use super::ChunkableIds; #[async_trait(?Send)] pub trait SyncServer { async fn meta(&self) -> Result; @@ -54,7 +54,7 @@ pub struct LocalServer { /// config to client. client_is_newer: bool, /// Set on the first call to chunk() - server_chunk_ids: Option, + server_chunk_ids: Option, } impl LocalServer { diff --git a/rslib/src/tags/bulkadd.rs b/rslib/src/tags/bulkadd.rs index dcb9c5f03..b208e1dce 100644 --- a/rslib/src/tags/bulkadd.rs +++ b/rslib/src/tags/bulkadd.rs @@ -10,13 +10,13 @@ use super::{join_tags, split_tags}; use crate::{notes::NoteTags, prelude::*}; impl Collection { - pub fn add_tags_to_notes(&mut self, nids: &[NoteID], tags: &str) -> Result> { + pub fn add_tags_to_notes(&mut self, nids: &[NoteId], tags: &str) -> Result> { self.transact(Op::UpdateTag, |col| col.add_tags_to_notes_inner(nids, tags)) } } impl Collection { - fn add_tags_to_notes_inner(&mut self, nids: &[NoteID], tags: &str) -> Result { + fn add_tags_to_notes_inner(&mut self, nids: &[NoteId], tags: &str) -> Result { let usn = self.usn()?; // will update tag list for any new tags, and match case diff --git a/rslib/src/tags/findreplace.rs b/rslib/src/tags/findreplace.rs index 746d4b423..642936249 100644 --- a/rslib/src/tags/findreplace.rs +++ b/rslib/src/tags/findreplace.rs @@ -12,7 +12,7 @@ impl Collection { /// Replace occurences of a search with a new value in tags. pub fn find_and_replace_tag( &mut self, - nids: &[NoteID], + nids: &[NoteId], search: &str, replacement: &str, regex: bool, @@ -47,7 +47,7 @@ impl Collection { impl Collection { fn replace_tags_for_notes_inner( &mut self, - nids: &[NoteID], + nids: &[NoteId], regex: Regex, mut repl: R, ) -> Result { @@ -97,7 +97,7 @@ where #[cfg(test)] mod test { use super::*; - use crate::{collection::open_test_collection, decks::DeckID}; + use crate::{collection::open_test_collection, decks::DeckId}; #[test] fn find_replace() -> Result<()> { @@ -105,7 +105,7 @@ mod test { let nt = col.get_notetype_by_name("Basic")?.unwrap(); let mut note = nt.new_note(); note.tags.push("test".into()); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; col.find_and_replace_tag(&[note.id], "foo|test", "bar", true, false)?; let note = col.storage.get_note(note.id)?.unwrap(); diff --git a/rslib/src/tags/register.rs b/rslib/src/tags/register.rs index 666a8f63d..7becd2ee3 100644 --- a/rslib/src/tags/register.rs +++ b/rslib/src/tags/register.rs @@ -162,14 +162,14 @@ fn normalize_tag_name(name: &str) -> Cow { #[cfg(test)] mod test { use super::*; - use crate::{collection::open_test_collection, decks::DeckID}; + use crate::{collection::open_test_collection, decks::DeckId}; #[test] fn tags() -> Result<()> { let mut col = open_test_collection(); let nt = col.get_notetype_by_name("Basic")?.unwrap(); let mut note = nt.new_note(); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; let tags: String = col.storage.db_scalar("select tags from notes")?; assert_eq!(tags, ""); diff --git a/rslib/src/tags/remove.rs b/rslib/src/tags/remove.rs index 0c736281c..c4e928462 100644 --- a/rslib/src/tags/remove.rs +++ b/rslib/src/tags/remove.rs @@ -13,7 +13,7 @@ impl Collection { /// Remove whitespace-separated tags from provided notes. pub fn remove_tags_from_notes( &mut self, - nids: &[NoteID], + nids: &[NoteId], tags: &str, ) -> Result> { self.transact(Op::RemoveTag, |col| { @@ -54,7 +54,7 @@ impl Collection { Ok(match_count) } - fn remove_tags_from_notes_inner(&mut self, nids: &[NoteID], tags: &str) -> Result { + fn remove_tags_from_notes_inner(&mut self, nids: &[NoteId], tags: &str) -> Result { let usn = self.usn()?; let mut re = TagMatcher::new(tags)?; @@ -106,7 +106,7 @@ mod test { let mut note = nt.new_note(); note.tags.push("one".into()); note.tags.push("two".into()); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; col.set_tag_expanded("one", true)?; col.clear_unused_tags()?; diff --git a/rslib/src/tags/reparent.rs b/rslib/src/tags/reparent.rs index 915b6d1ee..ffc758791 100644 --- a/rslib/src/tags/reparent.rs +++ b/rslib/src/tags/reparent.rs @@ -138,7 +138,7 @@ mod test { ] { let mut note = nt.new_note(); note.tags.push(tag.to_string()); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; } // two decks with the same base name; they both get mapped diff --git a/rslib/src/tags/tree.rs b/rslib/src/tags/tree.rs index 515e39d5d..193877695 100644 --- a/rslib/src/tags/tree.rs +++ b/rslib/src/tags/tree.rs @@ -121,7 +121,7 @@ mod test { let mut note = nt.new_note(); note.tags.push("foo::bar::a".into()); note.tags.push("foo::bar::b".into()); - col.add_note(&mut note, DeckID(1))?; + col.add_note(&mut note, DeckId(1))?; // missing parents are added assert_eq!( diff --git a/rslib/src/text.rs b/rslib/src/text.rs index 2142a553f..e3d71a225 100644 --- a/rslib/src/text.rs +++ b/rslib/src/text.rs @@ -31,7 +31,7 @@ impl Trimming for Cow<'_, str> { } #[derive(Debug, PartialEq)] -pub enum AVTag { +pub enum AvTag { SoundOrVideo(String), TextToSpeech { field_text: String, @@ -179,13 +179,13 @@ pub fn strip_av_tags(text: &str) -> Cow { } /// Extract audio tags from string, replacing them with [anki:play] refs -pub fn extract_av_tags(text: &str, question_side: bool) -> (Cow, Vec) { +pub fn extract_av_tags(text: &str, question_side: bool) -> (Cow, Vec) { let mut tags = vec![]; let context = if question_side { 'q' } else { 'a' }; let replaced_text = AV_TAGS.replace_all(text, |caps: &Captures| { // extract let tag = if let Some(av_file) = caps.get(1) { - AVTag::SoundOrVideo(decode_entities(av_file.as_str()).into()) + AvTag::SoundOrVideo(decode_entities(av_file.as_str()).into()) } else { let args = caps.get(2).unwrap(); let field_text = caps.get(3).unwrap(); @@ -241,7 +241,7 @@ pub(crate) fn extract_media_refs(text: &str) -> Vec { out } -fn tts_tag_from_string<'a>(field_text: &'a str, args: &'a str) -> AVTag { +fn tts_tag_from_string<'a>(field_text: &'a str, args: &'a str) -> AvTag { let mut other_args = vec![]; let mut split_args = args.split_ascii_whitespace(); let lang = split_args.next().unwrap_or(""); @@ -266,7 +266,7 @@ fn tts_tag_from_string<'a>(field_text: &'a str, args: &'a str) -> AVTag { } } - AVTag::TextToSpeech { + AvTag::TextToSpeech { field_text: strip_html_for_tts(field_text).into(), lang: lang.into(), voices: voices.unwrap_or_else(Vec::new), @@ -451,8 +451,8 @@ mod test { assert_eq!( tags, vec![ - AVTag::SoundOrVideo("fo&obar.mp3".into()), - AVTag::TextToSpeech { + AvTag::SoundOrVideo("fo&obar.mp3".into()), + AvTag::TextToSpeech { field_text: "foo bar 1>2".into(), lang: "en_US".into(), voices: vec!["Bob".into(), "Jane".into()],