lt_rs/alerts/torrent_state.rs
1use std::fmt::Display;
2
3/// The missing enums are unused enums from versions of libtorrent before 1.2
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5#[cfg_attr(feature = "safe_enums", derive(num_enum::FromPrimitive))]
6#[repr(u8)]
7pub enum TorrentState {
8 /// The torrent is in the queue for being checked. But there
9 /// currently is another torrent that are being checked.
10 /// This torrent will wait for its turn.
11 // QueuedForChecking = 0,
12
13 /// The torrent has not started its download yet, and is
14 /// currently checking existing files.
15 CheckingFiles,
16 /// The torrent is trying to download metadata from peers.
17 /// This implies the ut_metadata extension is in use.
18 DownloadingMetadata,
19 /// The torrent is being downloaded. This is the state
20 /// most torrents will be in most of the time. The progress
21 /// meter will tell how much of the files that has been
22 /// downloaded.
23 Downloading,
24 /// In this state the torrent has finished downloading but
25 /// still doesn't have the entire torrent. i.e. some pieces
26 /// are filtered and won't get downloaded.
27 Finished,
28 /// In this state the torrent has finished downloading and
29 /// is a pure seeder.
30 Seeding,
31 /// If the torrent was started in full allocation mode, this
32 /// indicates that the (disk) storage for the torrent is
33 /// allocated.
34 // Allocating = 6,
35
36 /// The torrent is currently checking the fast resume data and
37 /// comparing it to the files on disk. This is typically
38 /// completed in a fraction of a second, but if you add a
39 /// large number of torrents at once, they will queue up.
40 CheckingResumeData = 7,
41
42 /// Theoretically this state should never be reached, but
43 /// just in case libtorrent adds a new state and this enum is not updated
44 /// or libtorrent itself somehow reaches an invalid state.
45 #[cfg(feature = "safe_enums")]
46 #[num_enum(default)]
47 Unknown,
48}
49
50impl TorrentState {
51 pub(crate) fn from_u8(v: u8) -> Self {
52 cfg_if::cfg_if! {
53 if #[cfg(feature = "safe_enums")] {
54 v.into()
55 } else {
56 unsafe { std::mem::transmute(v) }
57 }
58 }
59 }
60}
61
62impl Display for TorrentState {
63 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64 write!(f, "{:?}", self)
65 }
66}