[−][src]Enum sveppa_bencode::Bencode
A nested enum containing the parsed Bencode file structure.
Variants
A value. (or a 'leaf' in tree terminology) which can be converted into a value with any
of: as_string()
, as_bytes()
, or as_usize()
.
Possible options:
- An Integer. eg:
i123e
. indicated byi
and terminated bye
. - A ByteString. eg:
3:cat
. stars with an integer length, followed by:
as a separator, then the bytes.
A list of Bencode structs which can be destructured into a Vec with as_vec()
.
A map of bencoded values. All keys are Vecas_map()
.
Implementations
impl Bencode
[src]
pub fn as_usize(&self) -> Result<usize, BencodeParserError>
[src]
Attempt to parse a Bencode::Value
variant into a usize
.
Can return:
InvalidVariantMethod
, if called on any ofBencode::{List, Dict}
.InvalidUTF8String
, if the bytes cannot be parsed as a UTF8, ASCII string.InvalidASCIIInteger
, if the ASCII bytes aren't a valid base 10 number.
pub fn as_string(&self) -> Result<String, BencodeParserError>
[src]
Attempt to parse a Bencode::Value
variant into a String
.
Can return:
InvalidVariantMethod
, if called on any ofBencode::{List, Dict}
.InvalidUTF8String
, if the bytes cannot be parsed as a UTF8, ASCII string.
pub fn as_bytes(&self) -> Result<&Vec<u8>, BencodeParserError>
[src]
Destructures a Bencode::Value
into a Vec<u8>
. This method will always succeed if applied
to a Bencode::Value
.
Can return:
InvalidVariantMethod
, if called on any ofBencode::{List, Dict}
.
pub fn as_vec(&self) -> Result<&Vec<Bencode>, BencodeParserError>
[src]
Attempt to parse a Bencode::List
into a Vec<Bencode>
. This method will always succeed
if applied to a Bencode::List
.
Can return:
InvalidVariantMethod
, if called on any ofBencode::{Value, Dict}
.
pub fn as_map(&self) -> Result<&HashMap<Vec<u8>, Bencode>, BencodeParserError>
[src]
Attempt to parse a Bencode::Dict
into a HashMap<Vec<u8>, Bencode>
. This method will
always succeed if applied to a Bencode::Dict
.
Can return:
InvalidVariantMethod
, if called on any ofBencode::{Value, List}
.
Auto Trait Implementations
impl RefUnwindSafe for Bencode
[src]
impl Send for Bencode
[src]
impl Sync for Bencode
[src]
impl Unpin for Bencode
[src]
impl UnwindSafe for Bencode
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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.
pub 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>,