dcs2 0.1.0

An extensible distributed control system framework made in rust with no-std support.
Documentation
use core::str::FromStr;
use heapless::{LinearMap, String, Vec};
use log::{debug, error};

use crate::nodes::{NodeRole, SystemClusterId, SystemNodeId};
use crate::properties::CLUSTERS_PER_TRANSLATOR;

const MAX_ARGUMENT_LENGTH: usize = 32;
const MAX_CUSTOMIZABLE_ARGS: usize = 8;

pub type ArgumentString = String<MAX_ARGUMENT_LENGTH>;
pub type CustomizableArgs = LinearMap<ArgumentString, ArgumentString, MAX_CUSTOMIZABLE_ARGS>;

pub fn get_argument(args: CustomizableArgs, raw_key: &str) -> Option<ArgumentString> {
    let key = String::from_str(raw_key).unwrap_or_else(|_| {
        error!("Couldn't create ArgumentString from value '{}'", raw_key);
        panic!()
    });

    args.get(&key).cloned().or_else(|| {
        debug!("Argument '{}' not given.", key);
        None
    })
}

#[derive(Clone)]
pub struct SystemNodeArgs {
    pub id: SystemNodeId,
    pub role: NodeRole,
    pub clusters: Vec<SystemClusterId, CLUSTERS_PER_TRANSLATOR>,
    pub coordination: Option<CustomizableArgs>,
    pub communication: CustomizableArgs,
    pub membership: CustomizableArgs,
}