Skip to main content

at_parser_rs/
context.rs

1/***************************************************************************
2 *
3 * AT Command Parser
4 * Copyright (C) 2026 Antonio Salsi <passy.linux@zresa.it>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
18 *
19 ***************************************************************************/
20 
21use crate::{Args, AtError, AtResult};
22
23/// Trait that defines the context for AT command execution.
24/// Implementations of this trait handle the actual logic for each AT command form.
25///
26/// The const generic `SIZE` defines the size (in bytes) of the response buffer
27/// returned by command handlers.
28pub trait AtContext<const SIZE: usize> {
29
30    /// Execute command (AT+CMD)
31    /// This is called when a command is invoked without any suffix.
32    fn exec(&mut self) -> AtResult<'_, SIZE> {
33        Err(AtError::NotSupported)
34    }
35
36    /// Query command (AT+CMD?)
37    /// This is called to retrieve the current value/state of a command.
38    fn query(&mut self) -> AtResult<'_, SIZE> {
39        Err(AtError::NotSupported)
40    }
41    
42    /// Test command (AT+CMD=?)
43    /// This is called to check if a command is supported or to get valid parameter ranges.
44    fn test(&mut self) -> AtResult<'_, SIZE> {
45        Err(AtError::NotSupported)
46    }
47
48    /// Set command (AT+CMD=args)
49    /// This is called to set parameters for a command.
50    fn set(&mut self, _args: Args) -> AtResult<'_, SIZE> {
51        Err(AtError::NotSupported)
52    }
53
54}