embedded_basic/embedded_basic.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
21//! Basic usage example demonstrating no_std compatible code
22//! This example shows how the parser can be used in no_std contexts
23
24#![allow(dead_code)]
25
26extern crate at_parser_rs;
27
28use at_parser_rs::{Args, AtError, AtResult};
29
30// Example function using Args in no_std
31fn parse_args_example() -> AtResult<'static> {
32 let args = Args { raw: "foo,bar,baz" };
33 match args.get(1) {
34 Some(val) => Ok(val),
35 None => Err(AtError::InvalidArgs),
36 }
37}
38
39// Example of error handling
40fn handle_error_example() -> &'static str {
41 match parse_args_example() {
42 Ok(val) => val,
43 Err(AtError::InvalidArgs) => "Argomento non valido",
44 Err(_) => "Errore generico",
45 }
46}
47
48// In an embedded environment, these functions can be called from main or from a task.
49
50// Mock main for compilation (in real embedded code, this would be in your firmware)
51fn main() {
52 // Example usage - in embedded this would be called from your main loop
53 let _result = handle_error_example();
54}