Struct lava_torrent::torrent::v1::TorrentBuilder [−][src]
pub struct TorrentBuilder { /* fields omitted */ }
Builder for creating Torrent
s from files.
This struct is used for creating Torrent
s, 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: announce
, 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.
Methods
impl TorrentBuilder
[src]
impl TorrentBuilder
pub fn new<P>(
announce: String,
path: P,
piece_length: Integer
) -> TorrentBuilder where
P: AsRef<Path>,
[src]
pub fn new<P>(
announce: String,
path: P,
piece_length: Integer
) -> TorrentBuilder where
P: AsRef<Path>,
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 than0
AND is a power of2
. -
Using a
path
containing hidden components will makebuild()
returnErr
. This is *nix-specific. Hidden components are those that start with.
. -
Paths with components exactly matching
..
are invalid.
pub fn build(self) -> Result<Torrent>
[src]
pub fn build(self) -> Result<Torrent>
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.
pub fn set_announce(self, announce: String) -> TorrentBuilder
[src]
pub fn set_announce(self, announce: String) -> TorrentBuilder
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.
pub fn set_announce_list(self, announce_list: AnnounceList) -> TorrentBuilder
[src]
pub fn set_announce_list(self, announce_list: AnnounceList) -> TorrentBuilder
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.
pub fn set_name(self, name: String) -> TorrentBuilder
[src]
pub fn set_name(self, name: String) -> TorrentBuilder
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.
pub fn set_path<P>(self, path: P) -> TorrentBuilder where
P: AsRef<Path>,
[src]
pub fn set_path<P>(self, path: P) -> TorrentBuilder where
P: AsRef<Path>,
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. -
Using a
path
containing hidden components will makebuild()
returnErr
. This is *nix-specific. Hidden components are those that start with.
. -
Paths with components exactly matching
..
are invalid.
pub fn set_piece_length(self, piece_length: Integer) -> TorrentBuilder
[src]
pub fn set_piece_length(self, piece_length: Integer) -> TorrentBuilder
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
.
pub fn add_extra_field(self, key: String, val: BencodeElem) -> TorrentBuilder
[src]
pub fn add_extra_field(self, key: String, val: BencodeElem) -> TorrentBuilder
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.
pub fn add_extra_info_field(
self,
key: String,
val: BencodeElem
) -> TorrentBuilder
[src]
pub fn add_extra_info_field(
self,
key: String,
val: BencodeElem
) -> TorrentBuilder
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.
pub fn set_privacy(self, is_private: bool) -> TorrentBuilder
[src]
pub fn set_privacy(self, is_private: bool) -> TorrentBuilder
Make the Torrent
private or public, as defined in BEP 27.
Calling this method multiple times will simply override previous settings.
Trait Implementations
impl Clone for TorrentBuilder
[src]
impl Clone for TorrentBuilder
fn clone(&self) -> TorrentBuilder
[src]
fn clone(&self) -> TorrentBuilder
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for TorrentBuilder
[src]
impl Debug for TorrentBuilder
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Default for TorrentBuilder
[src]
impl Default for TorrentBuilder
fn default() -> TorrentBuilder
[src]
fn default() -> TorrentBuilder
Returns the "default value" for a type. Read more
impl Eq for TorrentBuilder
[src]
impl Eq for TorrentBuilder
impl PartialEq for TorrentBuilder
[src]
impl PartialEq for TorrentBuilder
fn eq(&self, other: &TorrentBuilder) -> bool
[src]
fn eq(&self, other: &TorrentBuilder) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &TorrentBuilder) -> bool
[src]
fn ne(&self, other: &TorrentBuilder) -> bool
This method tests for !=
.
Auto Trait Implementations
impl Send for TorrentBuilder
impl Send for TorrentBuilder
impl Sync for TorrentBuilder
impl Sync for TorrentBuilder