Skip to content

Commit

Permalink
refactor: make on_collection take a reference
Browse files Browse the repository at this point in the history
This way we avoid a clone
  • Loading branch information
rklaehn committed Feb 8, 2023
1 parent 1a127fa commit 34aa8e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub async fn run<A, B, C, FutA, FutB, FutC>(
where
A: FnOnce() -> FutA,
FutA: Future<Output = Result<()>>,
B: FnMut(Collection) -> FutB,
B: FnMut(&Collection) -> FutB,
FutB: Future<Output = Result<()>>,
C: FnMut(Hash, DataStream, String) -> FutC,
FutC: Future<Output = Result<DataStream>>,
Expand Down Expand Up @@ -187,7 +187,7 @@ where

// decode the collection
let collection = Collection::from_bytes(&data)?;
on_collection(collection.clone()).await?;
on_collection(&collection).await?;

// expect to get blob data in the order they appear in the collection
let mut remaining_size = total_blobs_size;
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ mod tests {
hash,
token,
opts,
|| async move { Ok(()) },
|_collection| async move { Ok(()) },
|| async { Ok(()) },
|_collection| async { Ok(()) },
|got_hash, mut reader, got_name| async move {
assert_eq!(file_hash, got_hash);
let mut got = Vec::new();
Expand Down Expand Up @@ -221,10 +221,10 @@ mod tests {
collection_hash,
provider.auth_token(),
opts,
|| async move { Ok(()) },
|collection| async move {
|| async { Ok(()) },
|collection| {
assert_eq!(collection.blobs.len(), num_blobs);
Ok(())
async { Ok(()) }
},
|got_hash, mut reader, got_name| {
let i = &i;
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ async fn get_interactive(
Ok(())
}
};
let on_collection = |collection: sendme::blobs::Collection| {
let on_collection = |collection: &sendme::blobs::Collection| {
let pb = &pb;
let out_writer = &out_writer;
let name = collection.name().to_string();
let total_entries = collection.total_entries();
let size = collection.total_blobs_size();
async move {
let name = collection.name();
let total_entries = collection.total_entries();
let size = collection.total_blobs_size();
out_writer
.println(format!(
"{} Downloading {name}...",
Expand Down

0 comments on commit 34aa8e1

Please sign in to comment.