[−][src]Enum lava_torrent::bencode::BencodeElem
Represent a single bencode element.
There are 4 variants in the spec, but this enum has 5 variants. The extra variant is
Bytes
(a sequence of bytes that does not represent a valid utf8
string, e.g. a SHA1 block hash), which is considered to be the
same as String
in the spec. But they are best treated differently
in actual implementations to make things easier.
Note that the Integer
variant here uses i64
explicitly instead of using a type alias like
Integer
. The reasoning behind this is that if you have to handle
bencode directly then what you are doing is relatively low-level. In this case, exposing the
underlying type might actually be better.
Variants
String(String)
Integer(i64)
List(Vec<BencodeElem>)
Dictionary(HashMap<String, BencodeElem>)
Methods
impl BencodeElem
[src]
pub fn from_bytes<B>(bytes: B) -> Result<Vec<BencodeElem>> where
B: AsRef<[u8]>,
[src]
B: AsRef<[u8]>,
Parse bytes
and return all BencodeElem
found.
If bytes
is empty, then Ok(vec)
will be returned, but
vec
would be empty as well.
If bytes
contains any malformed bencode, or if any other
error is encountered (e.g. IOError
), then Err(error)
will be returned.
pub fn from_file<P>(path: P) -> Result<Vec<BencodeElem>> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Parse the content of the file at path
and return all BencodeElem
found.
If the file at path
is empty, then Ok(vec)
will be returned, but
vec
would be empty as well.
If the file at path
contains any malformed bencode, or if any other
error is encountered (e.g. IOError
), then Err(error)
will be returned.
impl BencodeElem
[src]
pub fn write_into<W>(&self, dst: &mut W) -> Result<()> where
W: Write,
[src]
W: Write,
Encode self
and write the result to dst
.
pub fn write_into_file<P>(&self, path: P) -> Result<()> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Encode self
and write the result to path
.
path
must be the path to a file.
"This function will create a file if it does not exist, and will truncate it if it does."
Note: it is the client's responsibility to ensure
that all directories in path
actually exist (e.g.
by calling create_dir_all
).
pub fn encode(&self) -> Vec<u8>
[src]
Encode self
and return the result in a Vec
.
Trait Implementations
impl Eq for BencodeElem
[src]
impl Clone for BencodeElem
[src]
fn clone(&self) -> BencodeElem
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl PartialEq<BencodeElem> for BencodeElem
[src]
fn eq(&self, other: &BencodeElem) -> bool
[src]
fn ne(&self, other: &BencodeElem) -> bool
[src]
impl From<u8> for BencodeElem
[src]
fn from(val: u8) -> BencodeElem
[src]
impl From<u16> for BencodeElem
[src]
fn from(val: u16) -> BencodeElem
[src]
impl From<u32> for BencodeElem
[src]
fn from(val: u32) -> BencodeElem
[src]
impl From<i8> for BencodeElem
[src]
fn from(val: i8) -> BencodeElem
[src]
impl From<i16> for BencodeElem
[src]
fn from(val: i16) -> BencodeElem
[src]
impl From<i32> for BencodeElem
[src]
fn from(val: i32) -> BencodeElem
[src]
impl From<i64> for BencodeElem
[src]
fn from(val: i64) -> BencodeElem
[src]
impl<'a> From<&'a str> for BencodeElem
[src]
fn from(val: &'a str) -> BencodeElem
[src]
impl From<String> for BencodeElem
[src]
fn from(val: String) -> BencodeElem
[src]
impl<'a> From<&'a [u8]> for BencodeElem
[src]
impl From<Vec<u8>> for BencodeElem
[src]
fn from(val: Vec<u8>) -> BencodeElem
[src]
impl Debug for BencodeElem
[src]
impl Display for BencodeElem
[src]
Auto Trait Implementations
impl Send for BencodeElem
impl Unpin for BencodeElem
impl Sync for BencodeElem
impl UnwindSafe for BencodeElem
impl RefUnwindSafe for BencodeElem
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, Dst> ConvAsUtil<Dst> for T
[src]
fn approx(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
[src]
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
[src]
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
[src]
Scheme: ApproxScheme,
type Err = NoError
The error type produced by a failed conversion.
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
[src]
impl<T> ConvUtil for T
[src]
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
[src]
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
[src]
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
fn into_as<Dst>(self) -> Dst where
Self: Into<Dst>,
[src]
Self: Into<Dst>,
fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: TryInto<Dst>,
[src]
Self: TryInto<Dst>,
fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ValueInto<Dst>,
[src]
Self: ValueInto<Dst>,
impl<Src> ValueFrom<Src> for Src
[src]
type Err = NoError
The error type produced by a failed conversion.
fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
[src]
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
[src]
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
[src]
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
[src]
Dst: ValueFrom<Src>,
type Err = <Dst as ValueFrom<Src>>::Err
The error type produced by a failed conversion.
fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>
[src]
impl<Src> TryFrom<Src> for Src
[src]
type Err = NoError
The error type produced by a failed conversion.
fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>
[src]
impl<Src, Dst> TryInto<Dst> for Src where
Dst: TryFrom<Src>,
[src]
Dst: TryFrom<Src>,