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.
25pub trait AtContext {
26
27    /// Execute command (AT+CMD)
28    /// This is called when a command is invoked without any suffix.
29    fn exec(&self) -> AtResult<'static> {
30        Err(AtError::NotSupported)
31    }
32
33    /// Query command (AT+CMD?)
34    /// This is called to retrieve the current value/state of a command.
35    fn query(&mut self) -> AtResult<'static> {
36        Err(AtError::NotSupported)
37    }
38    
39    /// Test command (AT+CMD=?)
40    /// This is called to check if a command is supported or to get valid parameter ranges.
41    fn test(&mut self) -> AtResult<'static> {
42        Err(AtError::NotSupported)
43    }
44
45    /// Set command (AT+CMD=args)
46    /// This is called to set parameters for a command.
47    fn set(&mut self, _args: Args) -> AtResult<'static> {
48        Err(AtError::NotSupported)
49    }
50
51}