From a4a503dc1a419a28343399e97f0473fa3f751d2c Mon Sep 17 00:00:00 2001 From: Til Blechschmidt Date: Sat, 8 Jun 2024 20:36:55 +0200 Subject: [PATCH 1/2] fix: Export `FullIndex` and `IndexedStatus` so the Repository type can be fully specified --- crates/core/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 5df9ccff..d2584b04 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -148,5 +148,7 @@ pub use crate::{ repofile::snapshotfile::{ PathList, SnapshotGroup, SnapshotGroupCriterion, SnapshotOptions, StringList, }, - repository::{IndexedFull, OpenStatus, Repository, RepositoryOptions}, + repository::{ + FullIndex, IndexedFull, IndexedStatus, OpenStatus, Repository, RepositoryOptions, + }, }; From fc987ca5069cc942847ad0b93b654f99ee87c8a8 Mon Sep 17 00:00:00 2001 From: Til Blechschmidt Date: Fri, 14 Jun 2024 23:26:18 +0200 Subject: [PATCH 2/2] test: Check ability to create wrapper types around repository --- crates/core/tests/integration.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/core/tests/integration.rs b/crates/core/tests/integration.rs index 15e9242b..6acc2e3e 100644 --- a/crates/core/tests/integration.rs +++ b/crates/core/tests/integration.rs @@ -35,8 +35,8 @@ use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; use rustic_core::{ repofile::SnapshotFile, BackupOptions, CheckOptions, ConfigOptions, FindMatches, FindNode, - KeyOptions, LimitOption, LsOptions, NoProgressBars, OpenStatus, PathList, Repository, - RepositoryBackends, RepositoryOptions, RusticResult, + FullIndex, IndexedFull, IndexedStatus, KeyOptions, LimitOption, LsOptions, NoProgressBars, + OpenStatus, PathList, Repository, RepositoryBackends, RepositoryOptions, RusticResult, }; use rustic_core::{ repofile::{Metadata, Node}, @@ -464,3 +464,29 @@ fn test_prune( Ok(()) } + +/// Verifies that users can create wrappers around repositories +/// without resorting to generics. The rationale is that such +/// types can be used to dynamically open, store, and cache repos. +/// +/// See issue #277 for more context. +#[test] +fn test_wrapping_in_new_type() -> Result<()> { + struct Wrapper(Repository>); + + impl Wrapper { + fn new() -> Result { + Ok(Self(set_up_repo()?.to_indexed()?)) + } + } + + /// Fake function that "does something" with a fully indexed repo + /// (without actually relying on any functionality for the test) + fn use_repo(_: &impl IndexedFull) {} + + let collection: Vec = vec![Wrapper::new()?, Wrapper::new()?]; + + collection.iter().map(|r| &r.0).for_each(use_repo); + + Ok(()) +}