pub trait PathStrategy {
// Required methods
fn get_containing_directory<T>(&self, repository: T) -> Result<PathBuf>
where T: Into<RepositoryLocation>;
fn get_directory<T>(&self, repository: T) -> Result<PathBuf>
where T: Into<RepositoryLocation>;
}Required Methods§
Sourcefn get_containing_directory<T>(&self, repository: T) -> Result<PathBuf>where
T: Into<RepositoryLocation>,
fn get_containing_directory<T>(&self, repository: T) -> Result<PathBuf>where
T: Into<RepositoryLocation>,
Get the containing directory for a repository
This can work even when the repository doesn’t exist (yet). So this can be used to get the directory to move into, for example.
Grass makes no guarentees that all repositories will be contained in the same directory. You cannot assume that other repositories in the same category are contained in the same directory.
§Example
use grass::dev::strategy::path::{MockPathStrategy, PathStrategy, PathStrategyError};
use std::path::PathBuf;
let strategy = MockPathStrategy;
fn test_strategy<T: PathStrategy>(strategy: &T) {
assert_eq!(
strategy.get_containing_directory(("all_good", "first")),
Ok(PathBuf::from("/home/example/repositories/all_good"))
);
assert_eq!(
strategy.get_containing_directory(("with_changes", "does_not_exist")),
Ok(PathBuf::from("/home/example/repositories/with_changes"))
);
assert!(matches!(
strategy.get_containing_directory(("does_not_exist", "third")),
Err(PathStrategyError::RepositoryNotFound { .. })
));
}
test_strategy(&strategy);Sourcefn get_directory<T>(&self, repository: T) -> Result<PathBuf>where
T: Into<RepositoryLocation>,
fn get_directory<T>(&self, repository: T) -> Result<PathBuf>where
T: Into<RepositoryLocation>,
Get the directory for a repository
This will also work if the path doesn’t exist
§Example
use grass::dev::strategy::path::{MockPathStrategy, PathStrategy, PathStrategyError};
use std::path::PathBuf;
let strategy = MockPathStrategy;
fn test_strategy<T: PathStrategy>(strategy: &T) {
assert_eq!(
strategy.get_directory(("all_good", "first")),
Ok(PathBuf::from("/home/example/repositories/all_good/first"))
);
assert!(matches!(
strategy.get_directory(("all_good", "does_not_exist")),
Err(PathStrategyError::RepositoryNotFound { .. })
));
assert!(matches!(
strategy.get_directory(("does_not_exist", "third")),
Err(PathStrategyError::RepositoryNotFound { .. })
));
}
test_strategy(&strategy);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.