use super::ParamTable;
#[cfg(test)]
mod tests;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Bound {
value: f32,
inclusive: bool,
}
impl Bound {
pub const fn value(&self) -> f32 {
self.value
}
pub const fn inclusive(&self) -> bool {
self.inclusive
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ParamMeta {
name: &'static str,
description: &'static str,
units: &'static str,
category: &'static str,
group: &'static str,
min: Option<Bound>,
max: Option<Bound>,
}
impl ParamMeta {
pub const fn in_group(category: &'static str, group: &'static str) -> Self {
Self {
name: "",
description: "",
units: "",
category,
group,
min: None,
max: None,
}
}
pub const fn param(self, name: &'static str, description: &'static str) -> Self {
Self {
name,
description,
..self
}
}
pub const fn with_units(self, units: &'static str) -> Self {
Self { units, ..self }
}
pub const fn at_least(self, value: f32) -> Self {
self.with_min(value, true)
}
pub const fn above(self, value: f32) -> Self {
self.with_min(value, false)
}
pub const fn at_most(self, value: f32) -> Self {
self.with_max(value, true)
}
pub const fn below(self, value: f32) -> Self {
self.with_max(value, false)
}
const fn with_min(self, value: f32, inclusive: bool) -> Self {
Self {
min: Some(Bound { value, inclusive }),
..self
}
}
const fn with_max(self, value: f32, inclusive: bool) -> Self {
Self {
max: Some(Bound { value, inclusive }),
..self
}
}
pub const fn name(&self) -> &'static str {
self.name
}
pub const fn description(&self) -> &'static str {
self.description
}
pub const fn units(&self) -> &'static str {
self.units
}
pub const fn category(&self) -> &'static str {
self.category
}
pub const fn group(&self) -> &'static str {
self.group
}
pub const fn min(&self) -> Option<Bound> {
self.min
}
pub const fn max(&self) -> Option<Bound> {
self.max
}
}
pub trait ParamMetadata: ParamTable {
const METADATA: &'static [ParamMeta];
}