Skip to main content

ParameterServer

Struct ParameterServer 

Source
pub struct ParameterServer { /* private fields */ }
Expand description

Parameter server with static storage

Stores parameters in a fixed-size array. The capacity is determined at compile time via the MAX_PARAMETERS constant.

§Example

use nros_params::{ParameterServer, ParameterValue};

let mut server = ParameterServer::new();

// Declare a parameter with initial value
server.declare("max_speed", ParameterValue::Double(1.0));

// Get parameter value
if let Some(value) = server.get("max_speed") {
    println!("max_speed = {:?}", value.as_double());
}

// Set parameter value
server.set("max_speed", ParameterValue::Double(2.0));

Implementations§

Source§

impl ParameterServer

Source

pub const fn new() -> ParameterServer

Create a new empty parameter server

Source

pub fn take_dirty(&mut self) -> bool

Phase 172.H — take the dirty flag, clearing it. Returns true if a value changed (via set / unset) since the last call, signalling the persistence layer to flush.

Source

pub fn len(&self) -> usize

Get the number of parameters stored

Source

pub fn is_empty(&self) -> bool

Check if the server has no parameters

Source

pub fn is_full(&self) -> bool

Check if the server is at capacity

Source

pub fn declare(&mut self, name: &str, value: ParameterValue) -> bool

Declare a new parameter with a value

If the parameter already exists, this does nothing and returns false. Returns true if the parameter was declared successfully.

Source

pub fn declare_with_descriptor( &mut self, name: &str, value: ParameterValue, descriptor: Option<ParameterDescriptor>, ) -> bool

Declare a new parameter with value and descriptor

The descriptor provides metadata like description, constraints, and read-only flag.

Source

pub fn get(&self, name: &str) -> Option<&ParameterValue>

Get a parameter value by name

Source

pub fn get_parameter(&self, name: &str) -> Option<&Parameter>

Get a parameter by name

Source

pub fn get_descriptor(&self, name: &str) -> Option<&ParameterDescriptor>

Get a parameter descriptor by name

Source

pub fn set(&mut self, name: &str, value: ParameterValue) -> SetParameterResult

Set a parameter value

Returns the result of the set operation.

Source

pub fn unset(&mut self, name: &str) -> SetParameterResult

Unset an optional parameter (set to NotSet)

This bypasses the type check to allow optional parameters to be unset. Returns an error if the parameter is read-only.

Source

pub fn set_or_declare( &mut self, name: &str, value: ParameterValue, ) -> SetParameterResult

Set or declare a parameter

If the parameter exists, sets its value. Otherwise, declares it.

Source

pub fn has(&self, name: &str) -> bool

Check if a parameter exists

Source

pub fn remove(&mut self, name: &str) -> bool

Remove a parameter

Returns true if the parameter was removed.

Source

pub fn get_type(&self, name: &str) -> Option<ParameterType>

Get the type of a parameter

Source

pub fn iter(&self) -> impl Iterator<Item = &Parameter>

Iterate over all parameters

Source

pub fn list_names(&self) -> impl Iterator<Item = &str>

List all parameter names

Source

pub fn list_with_prefix<'a>( &'a self, prefix: &'a str, ) -> impl Iterator<Item = &'a str>

List parameter names with a given prefix

Source

pub fn get_bool(&self, name: &str) -> Option<bool>

Get a bool parameter value

Source

pub fn get_integer(&self, name: &str) -> Option<i64>

Get an integer parameter value

Source

pub fn get_double(&self, name: &str) -> Option<f64>

Get a double parameter value

Source

pub fn get_string(&self, name: &str) -> Option<&str>

Get a string parameter value

Source

pub fn set_bool(&mut self, name: &str, value: bool) -> SetParameterResult

Set a bool parameter value

Source

pub fn set_integer(&mut self, name: &str, value: i64) -> SetParameterResult

Set an integer parameter value

Source

pub fn set_double(&mut self, name: &str, value: f64) -> SetParameterResult

Set a double parameter value

Source

pub fn set_string(&mut self, name: &str, value: &str) -> SetParameterResult

Set a string parameter value

Source

pub fn declare_parameter( &mut self, descriptor: ParameterDescriptor, initial_value: Option<&ParameterValue>, ) -> Result<(), SetParameterResult>

Declare a parameter with a descriptor and optional initial value.

This is a more comprehensive declaration method used by the typed parameter API.

§Arguments
  • descriptor: The metadata for the parameter.
  • initial_value: An optional initial value for the parameter. If None, the parameter will be initialized to ParameterValue::NotSet.
Source

pub fn get_parameter_value(&self, name: &str) -> Option<ParameterValue>

Get the current value of a parameter.

Returns Some(ParameterValue) if the parameter exists, None otherwise. The ParameterValue is cloned to avoid lifetime issues with &mut self.

Source

pub fn set_parameter_value( &mut self, name: &str, value: ParameterValue, ) -> SetParameterResult

Set the value of a parameter.

Returns SetParameterResult::Success on success, or an error if the parameter is read-only, type mismatches, or is out of range.

Trait Implementations§

Source§

impl Default for ParameterServer

Source§

fn default() -> ParameterServer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.