diff --git a/crates/core/tests/integration.rs b/crates/core/tests/integration.rs index 15e9242b9..5a1c21e77 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,32 @@ 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 mut collection: Vec = Vec::new(); + + collection.push(Wrapper::new()?); + collection.push(Wrapper::new()?); + + collection.iter().map(|r| &r.0).for_each(use_repo); + + Ok(()) +}