Use fat pointer to avoid propogating generics

This commit is contained in:
RumovZ 2022-04-16 22:14:01 +02:00
parent ed24fd13db
commit e65b79ba63
6 changed files with 10 additions and 10 deletions

View file

@ -65,7 +65,7 @@ impl Collection {
}
}
impl<F> Context<'_, F> {
impl Context<'_> {
pub(super) fn import_cards_and_revlog(
&mut self,
imported_notes: &HashMap<NoteId, NoteId>,

View file

@ -26,7 +26,7 @@ impl<'d> DeckContext<'d> {
}
}
impl<F> Context<'_, F> {
impl Context<'_> {
pub(super) fn import_decks_and_configs(&mut self) -> Result<HashMap<DeckId, DeckId>> {
let mut ctx = DeckContext::new(self.target_col, self.usn);
ctx.import_deck_configs(mem::take(&mut self.data.deck_configs))?;

View file

@ -32,7 +32,7 @@ pub(super) struct MediaUseMap {
unchecked: Vec<SafeMediaEntry>,
}
impl<F: FnMut(ImportProgress) -> Result<()>> Context<'_, F> {
impl Context<'_> {
pub(super) fn prepare_media(&mut self) -> Result<MediaUseMap> {
let progress_fn = |u| (&mut self.progress_fn)(ImportProgress::MediaCheck(u)).is_ok();
let existing_sha1s = self.target_col.all_existing_sha1s(progress_fn)?;

View file

@ -20,19 +20,19 @@ use crate::{
search::SearchNode,
};
struct Context<'a, F> {
struct Context<'a> {
target_col: &'a mut Collection,
archive: ZipArchive<File>,
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<Path>,
progress_fn: impl FnMut(ImportProgress) -> Result<()>,
progress_fn: &mut dyn Fn(ImportProgress) -> Result<()>,
) -> Result<OpOutput<()>> {
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<File>,
target_col: &'a mut Collection,
progress_fn: F,
progress_fn: &'a mut dyn Fn(ImportProgress) -> Result<()>,
) -> Result<Self> {
let data =
ExchangeData::gather_from_archive(&mut archive, SearchNode::WholeCollection, true)?;

View file

@ -43,7 +43,7 @@ impl NoteMeta {
}
}
impl<F> Context<'_, F> {
impl Context<'_> {
pub(super) fn import_notes_and_notetypes(
&mut self,
media_map: &mut MediaUseMap,

View file

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