pub enum Bencode {
Value(Vec<u8>),
List(Vec<Bencode>),
Dict(HashMap<Vec<u8>, Bencode>),
}Expand description
A nested enum containing the parsed Bencode file structure.
Variants§
Value(Vec<u8>)
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 byiand terminated bye. - A ByteString. eg:
3:cat. stars with an integer length, followed by:as a separator, then the bytes.
List(Vec<Bencode>)
A list of Bencode structs which can be destructured into a Vec with as_vec().
Dict(HashMap<Vec<u8>, Bencode>)
A map of bencoded values. All keys are Vecas_map().
Implementations§
Source§impl Bencode
impl Bencode
Sourcepub fn as_usize(&self) -> Result<usize, BencodeParserError>
pub fn as_usize(&self) -> Result<usize, BencodeParserError>
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.
Sourcepub fn as_string(&self) -> Result<String, BencodeParserError>
pub fn as_string(&self) -> Result<String, BencodeParserError>
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.
Sourcepub fn as_bytes(&self) -> Result<&Vec<u8>, BencodeParserError>
pub fn as_bytes(&self) -> Result<&Vec<u8>, BencodeParserError>
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}.
Auto Trait Implementations§
impl Freeze for Bencode
impl RefUnwindSafe for Bencode
impl Send for Bencode
impl Sync for Bencode
impl Unpin for Bencode
impl UnwindSafe for Bencode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more