Struct CommandParser

Source
pub struct CommandParser<'a, D> { /* private fields */ }
Expand description
use at_commands::parser::CommandParser;
let (x, y, z) = CommandParser::parse(b"+SYSGPIOREAD:654,\"true\",-65154\r\nOK\r\n")
   .expect_identifier(b"+SYSGPIOREAD:")
   .expect_int_parameter()
   .expect_string_parameter()
   .expect_int_parameter()
   .expect_identifier(b"\r\nOK\r\n")
   .finish()
   .unwrap();

assert_eq!(x, 654);
assert_eq!(y, "true");
assert_eq!(z, -65154);

let (w,) = CommandParser::parse(b"+STATUS: READY\r\nOK\r\n")
   .expect_identifier(b"+STATUS: ")
   .expect_raw_string()
   .expect_identifier(b"\r\nOK\r\n")
   .finish()
   .unwrap();

assert_eq!(w, "READY");

Implementations§

Source§

impl<'a> CommandParser<'a, ()>

Source

pub fn parse(buffer: &'a [u8]) -> CommandParser<'a, ()>

Start parsing the command

Source§

impl<'a, D> CommandParser<'a, D>

Source

pub fn expect_identifier(self, identifier: &[u8]) -> Self

Tries reading an identifier

Source

pub fn expect_optional_identifier(self, identifier: &[u8]) -> Self

Tries reading an optional identifier.

Source

pub fn finish(self) -> Result<D, ParseError>

Finish parsing the command and get the results

Source§

impl<'a, D: TupleConcat<i32>> CommandParser<'a, D>

Source

pub fn expect_int_parameter(self) -> CommandParser<'a, D::Out>

Tries reading an int parameter

Source§

impl<'a, D: TupleConcat<&'a str>> CommandParser<'a, D>

Source

pub fn expect_string_parameter(self) -> CommandParser<'a, D::Out>

Tries reading a string parameter

Source

pub fn expect_raw_string(self) -> CommandParser<'a, D::Out>

Tries reading a non-parameter, non-quoted string

Source§

impl<'a, D: TupleConcat<Option<i32>>> CommandParser<'a, D>

Source

pub fn expect_optional_int_parameter(self) -> CommandParser<'a, D::Out>

Tries reading an int parameter

Source§

impl<'a, D: TupleConcat<Option<&'a str>>> CommandParser<'a, D>

Source

pub fn expect_optional_string_parameter(self) -> CommandParser<'a, D::Out>

Tries reading a string parameter

Source

pub fn expect_optional_raw_string(self) -> CommandParser<'a, D::Out>

Tries reading a non-parameter, non-quoted string

Auto Trait Implementations§

§

impl<'a, D> Freeze for CommandParser<'a, D>
where D: Freeze,

§

impl<'a, D> RefUnwindSafe for CommandParser<'a, D>
where D: RefUnwindSafe,

§

impl<'a, D> Send for CommandParser<'a, D>
where D: Send,

§

impl<'a, D> Sync for CommandParser<'a, D>
where D: Sync,

§

impl<'a, D> Unpin for CommandParser<'a, D>
where D: Unpin,

§

impl<'a, D> UnwindSafe for CommandParser<'a, D>
where D: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.