Skip to content

Commit 9b2392e

Browse files
committed
refactor: [torrust#1495] make TrackedTorrent fields private
1 parent 82bbfe3 commit 9b2392e

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

packages/torrent-repository/src/entry/torrent.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ use super::swarm::Swarm;
1919
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
2020
pub struct TrackedTorrent {
2121
/// A network of peers that are all trying to download the torrent.
22-
pub(crate) swarm: Swarm,
22+
swarm: Swarm,
2323

2424
/// The number of peers that have ever completed downloading the torrent.
2525
/// This value is can be persistent so it's loaded from the database when
2626
/// the tracker starts.
27-
pub(crate) downloaded: u32,
27+
downloaded: u32,
2828
}
2929

3030
impl TrackedTorrent {
31+
#[must_use]
32+
pub fn new(swarm: Swarm, downloaded: u32) -> Self {
33+
Self { swarm, downloaded }
34+
}
35+
3136
#[must_use]
3237
pub fn get_swarm_metadata(&self) -> SwarmMetadata {
3338
let metadata = self.swarm.metadata();

packages/torrent-repository/src/repository.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ impl TorrentRepository {
5151
tracing::debug!("Inserting new torrent: {:?}", info_hash);
5252

5353
let new_entry = if let Some(number_of_downloads) = opt_persistent_torrent {
54-
TrackedTorrentHandle::new(
55-
TrackedTorrent {
56-
swarm: Swarm::default(),
57-
downloaded: number_of_downloads,
58-
}
59-
.into(),
60-
)
54+
TrackedTorrentHandle::new(TrackedTorrent::new(Swarm::default(), number_of_downloads).into())
6155
} else {
6256
TrackedTorrentHandle::default()
6357
};
@@ -235,13 +229,7 @@ impl TorrentRepository {
235229
continue;
236230
}
237231

238-
let entry = TrackedTorrentHandle::new(
239-
TrackedTorrent {
240-
swarm: Swarm::default(),
241-
downloaded: *completed,
242-
}
243-
.into(),
244-
);
232+
let entry = TrackedTorrentHandle::new(TrackedTorrent::new(Swarm::default(), *completed).into());
245233

246234
// Since SkipMap is lock-free the torrent could have been inserted
247235
// after checking if it exists.

0 commit comments

Comments
 (0)