Try to get rid of owned types

Inspired by https://www.youtube.com/watch?v=A4cKi7PTJSs. This turns a
lot of cloning Strings and PathBufs into Rcs.
This commit is contained in:
Adrian Heine 2023-06-17 14:53:38 +02:00
parent e3b425eb1c
commit d091265d27
20 changed files with 343 additions and 232 deletions

View file

@ -3,7 +3,7 @@ use schematics::symbols::file::File as FileSymbol;
use schematics::symbols::Symbol;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::path::Path;
use tempfile::{tempdir, TempDir};
fn get_dir(content: Option<&str>) -> TempDir {
@ -19,8 +19,8 @@ fn get_dir(content: Option<&str>) -> TempDir {
tmp_dir
}
fn get_symbol(path: &Path) -> FileSymbol<PathBuf, &str> {
FileSymbol::new(path.join("filename"), "target content")
fn get_symbol(path: &Path) -> FileSymbol<Box<Path>, &str> {
FileSymbol::new(path.join("filename").into(), "target content")
}
// Normal cases

View file

@ -9,6 +9,7 @@ use schematics::SymbolRunner;
use slog::{info, Logger as SlogLogger};
use std::error::Error;
use std::fmt::Debug;
use std::path::Path;
use std::time::Duration;
#[derive(Clone, Debug)]
@ -60,7 +61,7 @@ fn test(
#[test]
fn can_create_an_acme_user() {
let mut result = test(1, |setup| {
assert_eq!((run(setup.add(AcmeUser)).unwrap().0).0, "acme");
assert_eq!(&*(run(setup.add(AcmeUser)).unwrap().0).0, "acme");
});
let entry = result
.pop()
@ -133,8 +134,8 @@ fn can_create_an_acme_cert() {
#[test]
fn can_create_a_git_checkout() {
let mut result = test(1, |setup| {
run(setup.add(GitCheckout(
"/tmp/somepath".into(),
run(setup.add(GitCheckout::new(
"/tmp/somepath".as_ref() as &Path,
"/tmp/some_src_repo",
"master",
)))

View file

@ -16,7 +16,7 @@ fn get_dir<'a, I: IntoIterator<Item = &'a &'a str>>(content: I) -> TempDir {
}
fn get_storage(path: &Path) -> SimpleStorage {
SimpleStorage::new(path.join("_filename"))
SimpleStorage::new(path.join("_filename").into())
}
// Normal cases
@ -33,7 +33,7 @@ fn single_file() {
);
assert_eq!(
dir.path().join("_filename").join("12345"),
Path::new(&storage.read_filename().unwrap())
Path::new(&*storage.read_filename().unwrap())
);
assert_eq!(storage.recent_date().unwrap(), 12345);
}
@ -50,7 +50,7 @@ fn two_files() {
);
assert_eq!(
dir.path().join("_filename").join("23456"),
Path::new(&storage.read_filename().unwrap())
Path::new(&*storage.read_filename().unwrap())
);
assert_eq!(storage.recent_date().unwrap(), 23456);
}
@ -67,7 +67,7 @@ fn another_two_files() {
);
assert_eq!(
dir.path().join("_filename").join("23456"),
Path::new(&storage.read_filename().unwrap())
Path::new(&*storage.read_filename().unwrap())
);
assert_eq!(storage.recent_date().unwrap(), 23456);
}
@ -84,7 +84,7 @@ fn three_files() {
);
assert_eq!(
dir.path().join("_filename").join("23456"),
Path::new(&storage.read_filename().unwrap())
Path::new(&*storage.read_filename().unwrap())
);
assert_eq!(storage.recent_date().unwrap(), 23456);
}