Struct bencode_decoder::BString [] [src]

pub struct BString {
    // some fields omitted
}

Struct for representing string (byte sequence) in Bencode format.

Methods

impl BString
[src]

fn new(data: &[u8]) -> BString

Simple constructor from array of bytes.

Trait Implementations

impl Debug for BString
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl PartialEq for BString
[src]

fn eq(&self, __arg_0: &BString) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &BString) -> bool

This method tests for !=.

impl Eq for BString
[src]

impl BElement<BString> for BString
[src]

fn decode(encoded: &[u8]) -> Result<(usize, BString), &'static str>

Decodes BString from array of bytes.

Returns Ok((position of last used byte in passed array, parsed BString)) or Err if couldn't parse BString correctly.

Examples

BString must have following structure: :, where data - sequence of bytes with corresponding length.

use bencode_decoder::BElement;
use bencode_decoder::BString;

assert_eq!((4, BString::new("abc".as_bytes())), 
           BString::decode("3:abc".as_bytes()).ok().expect("invalid"));