Skip to main content

AtParser

Struct AtParser 

Source
pub struct AtParser<'a, T, const SIZE: usize>
where T: AtContext<SIZE> + ?Sized,
{ pub commands: &'a mut [(&'static str, &'a mut T)], }
Expand description

The main AT command parser

Generic over T which must implement the AtContext<SIZE> trait, and over the const SIZE which determines the response buffer size.

§Generic Design

The parser is generic over the command handler type T and response size SIZE to allow compile-time type checking when all handlers are of the same type. This provides:

  • Type safety: Compile-time verification of handler types
  • Zero overhead: No dynamic dispatch when using concrete types
  • Flexibility: Can be used with trait objects (dyn AtContext<SIZE>) for mixed handler types

§Usage Patterns

const SIZE: usize = 64;
let mut parser: AtParser<dyn AtContext<SIZE>, SIZE> = AtParser::new();
let commands: &mut [(&str, &mut dyn AtContext<SIZE>)] = &mut [
    ("AT+ECHO", &mut echo_handler),
    ("AT+RST", &mut reset_handler),
];
parser.set_commands(commands);

§With concrete types (for homogeneous handlers):

const SIZE: usize = 64;
let mut parser: AtParser<MyHandler, SIZE> = AtParser::new();
let commands: &mut [(&str, &mut MyHandler)] = &mut [
    ("AT+CMD1", &mut handler1),
    ("AT+CMD2", &mut handler2),
];
parser.set_commands(commands);

Fields§

§commands: &'a mut [(&'static str, &'a mut T)]

Array of registered commands with their name and handler

Implementations§

Source§

impl<'a, T, const SIZE: usize> AtParser<'a, T, SIZE>
where T: AtContext<SIZE> + ?Sized,

Source

pub const fn new() -> Self

Create a new empty parser

Source

pub fn set_commands(&mut self, commands: &'a mut [(&'static str, &'a mut T)])

Register commands that this parser will handle

Source

pub fn execute(&mut self, input: &str) -> AtResult<SIZE>

Parse and execute an AT command string

§Arguments
  • input - The raw AT command string (e.g., “AT+CMD?”)
§Returns
  • Ok(Bytes<SIZE>) - Success response from the command handler
  • Err(AtError) - Error if parsing fails or command is not found

Auto Trait Implementations§

§

impl<'a, T, const SIZE: usize> Freeze for AtParser<'a, T, SIZE>
where T: ?Sized,

§

impl<'a, T, const SIZE: usize> RefUnwindSafe for AtParser<'a, T, SIZE>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T, const SIZE: usize> Send for AtParser<'a, T, SIZE>
where T: Send + ?Sized,

§

impl<'a, T, const SIZE: usize> Sync for AtParser<'a, T, SIZE>
where T: Sync + ?Sized,

§

impl<'a, T, const SIZE: usize> Unpin for AtParser<'a, T, SIZE>
where T: ?Sized,

§

impl<'a, T, const SIZE: usize> UnsafeUnpin for AtParser<'a, T, SIZE>
where T: ?Sized,

§

impl<'a, T, const SIZE: usize> !UnwindSafe for AtParser<'a, T, SIZE>

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.