pub trait BStrParse {
// Required method
fn parse<F: FromBStr>(&self) -> Result<F, F::Err>;
}Expand description
An extension trait for parse.
Required Methods§
Sourcefn parse<F: FromBStr>(&self) -> Result<F, F::Err>
fn parse<F: FromBStr>(&self) -> Result<F, F::Err>
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());Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl BStrParse for [u8]
impl BStrParse for [u8]
Source§fn parse<F: FromBStr>(&self) -> Result<F, F::Err>
fn parse<F: FromBStr>(&self) -> Result<F, F::Err>
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());