[][src]Trait bstr_parse::BStrParse

pub trait BStrParse {
    pub fn parse<F: FromBStr>(&self) -> Result<F, F::Err>;
}

An extension trait for parse.

Required methods

pub fn parse<F: FromBStr>(&self) -> Result<F, F::Err>[src]

Parses this string slice into another type.

Because parse is so general, it can cause problems with type inference. As such, parse is one of the few times you'll see the syntax affectionately known as the 'turbofish': ::<>. This helps the inference algorithm understand specifically which type you're trying to parse into.

parse can parse any type that implements the FromBStr trait.

Errors

Will return Err if it's not possible to parse this string slice into the desired type.

Examples

Basic usage

use bstr_parse::*;
let four: u32 = b"4".parse().unwrap();

assert_eq!(4, four);

Using the 'turbofish' instead of annotating four:

use bstr_parse::*;
let four = b"4".parse::<u32>();

assert_eq!(Ok(4), four);

Failing to parse:

use bstr_parse::*;
let nope = b"j".parse::<u32>();

assert!(nope.is_err());
Loading content...

Implementations on Foreign Types

impl BStrParse for [u8][src]

pub fn parse<F: FromBStr>(&self) -> Result<F, F::Err>[src]

Parses this string slice into another type.

Because parse is so general, it can cause problems with type inference. As such, parse is one of the few times you'll see the syntax affectionately known as the 'turbofish': ::<>. This helps the inference algorithm understand specifically which type you're trying to parse into.

parse can parse any type that implements the FromBStr trait.

Errors

Will return Err if it's not possible to parse this string slice into the desired type.

Examples

Basic usage

use bstr_parse::*;
let four: u32 = b"4".parse().unwrap();

assert_eq!(4, four);

Using the 'turbofish' instead of annotating four:

use bstr_parse::*;
let four = b"4".parse::<u32>();

assert_eq!(Ok(4), four);

Failing to parse:

use bstr_parse::*;
let nope = b"j".parse::<u32>();

assert!(nope.is_err());
Loading content...

Implementors

Loading content...