Skip to content

Commit 06d950e

Browse files
committed
Make the accessors on TempTag return copies, not references.
For consistency.
1 parent a4fc497 commit 06d950e

File tree

11 files changed

+45
-50
lines changed

11 files changed

+45
-50
lines changed

examples/expiring-tags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ async fn main() -> anyhow::Result<()> {
162162
let expires_at = SystemTime::now()
163163
.checked_add(Duration::from_secs(10))
164164
.unwrap();
165-
create_expiring_tag(&store, &[*a.hash(), *b.hash()], "expiring", expires_at).await?;
165+
create_expiring_tag(&store, &[a.hash(), b.hash()], "expiring", expires_at).await?;
166166

167167
// add a single blob and tag it with an expiry date 60 seconds in the future
168168
let c = batch.add_bytes("blob 3".as_bytes()).await?;
169169
let expires_at = SystemTime::now()
170170
.checked_add(Duration::from_secs(60))
171171
.unwrap();
172-
create_expiring_tag(&store, &[*c.hash()], "expiring", expires_at).await?;
172+
create_expiring_tag(&store, &[c.hash()], "expiring", expires_at).await?;
173173
// batch goes out of scope, so data is only protected by the tags we created
174174
}
175175

examples/transfer-collection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ impl Node {
8080

8181
let collection_items = collection_items
8282
.iter()
83-
.map(|(name, tag)| (name.to_string(), *tag.hash()))
83+
.map(|(name, tag)| (name.to_string(), tag.hash()))
8484
.collect::<Vec<_>>();
8585

8686
let collection = Collection::from_iter(collection_items);
8787

8888
let tt = collection.store(&self.store).await?;
89-
self.store.tags().create(*tt.hash_and_format()).await?;
90-
Ok(*tt.hash())
89+
self.store.tags().create(tt.hash_and_format()).await?;
90+
Ok(tt.hash())
9191
}
9292

9393
/// retrieve an entire collection from a given hash and provider

