Struct lava_torrent::torrent::v1::TorrentBuilder
source · [−]pub struct TorrentBuilder { /* private fields */ }
Expand description
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: 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
sourceimpl TorrentBuilder
impl TorrentBuilder
sourcepub fn new<P>(path: P, piece_length: Integer) -> TorrentBuilder where
P: AsRef<Path>,
pub fn new<P>(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
. -
Paths with components exactly matching
..
are invalid.
sourcepub fn build(self) -> Result<Torrent, LavaTorrentError>
pub fn build(self) -> Result<Torrent, LavaTorrentError>
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.
sourcepub fn set_announce(self, announce: Option<String>) -> TorrentBuilder
pub fn set_announce(self, announce: Option<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.
sourcepub fn set_announce_list(self, announce_list: AnnounceList) -> TorrentBuilder
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.
sourcepub fn set_name(self, name: String) -> TorrentBuilder
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.
sourcepub fn set_path<P>(self, path: P) -> TorrentBuilder where
P: AsRef<Path>,
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. -
Paths with components exactly matching
..
are invalid.
sourcepub fn set_piece_length(self, piece_length: Integer) -> TorrentBuilder
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
.
sourcepub fn add_extra_field(self, key: String, val: BencodeElem) -> TorrentBuilder
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.
sourcepub fn add_extra_info_field(
self,
key: String,
val: BencodeElem
) -> TorrentBuilder
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.
sourcepub fn set_privacy(self, is_private: bool) -> TorrentBuilder
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
sourceimpl Clone for TorrentBuilder
impl Clone for TorrentBuilder
sourcefn clone(&self) -> TorrentBuilder
fn clone(&self) -> TorrentBuilder
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for TorrentBuilder
impl Debug for TorrentBuilder
sourceimpl Default for TorrentBuilder
impl Default for TorrentBuilder
sourcefn default() -> TorrentBuilder
fn default() -> TorrentBuilder
Returns the “default value” for a type. Read more
sourceimpl PartialEq<TorrentBuilder> for TorrentBuilder
impl PartialEq<TorrentBuilder> for TorrentBuilder
sourcefn eq(&self, other: &TorrentBuilder) -> bool
fn eq(&self, other: &TorrentBuilder) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &TorrentBuilder) -> bool
fn ne(&self, other: &TorrentBuilder) -> bool
This method tests for !=
.
impl Eq for TorrentBuilder
impl StructuralEq for TorrentBuilder
impl StructuralPartialEq for TorrentBuilder
Auto Trait Implementations
impl RefUnwindSafe for TorrentBuilder
impl Send for TorrentBuilder
impl Sync for TorrentBuilder
impl Unpin for TorrentBuilder
impl UnwindSafe for TorrentBuilder
Blanket Implementations
sourceimpl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
sourcefn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Convert the given value into an approximately equivalent representation.
sourceimpl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
sourcefn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
sourcefn approx(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
fn approx(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
Approximate the subject with the default scheme.
sourcefn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Approximate the subject with a specific scheme.
sourceimpl<T> ConvUtil for T
impl<T> ConvUtil for T
sourcefn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
Approximate the subject to a given type with the default scheme.
sourcefn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Approximate the subject to a given type with a specific scheme.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more