misc: clippy fixes

This commit is contained in:
Kat Marchán 2023-01-28 15:42:27 -08:00
parent dca57e1100
commit 2767a6a671
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
3 changed files with 59 additions and 59 deletions

View File

@ -43,7 +43,7 @@ fn baseline_read_many_sync(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap(); let tmp = tempfile::tempdir().unwrap();
let paths: Vec<_> = (0..) let paths: Vec<_> = (0..)
.take(NUM_REPEATS) .take(NUM_REPEATS)
.map(|i| tmp.path().join(format!("test_file_{}", i))) .map(|i| tmp.path().join(format!("test_file_{i}")))
.collect(); .collect();
let data = b"hello world"; let data = b"hello world";
for path in paths.iter() { for path in paths.iter() {
@ -76,7 +76,7 @@ fn baseline_read_many_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap(); let tmp = tempfile::tempdir().unwrap();
let paths: Vec<_> = (0..) let paths: Vec<_> = (0..)
.take(NUM_REPEATS) .take(NUM_REPEATS)
.map(|i| tmp.path().join(format!("test_file_{}", i))) .map(|i| tmp.path().join(format!("test_file_{i}")))
.collect(); .collect();
let data = b"hello world"; let data = b"hello world";
for path in paths.iter() { for path in paths.iter() {
@ -107,7 +107,7 @@ fn read_hash_many_sync(c: &mut Criterion) {
let cache = tmp.path().to_owned(); let cache = tmp.path().to_owned();
let data: Vec<_> = (0..) let data: Vec<_> = (0..)
.take(NUM_REPEATS) .take(NUM_REPEATS)
.map(|i| format!("test_file_{}", i)) .map(|i| format!("test_file_{i}"))
.collect(); .collect();
let sris: Vec<_> = data let sris: Vec<_> = data
.iter() .iter()
@ -147,7 +147,7 @@ fn read_hash_many_async(c: &mut Criterion) {
let cache = tmp.path().to_owned(); let cache = tmp.path().to_owned();
let data: Vec<_> = (0..) let data: Vec<_> = (0..)
.take(NUM_REPEATS) .take(NUM_REPEATS)
.map(|i| format!("test_file_{}", i)) .map(|i| format!("test_file_{i}"))
.collect(); .collect();
let sris: Vec<_> = data let sris: Vec<_> = data
.iter() .iter()
@ -200,7 +200,7 @@ fn write_hash_async(c: &mut Criterion) {
b.iter_custom(|iters| { b.iter_custom(|iters| {
let start = std::time::Instant::now(); let start = std::time::Instant::now();
for i in 0..iters { for i in 0..iters {
block_on(cacache::write_hash(&cache, format!("hello world{}", i))).unwrap(); block_on(cacache::write_hash(&cache, format!("hello world{i}"))).unwrap();
} }
start.elapsed() start.elapsed()
}) })

View File

@ -12,7 +12,7 @@ pub fn content_path(cache: &Path, sri: &Integrity) -> PathBuf {
let mut path = PathBuf::new(); let mut path = PathBuf::new();
let (algo, hex) = sri.to_hex(); let (algo, hex) = sri.to_hex();
path.push(cache); path.push(cache);
path.push(format!("content-v{}", CONTENT_VERSION)); path.push(format!("content-v{CONTENT_VERSION}"));
path.push(algo.to_string()); path.push(algo.to_string());
path.push(&hex[0..2]); path.push(&hex[0..2]);
path.push(&hex[2..4]); path.push(&hex[2..4]);
@ -32,7 +32,7 @@ mod tests {
let cpath = content_path(Path::new("~/.my-cache"), &sri); let cpath = content_path(Path::new("~/.my-cache"), &sri);
let mut wanted = PathBuf::new(); let mut wanted = PathBuf::new();
wanted.push("~/.my-cache"); wanted.push("~/.my-cache");
wanted.push(format!("content-v{}", CONTENT_VERSION)); wanted.push(format!("content-v{CONTENT_VERSION}"));
wanted.push("sha256"); wanted.push("sha256");
wanted.push("b9"); wanted.push("b9");
wanted.push("4d"); wanted.push("4d");

View File

@ -74,19 +74,19 @@ pub fn insert(cache: &Path, key: &str, opts: WriteOpts) -> Result<Integrity> {
size: opts.size.unwrap_or(0), size: opts.size.unwrap_or(0),
metadata: opts.metadata.unwrap_or(serde_json::Value::Null), metadata: opts.metadata.unwrap_or(serde_json::Value::Null),
}) })
.with_context(|| format!("Failed to serialize entry with key `{}`", key))?; .with_context(|| format!("Failed to serialize entry with key `{key}`"))?;
let mut buck = OpenOptions::new() let mut buck = OpenOptions::new()
.create(true) .create(true)
.append(true) .append(true)
.open(&bucket) .open(&bucket)
.with_context(|| format!("Failed to create or open index bucket at {:?}", bucket))?; .with_context(|| format!("Failed to create or open index bucket at {bucket:?}"))?;
let out = format!("\n{}\t{}", hash_entry(&stringified), stringified); let out = format!("\n{}\t{}", hash_entry(&stringified), stringified);
buck.write_all(out.as_bytes()) buck.write_all(out.as_bytes())
.with_context(|| format!("Failed to write to index bucket at {:?}", bucket))?; .with_context(|| format!("Failed to write to index bucket at {bucket:?}"))?;
buck.flush() buck.flush()
.with_context(|| format!("Failed to flush bucket at {:?}", bucket))?; .with_context(|| format!("Failed to flush bucket at {bucket:?}"))?;
Ok(opts Ok(opts
.sri .sri
.or_else(|| "sha1-deadbeef".parse::<Integrity>().ok()) .or_else(|| "sha1-deadbeef".parse::<Integrity>().ok())
@ -110,22 +110,22 @@ pub async fn insert_async<'a>(cache: &'a Path, key: &'a str, opts: WriteOpts) ->
size: opts.size.unwrap_or(0), size: opts.size.unwrap_or(0),
metadata: opts.metadata.unwrap_or(serde_json::Value::Null), metadata: opts.metadata.unwrap_or(serde_json::Value::Null),
}) })
.with_context(|| format!("Failed to serialize entry with key `{}`", key))?; .with_context(|| format!("Failed to serialize entry with key `{key}`"))?;
let mut buck = crate::async_lib::OpenOptions::new() let mut buck = crate::async_lib::OpenOptions::new()
.create(true) .create(true)
.append(true) .append(true)
.open(&bucket) .open(&bucket)
.await .await
.with_context(|| format!("Failed to create or open index bucket at {:?}", bucket))?; .with_context(|| format!("Failed to create or open index bucket at {bucket:?}"))?;
let out = format!("\n{}\t{}", hash_entry(&stringified), stringified); let out = format!("\n{}\t{}", hash_entry(&stringified), stringified);
buck.write_all(out.as_bytes()) buck.write_all(out.as_bytes())
.await .await
.with_context(|| format!("Failed to write to index bucket at {:?}", bucket))?; .with_context(|| format!("Failed to write to index bucket at {bucket:?}"))?;
buck.flush() buck.flush()
.await .await
.with_context(|| format!("Failed to flush bucket at {:?}", bucket))?; .with_context(|| format!("Failed to flush bucket at {bucket:?}"))?;
Ok(opts Ok(opts
.sri .sri
.or_else(|| "sha1-deadbeef".parse::<Integrity>().ok()) .or_else(|| "sha1-deadbeef".parse::<Integrity>().ok())
@ -135,7 +135,7 @@ pub async fn insert_async<'a>(cache: &'a Path, key: &'a str, opts: WriteOpts) ->
pub fn find(cache: &Path, key: &str) -> Result<Option<Metadata>> { pub fn find(cache: &Path, key: &str) -> Result<Option<Metadata>> {
let bucket = bucket_path(cache, key); let bucket = bucket_path(cache, key);
Ok(bucket_entries(&bucket) Ok(bucket_entries(&bucket)
.with_context(|| format!("Failed to read index bucket entries from {:?}", bucket))? .with_context(|| format!("Failed to read index bucket entries from {bucket:?}"))?
.into_iter() .into_iter()
.fold(None, |acc, entry| { .fold(None, |acc, entry| {
if entry.key == key { if entry.key == key {
@ -164,7 +164,7 @@ pub async fn find_async(cache: &Path, key: &str) -> Result<Option<Metadata>> {
let bucket = bucket_path(cache, key); let bucket = bucket_path(cache, key);
Ok(bucket_entries_async(&bucket) Ok(bucket_entries_async(&bucket)
.await .await
.with_context(|| format!("Failed to read index bucket entries from {:?}", bucket))? .with_context(|| format!("Failed to read index bucket entries from {bucket:?}"))?
.into_iter() .into_iter()
.fold(None, |acc, entry| { .fold(None, |acc, entry| {
if entry.key == key { if entry.key == key {
@ -220,7 +220,7 @@ pub async fn delete_async(cache: &Path, key: &str) -> Result<()> {
} }
pub fn ls(cache: &Path) -> impl Iterator<Item = Result<Metadata>> { pub fn ls(cache: &Path) -> impl Iterator<Item = Result<Metadata>> {
WalkDir::new(cache.join(format!("index-v{}", INDEX_VERSION))) WalkDir::new(cache.join(format!("index-v{INDEX_VERSION}")))
.into_iter() .into_iter()
.map(|bucket| { .map(|bucket| {
let bucket = bucket.to_internal()?; let bucket = bucket.to_internal()?;
@ -257,7 +257,7 @@ pub fn ls(cache: &Path) -> impl Iterator<Item = Result<Metadata>> {
fn bucket_path(cache: &Path, key: &str) -> PathBuf { fn bucket_path(cache: &Path, key: &str) -> PathBuf {
let hashed = hash_key(key); let hashed = hash_key(key);
cache cache
.join(format!("index-v{}", INDEX_VERSION)) .join(format!("index-v{INDEX_VERSION}"))
.join(&hashed[0..2]) .join(&hashed[0..2])
.join(&hashed[2..4]) .join(&hashed[2..4])
.join(&hashed[4..]) .join(&hashed[4..])