Skip to content

Commit 6862bba

Browse files
committed
docs: Add more information about new features
1 parent f4df806 commit 6862bba

4 files changed

Lines changed: 34 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
other variants, and other rust types
2020
- `TrackerScheme` no longer derives de/serialize because that's not actually
2121
used in torrent files
22-
- A torrent file with an invalid tracker URI (such as an unknown scheme) will now
23-
fail to parse as a `DecodedTorrent` and therefore as a `TorrentFile`, unless the
24-
`unknown_tracker_scheme` variant is enabled, in which case it will produce a
25-
valid `TorrentFile` where the `TrackerScheme` is of the `Unknown` variant
22+
- A torrent file with an invalid tracker URI (eg. non-urlencoded or unknown
23+
scheme) will now fail to parse as a `DecodedTorrent` and therefore as a
24+
`TorrentFile`; if the `unknown_tracker_scheme` variant is enabled, the
25+
unknown scheme will not produce an error but a `TrackerScheme::Unknown`
2626

2727

2828
### Added

src/magnet.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ impl std::error::Error for MagnetLinkError {
116116

117117
/// A Magnet URI, which contains the infohash(es) but not the entire meta info.
118118
///
119-
/// The MagnetLink can provide information about the torrent
120-
/// [`name`](crate::magnet::MagnetLink::name) and [`hash`](crate::magnet::MagnetLink::hash).
121-
///
122119
/// More information is specified in [BEP-0009](https://bittorrent.org/beps/bep_0009.html), and
123120
/// even more appears in the wild, as explained [on Wikipedia](https://en.wikipedia.org/wiki/Magnet_URI_scheme).
124121
#[derive(Clone, Debug)]
@@ -133,6 +130,9 @@ pub struct MagnetLink {
133130
/// `magnet_force_name` crate feature is enabled.
134131
name: String,
135132
/// Trackers contained in the magnet link
133+
///
134+
/// The trackers are url-encoded in the magnet link, but are presented here
135+
/// in their decoded form which can is human-readable.
136136
trackers: Vec<Tracker>,
137137
}
138138

@@ -266,7 +266,7 @@ impl MagnetLink {
266266

267267
/// Parse the query in a list of key->value entries with a percent-decoder attached.
268268
///
269-
/// The results can be accessed raw with [EStr::as_str()] and percent-decoded with [EStr::decode].
269+
/// The results can be accessed raw with [EStr::as_str] and percent-decoded with [EStr::decode].
270270
///
271271
/// This method only fails if the magnet query is empty (`magnet:`), but may produce unexpected
272272
/// results because it does not apply magnet-specific sanitation.

src/torrent_file.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ impl std::error::Error for TorrentFileError {
7979
/// [`name`](crate::torrent_file::TorrentFile::name) and
8080
/// [`hash`](crate::torrent_file::TorrentFile::hash). Other fields could be supported, but are not
8181
/// currently implemented by this library.
82+
///
83+
/// To save the torrent file to disk, use the `TorrentFile::to_vec` method:
84+
///
85+
/// ```ignore
86+
/// std::fs::write("export.torrent", &torrent.to_vec()).unwrap();
87+
/// ```
8288
#[derive(Clone, Debug, Serialize, Deserialize)]
8389
pub struct TorrentFile {
8490
pub hash: InfoHash,

src/tracker.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,34 @@ pub enum PeerSource {
1212
Tracker(Tracker),
1313
}
1414

15-
/// A centralized variant of a [`Peersource`](crate::tracker::PeerSource).
15+
/// A Bittorrent rendezvous server for peers to find one another.
16+
///
17+
/// This is usually parsed directly from a [`TorrentFile`](crate::torrent_file::TorrentFile)
18+
/// or a [`MagnetLink`](crate::magnet::MagnetLink).
1619
#[derive(Clone, Debug, PartialEq)]
1720
pub struct Tracker {
21+
/// Tracker URL scheme (usually `ws`, `http(s)`, or `udp`)
1822
scheme: TrackerScheme,
23+
/// Complete tracker URL
1924
url: Uri<String>,
2025
}
2126

2227
impl Tracker {
2328
/// Generate a new Tracker from a given string URL.
29+
///
30+
/// Will fail if scheme is not "http", "https", "wss" or "udp", unless
31+
/// the `unknown_tracker_scheme` crate feature is enabled.
32+
///
33+
/// Will also fail if the provided URL is url-encoded.
2434
pub fn new(url: &str) -> Result<Tracker, TrackerError> {
2535
let url = Uri::parse(url.to_string())?;
2636
Tracker::from_url(&url)
2737
}
2838

2939
/// Generate a new Tracker from a parsed URL.
3040
///
31-
/// Will fail if scheme is not "http", "https", "wss" or "udp".
41+
/// Will fail if scheme is not "http", "https", "wss" or "udp", unless
42+
/// the `unknown_tracker_scheme` crate feature is enabled.
3243
pub fn from_url(url: &Uri<String>) -> Result<Tracker, TrackerError> {
3344
Ok(Tracker {
3445
scheme: TrackerScheme::from_str(url.scheme().as_str())?,
@@ -120,7 +131,14 @@ impl FromStr for TrackerScheme {
120131
/// Error occurred during parsing a [`Tracker`](crate::tracker::Tracker).
121132
#[derive(Clone, Debug, PartialEq)]
122133
pub enum TrackerError {
134+
/// Tracker URL could not be parsed because it is malformed.
135+
///
136+
/// I'm not sure under what circumstances this could happen.
123137
InvalidURL { source: UriParseError },
138+
/// Tracker scheme is not a known variant.
139+
///
140+
/// This error does not exist when the `unknown_tracker_scheme` crate
141+
/// feature is enabled.
124142
InvalidScheme { scheme: String },
125143
}
126144

0 commit comments

Comments
 (0)