noshell_parser/
utils.rs

1//! Parser utilities.
2
3use heapless::Vec;
4
5use crate::Error;
6
7/// Check if the argument `Option` is `None` and return an error `Error::InvalidArgument` if true
8#[inline(always)]
9pub fn check_arg_is_missing<T>(v: Option<T>) -> Result<Option<T>, Error> {
10    v.map(Some).ok_or(Error::MissingArgument)
11}
12
13/// Check if the value `Option` is `None` and return an error `Error::InvalidArgument` if true
14#[inline(always)]
15pub fn check_value_is_missing<T>(v: Option<T>) -> Result<Option<T>, Error> {
16    v.map(Some).ok_or(Error::InvalidArgument)
17}
18
19/// Check if the `Vec` is empty and return an error `Error::InvalidArgument` if true.
20#[inline(always)]
21pub fn check_vec_is_missing<T, const SIZE: usize>(v: Vec<T, SIZE>) -> Result<Vec<T, SIZE>, Error> {
22    if v.is_empty() {
23        return Err(Error::InvalidArgument);
24    }
25
26    Ok(v)
27}