Trait whiteread::White
[−]
[src]
pub trait White: Sized { fn read<I: StrStream>(it: &mut I) -> WhiteResult<Self>; }
Trait for values that can be parsed from stream of whitespace-separated words.
Implementations for primtives consume and parse one element from a stream (advancing a stream). Implementations for tuples just parse elements from left to right. Implementation for vector parses till the end of stream.
Examples
Using a trait directly
use whiteread::White; let mut stream = "123".split_whitespace(); assert_eq!(<i32 as White>::read(&mut stream).unwrap(), 123)
Semantics of provided trait implementations:
// tuples (up to 3) assert_eq!(parse_string("2 1 3 4").ok(), Some( ((2, 1), (3, 4)) )); // eager vector assert_eq!(parse_string("2 1 3 4").ok(), Some( vec![2, 1, 3, 4] )); // vec prefixed with length assert_eq!(parse_string("2 1 3").ok(), Some( Lengthed(vec![1, 3]) )); // you can mix impls of course assert_eq!(parse_string("a 1 b 2").ok(), Some( vec![('a', 1), ('b', 2)] ));
Required Methods
fn read<I: StrStream>(it: &mut I) -> WhiteResult<Self>
Implementors
impl White for bool
impl White for u8
impl White for u16
impl White for u32
impl White for u64
impl White for usize
impl White for i8
impl White for i16
impl White for i32
impl White for i64
impl White for isize
impl White for String
impl White for f32
impl White for f64
impl White for char
impl<T: White, U: White> White for (T, U)
impl<T: White, U: White, V: White> White for (T, U, V)
impl White for ()
impl<T: White> White for Vec<T>
impl<T: White> White for Lengthed<T>