embedded_basic/embedded_basic.rs
1/***************************************************************************
2 *
3 * AT Command Parser
4 * Copyright (C) 2026 Antonio Salsi <passy.linux@zresa.it>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ***************************************************************************/
19
20//! Basic usage example demonstrating no_std compatible code
21//! This example shows how the parser can be used in no_std contexts
22
23#![allow(dead_code)]
24
25extern crate at_parser_rs;
26
27use at_parser_rs::{Args, AtError, AtResult};
28
29// Example function using Args in no_std
30fn parse_args_example() -> AtResult<'static> {
31 let args = Args { raw: "foo,bar,baz" };
32 match args.get(1) {
33 Some(val) => Ok(val),
34 None => Err(AtError::InvalidArgs),
35 }
36}
37
38// Example of error handling
39fn handle_error_example() -> &'static str {
40 match parse_args_example() {
41 Ok(val) => val,
42 Err(AtError::InvalidArgs) => "Argomento non valido",
43 Err(_) => "Errore generico",
44 }
45}
46
47// In an embedded environment, these functions can be called from main or from a task.
48
49// Mock main for compilation (in real embedded code, this would be in your firmware)
50fn main() {
51 // Example usage - in embedded this would be called from your main loop
52 let _result = handle_error_example();
53}