src/api/blobs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,20 +656,20 @@ impl<'a> AddProgress<'a> {
656656
pub async fn with_named_tag(self, name: impl AsRef<[u8]>) -> RequestResult<HashAndFormat> {
657657
let blobs = self.blobs.clone();
658658
let tt = self.temp_tag().await?;
659-
let haf = *tt.hash_and_format();
659+
let haf = tt.hash_and_format();
660660
let tags = Tags::ref_from_sender(&blobs.client);
661-
tags.set(name, *tt.hash_and_format()).await?;
661+
tags.set(name, haf).await?;
662662
drop(tt);
663663
Ok(haf)
664664
}
665665

666666
pub async fn with_tag(self) -> RequestResult<TagInfo> {
667667
let blobs = self.blobs.clone();
668668
let tt = self.temp_tag().await?;
669-
let hash = *tt.hash();
669+
let hash = tt.hash();
670670
let format = tt.format();
671671
let tags = Tags::ref_from_sender(&blobs.client);
672-
let name = tags.create(*tt.hash_and_format()).await?;
672+
let name = tags.create(tt.hash_and_format()).await?;
673673
drop(tt);
674674
Ok(TagInfo { name, hash, format })
675675
}

src/api/remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ mod tests {
10881088
let store = FsStore::load(td.path().join("blobs.db")).await?;
10891089
let blobs = store.blobs();
10901090
let tt = blobs.add_slice(b"test").temp_tag().await?;
1091-
let hash = *tt.hash();
1091+
let hash = tt.hash();
10921092
let info = store.remote().local(hash).await?;
10931093
assert_eq!(info.bitfield.ranges, ChunkRanges::all());
10941094
assert_eq!(info.local_bytes(), 4);

src/format/collection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Collection {
191191
let (links, meta) = self.into_parts();
192192
let meta_bytes = postcard::to_stdvec(&meta)?;
193193
let meta_tag = db.add_bytes(meta_bytes).temp_tag().await?;
194-
let links_bytes = std::iter::once(*meta_tag.hash())
194+
let links_bytes = std::iter::once(meta_tag.hash())
195195
.chain(links)
196196
.collect::<HashSeq>();
197197
let links_tag = db

src/store/fs.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ pub mod tests {
16021602
let stream = bytes_to_stream(expected.clone(), 1023);
16031603
let obs = store.observe(expected_hash);
16041604
let tt = store.add_stream(stream).await.temp_tag().await?;
1605-
assert_eq!(expected_hash, *tt.hash());
1605+
assert_eq!(expected_hash, tt.hash());
16061606
// we must at some point see completion, otherwise the test will hang
16071607
obs.await_completion().await?;
16081608
let actual = store.get_bytes(expected_hash).await?;
@@ -2043,8 +2043,8 @@ pub mod tests {
20432043
.await?
20442044
.collect::<HashSet<_>>()
20452045
.await;
2046-
assert!(tts.contains(tt1.hash_and_format()));
2047-
assert!(tts.contains(tt2.hash_and_format()));
2046+
assert!(tts.contains(&tt1.hash_and_format()));
2047+
assert!(tts.contains(&tt2.hash_and_format()));
20482048
drop(batch);
20492049
store.sync_db().await?;
20502050
store.wait_idle().await?;
@@ -2055,8 +2055,8 @@ pub mod tests {
20552055
.collect::<HashSet<_>>()
20562056
.await;
20572057
// temp tag went out of scope, so it does not work anymore
2058-
assert!(!tts.contains(tt1.hash_and_format()));
2059-
assert!(!tts.contains(tt2.hash_and_format()));
2058+
assert!(!tts.contains(&tt1.hash_and_format()));
2059+
assert!(!tts.contains(&tt2.hash_and_format()));
20602060
drop(tt1);
20612061
drop(tt2);
20622062
Ok(())
@@ -2089,29 +2089,29 @@ pub mod tests {
20892089
let data = vec![0u8; size];
20902090
let data = Bytes::from(data);
20912091
let tt = store.add_bytes(data.clone()).temp_tag().await?;
2092-
data_by_hash.insert(*tt.hash(), data);
2092+
data_by_hash.insert(tt.hash(), data);
20932093
hashes.push(tt);
20942094
}
20952095
store.sync_db().await?;
20962096
for tt in &hashes {
2097-
let hash = *tt.hash();
2097+
let hash = tt.hash();
20982098
let path = testdir.path().join(format!("{hash}.txt"));
20992099
store.export(hash, path).await?;
21002100
}
21012101
for tt in &hashes {
21022102
let hash = tt.hash();
21032103
let data = store
2104-
.export_bao(*hash, ChunkRanges::all())
2104+
.export_bao(hash, ChunkRanges::all())
21052105
.data_to_vec()
21062106
.await
21072107
.unwrap();
2108-
assert_eq!(data, data_by_hash[hash].to_vec());
2108+
assert_eq!(data, data_by_hash[&hash].to_vec());
21092109
let bao = store
2110-
.export_bao(*hash, ChunkRanges::all())
2110+
.export_bao(hash, ChunkRanges::all())
21112111
.bao_to_vec()
21122112
.await
21132113
.unwrap();
2114-
bao_by_hash.insert(*hash, bao);
2114+
bao_by_hash.insert(hash, bao);
21152115
}
21162116
store.dump().await?;
21172117

src/store/gc.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ mod tests {
263263
let ft = blobs.add_slice("f").temp_tag().await?;
264264
let gt = blobs.add_slice("g").temp_tag().await?;
265265
let ht = blobs.add_slice("h").with_named_tag("h").await?;
266-
let a = *at.hash();
267-
let b = *bt.hash();
268-
let c = *ct.hash();
269-
let d = *dt.hash();
270-
let e = *et.hash();
271-
let f = *ft.hash();
272-
let g = *gt.hash();
266+
let a = at.hash();
267+
let b = bt.hash();
268+
let c = ct.hash();
269+
let d = dt.hash();
270+
let e = et.hash();
271+
let f = ft.hash();
272+
let g = gt.hash();
273273
let h = ht.hash;
274-
store.tags().set("c", *ct.hash_and_format()).await?;
274+
store.tags().set("c", ct.hash_and_format()).await?;
275275
let dehs = [d, e].into_iter().collect::<HashSeq>();
276276
let hehs = blobs
277277
.add_bytes_with_opts(AddBytesOptions {
@@ -287,7 +287,7 @@ mod tests {
287287
})
288288
.temp_tag()
289289
.await?;
290-
store.tags().set("fg", *fghs.hash_and_format()).await?;
290+
store.tags().set("fg", fghs.hash_and_format()).await?;
291291
drop(fghs);
292292
drop(bt);
293293
store.tags().delete("h").await?;
@@ -335,11 +335,11 @@ mod tests {
335335
.temp_tag()
336336
.await?;
337337
let ah = a.hash();
338-
let data_path = options.data_path(ah);
339-
let outboard_path = options.outboard_path(ah);
338+
let data_path = options.data_path(&ah);
339+
let outboard_path = options.outboard_path(&ah);
340340
assert!(data_path.exists());
341341
assert!(outboard_path.exists());
342-
assert!(store.has(*ah).await?);
342+
assert!(store.has(ah).await?);
343343
drop(a);
344344
gc_run_once(store, &mut live).await?;
345345
assert!(!data_path.exists());
@@ -410,7 +410,7 @@ mod tests {
410410

411411
async fn gc_check_deletion(store: &Store) -> TestResult {
412412
let temp_tag = store.add_bytes(b"foo".to_vec()).temp_tag().await?;
413-
let hash = *temp_tag.hash();
413+
let hash = temp_tag.hash();
414414
assert_eq!(store.get_bytes(hash).await?.as_ref(), b"foo");
415415
drop(temp_tag);
416416
let mut live = HashSet::new();

src/store/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ mod tests {
10871087
async fn smoke() -> TestResult<()> {
10881088
let store = MemStore::new();
10891089
let tt = store.add_bytes(vec![0u8; 1024 * 64]).temp_tag().await?;
1090-
let hash = *tt.hash();
1090+
let hash = tt.hash();
10911091
println!("hash: {hash:?}");
10921092
let mut stream = store.export_bao(hash, ChunkRanges::all()).stream();
10931093
while let Some(item) = stream.next().await {

src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ pub async fn add_test_hash_seq(
435435
for size in sizes {
436436
tts.push(batch.add_bytes(test_data(size)).await?);
437437
}
438-
let hash_seq = tts.iter().map(|tt| *tt.hash()).collect::<HashSeq>();
438+
let hash_seq = tts.iter().map(|tt| tt.hash()).collect::<HashSeq>();
439439
let root = batch
440440
.add_bytes_with_opts((hash_seq, BlobFormat::HashSeq))
441441
.with_named_tag("hs")
@@ -461,7 +461,7 @@ pub async fn add_test_hash_seq_incomplete(
461461
blobs.import_bao_bytes(hash, ranges, bao).await?;
462462
}
463463
}
464-
let hash_seq = tts.iter().map(|tt| *tt.hash()).collect::<HashSeq>();
464+
let hash_seq = tts.iter().map(|tt| tt.hash()).collect::<HashSeq>();
465465
let hash_seq_bytes = Bytes::from(hash_seq);
466466
let ranges = present(0);
467467
let (root, bao) = create_n0_bao(&hash_seq_bytes, &ranges)?;
@@ -673,7 +673,7 @@ async fn node_smoke_mem() -> TestResult<()> {
673673

674674
async fn node_smoke(store: &Store) -> TestResult<()> {
675675
let tt = store.add_bytes(b"hello world".to_vec()).temp_tag().await?;
676-
let hash = *tt.hash();
676+
let hash = tt.hash();
677677
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
678678
let blobs = crate::net_protocol::BlobsProtocol::new(store, None);
679679
let r1 = Router::builder(endpoint)
@@ -701,7 +701,7 @@ async fn test_export_chunk() -> TestResult {
701701
for size in [1024 * 18 + 1] {
702702
let data = vec![0u8; size];
703703
let tt = store.add_slice(&data).temp_tag().await?;
704-
let hash = *tt.hash();
704+
let hash = tt.hash();
705705
let c = blobs.export_chunk(hash, 0).await;
706706
println!("{c:?}");
707707
let c = blobs.export_chunk(hash, 1000000).await;

src/util/temp_tag.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,8 @@ impl TempTag {
9898
}
9999

100100
/// The hash of the pinned item
101-
pub fn inner(&self) -> &HashAndFormat {
102-
&self.inner
103-
}
104-
105-
/// The hash of the pinned item
106-
pub fn hash(&self) -> &Hash {
107-
&self.inner.hash
101+
pub fn hash(&self) -> Hash {
102+
self.inner.hash
108103
}
109104

110105
/// The format of the pinned item
@@ -113,8 +108,8 @@ impl TempTag {
113108
}
114109

115110
/// The hash and format of the pinned item
116-
pub fn hash_and_format(&self) -> &HashAndFormat {
117-
&self.inner
111+
pub fn hash_and_format(&self) -> HashAndFormat {
112+
self.inner
118113
}
119114

120115
/// Keep the item alive until the end of the process

0 commit comments

Comments
 (0)