From e65b79ba63438815d4b8859c92fc02e8ebbb6761 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sat, 16 Apr 2022 22:14:01 +0200 Subject: [PATCH] Use fat pointer to avoid propogating generics --- rslib/src/import_export/package/apkg/import/cards.rs | 2 +- rslib/src/import_export/package/apkg/import/decks.rs | 2 +- rslib/src/import_export/package/apkg/import/media.rs | 2 +- rslib/src/import_export/package/apkg/import/mod.rs | 10 +++++----- rslib/src/import_export/package/apkg/import/notes.rs | 2 +- rslib/src/import_export/package/apkg/tests.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/rslib/src/import_export/package/apkg/import/cards.rs b/rslib/src/import_export/package/apkg/import/cards.rs index c5009dd45..b6b01859b 100644 --- a/rslib/src/import_export/package/apkg/import/cards.rs +++ b/rslib/src/import_export/package/apkg/import/cards.rs @@ -65,7 +65,7 @@ impl Collection { } } -impl Context<'_, F> { +impl Context<'_> { pub(super) fn import_cards_and_revlog( &mut self, imported_notes: &HashMap, diff --git a/rslib/src/import_export/package/apkg/import/decks.rs b/rslib/src/import_export/package/apkg/import/decks.rs index 5de4654c5..35b035a54 100644 --- a/rslib/src/import_export/package/apkg/import/decks.rs +++ b/rslib/src/import_export/package/apkg/import/decks.rs @@ -26,7 +26,7 @@ impl<'d> DeckContext<'d> { } } -impl Context<'_, F> { +impl Context<'_> { pub(super) fn import_decks_and_configs(&mut self) -> Result> { let mut ctx = DeckContext::new(self.target_col, self.usn); ctx.import_deck_configs(mem::take(&mut self.data.deck_configs))?; diff --git a/rslib/src/import_export/package/apkg/import/media.rs b/rslib/src/import_export/package/apkg/import/media.rs index e5a8ca426..29e144cc8 100644 --- a/rslib/src/import_export/package/apkg/import/media.rs +++ b/rslib/src/import_export/package/apkg/import/media.rs @@ -32,7 +32,7 @@ pub(super) struct MediaUseMap { unchecked: Vec, } -impl Result<()>> Context<'_, F> { +impl Context<'_> { pub(super) fn prepare_media(&mut self) -> Result { let progress_fn = |u| (&mut self.progress_fn)(ImportProgress::MediaCheck(u)).is_ok(); let existing_sha1s = self.target_col.all_existing_sha1s(progress_fn)?; diff --git a/rslib/src/import_export/package/apkg/import/mod.rs b/rslib/src/import_export/package/apkg/import/mod.rs index 94c3d7de6..bec8598a4 100644 --- a/rslib/src/import_export/package/apkg/import/mod.rs +++ b/rslib/src/import_export/package/apkg/import/mod.rs @@ -20,19 +20,19 @@ use crate::{ search::SearchNode, }; -struct Context<'a, F> { +struct Context<'a> { target_col: &'a mut Collection, archive: ZipArchive, data: ExchangeData, usn: Usn, - progress_fn: F, + progress_fn: &'a mut dyn Fn(ImportProgress) -> Result<()>, } impl Collection { pub fn import_apkg( &mut self, path: impl AsRef, - progress_fn: impl FnMut(ImportProgress) -> Result<()>, + progress_fn: &mut dyn Fn(ImportProgress) -> Result<()>, ) -> Result> { let file = File::open(path)?; let archive = ZipArchive::new(file)?; @@ -44,11 +44,11 @@ impl Collection { } } -impl<'a, F: FnMut(ImportProgress) -> Result<()>> Context<'a, F> { +impl<'a> Context<'a> { fn new( mut archive: ZipArchive, target_col: &'a mut Collection, - progress_fn: F, + progress_fn: &'a mut dyn Fn(ImportProgress) -> Result<()>, ) -> Result { let data = ExchangeData::gather_from_archive(&mut archive, SearchNode::WholeCollection, true)?; diff --git a/rslib/src/import_export/package/apkg/import/notes.rs b/rslib/src/import_export/package/apkg/import/notes.rs index c35b8ad0c..9f3a15537 100644 --- a/rslib/src/import_export/package/apkg/import/notes.rs +++ b/rslib/src/import_export/package/apkg/import/notes.rs @@ -43,7 +43,7 @@ impl NoteMeta { } } -impl Context<'_, F> { +impl Context<'_> { pub(super) fn import_notes_and_notetypes( &mut self, media_map: &mut MediaUseMap, diff --git a/rslib/src/import_export/package/apkg/tests.rs b/rslib/src/import_export/package/apkg/tests.rs index 557245898..596e1c056 100644 --- a/rslib/src/import_export/package/apkg/tests.rs +++ b/rslib/src/import_export/package/apkg/tests.rs @@ -39,7 +39,7 @@ fn roundtrip() { |_| (), ) .unwrap(); - target_col.import_apkg(&apkg_path, |_| Ok(())).unwrap(); + target_col.import_apkg(&apkg_path, &mut |_| Ok(())).unwrap(); target_col.assert_decks(); target_col.assert_notetype(¬etype);