pub struct TorrentBuilder { /* private fields */ }
Expand description

Builder for creating Torrents from files.

This struct is used for creating Torrents, so that you can encode/serialize them to .torrent files. If you want to read existing .torrent files then use Torrent::read_from_file() or Torrent::read_from_bytes().

Required fields: path and piece_length. They are set when calling the constructor new().

Optional fields can be set by calling the corresponding methods (e.g. set_announce()). Fields can be updated in the same way.

Notes

*nix hidden files/dirs are ignored.

Reasoning: when handling these special “files”, there are many decisions to make:

  • Should they be ignored, included, or selectively ignored/included?
  • Should included/ignored entries be marked specially (e.g. BEP 47)?
  • Should users be allowed to configure the settings?
  • If users can configure the settings, what would be the ideal defaults?

Apparently it’s not easy to make these decisions. Therefore these files are ignored for now. Clients like Deluge and qBittorrent also ignore hidden entries.

Implementations

Create a new TorrentBuilder with required fields set.

The caller has to ensure that the inputs are valid, as this method does not validate its inputs. If they turn out to be invalid, calling build() later will fail.

Notes
  • path must be absolute.

  • A valid piece_length is larger than 0 AND is a power of 2.

  • Paths with components exactly matching .. are invalid.

Build a Torrent from this TorrentBuilder.

If name is not set, then the last component of path will be used as the Torrent’s name field.

build() does not provide comprehensive validation of any input. Basic cases such as setting announce to an empty string will be detected and Err will be returned. But more complicated cases such as using an invalid url as announce won’t be detected. Again, the caller has to ensure that the values given to a TorrentBuilder are valid.

Set the announce field of the Torrent to be built.

Calling this method multiple times will simply override previous settings.

The caller has to ensure that announce is valid, as this method does not validate its value. If announce turns out to be invalid, calling build() later will fail.

Set the announce_list field of the Torrent to be built.

Calling this method multiple times will simply override previous settings.

The caller has to ensure that announce_list is valid, as this method does not validate its value. If announce_list turns out to be invalid, calling build() later will fail.

Set the name field of the Torrent to be built.

Calling this method multiple times will simply override previous settings.

The caller has to ensure that name is valid, as this method does not validate its value. If name turns out to be invalid, calling build() later will fail.

Set the path to the file(s) from which the Torrent will be built.

Calling this method multiple times will simply override previous settings.

The caller has to ensure that path is valid, as this method does not validate its value. If path turns out to be invalid, calling build() later will fail.

Notes
  • path must be absolute.

  • Paths with components exactly matching .. are invalid.

Set the piece_length field of the Torrent to be built.

Calling this method multiple times will simply override previous settings.

The caller has to ensure that piece_length is valid, as this method does not validate its value. If piece_length turns out to be invalid, calling build() later will fail.

NOTE: A valid piece_length is larger than 0 AND is a power of 2.

Add an extra field to Torrent (i.e. to the root dictionary).

Calling this method multiple times with the same key will simply override previous settings.

The caller has to ensure that key and val are valid, as this method does not validate their values. If they turn out to be invalid, calling build() later will fail.

Add an extra info field to Torrent (i.e. to the info dictionary).

Calling this method multiple times with the same key will simply override previous settings.

The caller has to ensure that key and val are valid, as this method does not validate their values. If they turn out to be invalid, calling build() later will fail.

Make the Torrent private or public, as defined in BEP 27.

Calling this method multiple times will simply override previous settings.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The error type produced by a failed conversion.

Convert the given value into an approximately equivalent representation.

The error type produced by a failed conversion.

Convert the subject into an approximately equivalent representation.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Approximate the subject with the default scheme.

Approximate the subject with a specific scheme.

Approximate the subject to a given type with the default scheme.

Approximate the subject to a given type with a specific scheme.

Convert the subject to a given type.

Attempt to convert the subject to a given type.

Attempt a value conversion of the subject to a given type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The error type produced by a failed conversion.

Convert the given value into the subject type.

The type returned in the event of a conversion error.

Performs the conversion.

The error type produced by a failed conversion.

Convert the subject into the destination type.

The type returned in the event of a conversion error.

Performs the conversion.

The error type produced by a failed conversion.

Convert the given value into an exactly equivalent representation.

The error type produced by a failed conversion.

Convert the subject into an exactly equivalent representation.