Skip to content

Commit 9be7c68

Browse files
committed
refactor: [torrust#1491] remove redundant type aliases
1 parent 71aa8d0 commit 9be7c68

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
pub mod peer_list;
22
pub mod torrent;
3+
4+
use std::sync::{Arc, Mutex};
5+
6+
pub type TorrentEntry = Arc<Mutex<torrent::Torrent>>;

packages/torrent-repository/src/lib.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
use std::sync::{Arc, Mutex};
2-
3-
use torrust_tracker_clock::clock;
4-
51
pub mod entry;
62
pub mod repository;
73

8-
// Repo entry
9-
pub type TorrentEntry = EntryMutexStd;
10-
11-
// Repository
12-
pub type Torrents = TorrentsSkipMapMutexStd;
13-
14-
// The internal type of the entry
15-
pub(crate) type EntryMutexStd = Arc<Mutex<entry::torrent::Torrent>>;
4+
use torrust_tracker_clock::clock;
165

17-
// The internal type of the repository
18-
pub(crate) type TorrentsSkipMapMutexStd = repository::TorrentsSkipMapMutexStd;
6+
pub type TorrentEntry = entry::TorrentEntry;
7+
pub type Torrent = entry::torrent::Torrent;
8+
pub type Torrents = repository::TorrentsSkipMapMutexStd;
199

20-
/// This code needs to be copied into each crate.
2110
/// Working version, for production.
2211
#[cfg(not(test))]
2312
#[allow(dead_code)]

packages/torrent-repository/src/repository.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, PersistentTorrent
77

88
use crate::entry::peer_list::PeerList;
99
use crate::entry::torrent::Torrent;
10-
use crate::EntryMutexStd;
10+
use crate::TorrentEntry;
1111

1212
#[derive(Default, Debug)]
1313
pub struct TorrentsSkipMapMutexStd {
14-
pub torrents: SkipMap<InfoHash, EntryMutexStd>,
14+
pub torrents: SkipMap<InfoHash, TorrentEntry>,
1515
}
1616

1717
impl TorrentsSkipMapMutexStd {
@@ -53,15 +53,15 @@ impl TorrentsSkipMapMutexStd {
5353
tracing::debug!("Inserting new torrent: {:?}", info_hash);
5454

5555
let new_entry = if let Some(number_of_downloads) = opt_persistent_torrent {
56-
EntryMutexStd::new(
56+
TorrentEntry::new(
5757
Torrent {
5858
swarm: PeerList::default(),
5959
downloaded: number_of_downloads,
6060
}
6161
.into(),
6262
)
6363
} else {
64-
EntryMutexStd::default()
64+
TorrentEntry::default()
6565
};
6666

6767
let inserted_entry = self.torrents.get_or_insert(*info_hash, new_entry);
@@ -85,7 +85,7 @@ impl TorrentsSkipMapMutexStd {
8585
})
8686
}
8787

88-
pub fn get(&self, key: &InfoHash) -> Option<EntryMutexStd> {
88+
pub fn get(&self, key: &InfoHash) -> Option<TorrentEntry> {
8989
let maybe_entry = self.torrents.get(key);
9090
maybe_entry.map(|entry| entry.value().clone())
9191
}
@@ -107,7 +107,7 @@ impl TorrentsSkipMapMutexStd {
107107
metrics
108108
}
109109

110-
pub fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, EntryMutexStd)> {
110+
pub fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, TorrentEntry)> {
111111
match pagination {
112112
Some(pagination) => self
113113
.torrents
@@ -130,7 +130,7 @@ impl TorrentsSkipMapMutexStd {
130130
continue;
131131
}
132132

133-
let entry = EntryMutexStd::new(
133+
let entry = TorrentEntry::new(
134134
Torrent {
135135
swarm: PeerList::default(),
136136
downloaded: *completed,
@@ -144,7 +144,7 @@ impl TorrentsSkipMapMutexStd {
144144
}
145145
}
146146

147-
pub fn remove(&self, key: &InfoHash) -> Option<EntryMutexStd> {
147+
pub fn remove(&self, key: &InfoHash) -> Option<TorrentEntry> {
148148
self.torrents.remove(key).map(|entry| entry.value().clone())
149149
}
150150

0 commit comments

Comments
 (0)