Skip to main content

Dict

Struct Dict 

Source
pub struct Dict<'a, 'p> { /* private fields */ }
Expand description

A bencode dictionary

Implementations§

Source§

impl<'a, 'p> Dict<'a, 'p>

Source

pub fn iter(&self) -> DictIter<'a, 'p> ⓘ

Gets an iterator over the entries of the dictionary.

Source

pub fn as_raw_bytes(&self) -> &'a [u8] ⓘ

Returns raw bytes of this dictionary.

§Examples

Basic usage:

use ben::{Parser, Decoder};

let bytes = b"d1:a1:be";
let parser = &mut Parser::new();
let dict = parser.parse::<Decoder>(bytes).unwrap().into_dict().unwrap();
assert_eq!(b"d1:a1:be", dict.as_raw_bytes());
Source

pub fn get(&self, key: &str) -> Option<Decoder<'a, 'p>>

Returns the Decoder for the given key.

Source

pub fn get_dict(&self, key: &str) -> Option<Dict<'a, 'p>>

Returns the Dict for the given key.

Source

pub fn get_list(&self, key: &str) -> Option<List<'a, 'p>>

Returns the List for the given key.

Source

pub fn get_bytes(&self, key: &str) -> Option<&'a [u8]>

Returns the byte slice for the given key.

Source

pub fn get_str(&self, key: &str) -> Option<&'a str>

Returns the string slice for the given key.

Source

pub fn get_ascii_str(&self, key: &str) -> Option<&'a str>

Returns the printable ASCII string slice for the given key.

Source

pub fn get_int(&self, key: &str) -> Option<i64>

Returns the i64 for the given key.

Source

pub fn len(&self) -> usize

Returns the number of entries

Source

pub fn is_empty(&self) -> bool

Returns true if the dictionary is empty

Trait Implementations§

Source§

impl Debug for Dict<'_, '_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, 'p> Decode<'a, 'p> for Dict<'a, 'p>

Source§

fn decode(decoder: Decoder<'a, 'p>) -> Result<Self>

Source§

impl<'a, 'p> IntoIterator for Dict<'a, 'p>

Source§

type Item = (Decoder<'a, 'p>, Decoder<'a, 'p>)

The type of the elements being iterated over.
Source§

type IntoIter = DictIter<'a, 'p>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a, 'p> Freeze for Dict<'a, 'p>

§

impl<'a, 'p> RefUnwindSafe for Dict<'a, 'p>

§

impl<'a, 'p> Send for Dict<'a, 'p>

§

impl<'a, 'p> Sync for Dict<'a, 'p>

§

impl<'a, 'p> Unpin for Dict<'a, 'p>

§

impl<'a, 'p> UnsafeUnpin for Dict<'a, 'p>

§

impl<'a, 'p> UnwindSafe for Dict<'a, 'p>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.