Skip to main content

ModelManager

Struct ModelManager 

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

Model manager for device models

Implementations§

Source§

impl ModelManager

Source

pub fn new(model_dir: Option<PathBuf>) -> Result<Self>

Create a new model manager

§Arguments
  • model_dir - Optional custom directory for model files
§Returns
  • Result<ModelManager> - The new model manager or an error
Source

pub fn reload_models(&mut self) -> Result<()>

Reload all models from the model directory

§Returns
  • Result<()> - Ok if models were loaded successfully, an error otherwise
Source

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

Get a model by name

§Arguments
  • name - The name of the model
§Returns
  • Option<&DeviceModel> - The model if found, None otherwise
Source

pub fn get_model_mut(&mut self, name: &str) -> Option<&mut DeviceModel>

Get a mutable model by name

§Arguments
  • name - The name of the model
§Returns
  • Option<&mut DeviceModel> - The model if found, None otherwise
Source

pub fn get_all_models(&self) -> &HashMap<String, DeviceModel>

Get all loaded models

§Returns
  • &HashMap<String, DeviceModel> - Map of model names to models
Source

pub fn create_model( &mut self, name: &str, pins: HashMap<u8, PinModel>, ) -> Result<()>

Create a new model

§Arguments
  • name - The name of the model
  • pins - Map of pin numbers to pin models
§Returns
  • Result<()> - Ok if the model was created successfully, an error otherwise
Source

pub fn save_model(&self, model: &DeviceModel) -> Result<()>

Save a model to a file

§Arguments
  • model - The model to save
§Returns
  • Result<()> - Ok if the model was saved successfully, an error otherwise
Source

pub fn delete_model(&mut self, name: &str) -> Result<()>

Delete a model

§Arguments
  • name - The name of the model
§Returns
  • Result<()> - Ok if the model was deleted successfully, an error otherwise
Source

pub fn copy_model(&mut self, source_name: &str, target_name: &str) -> Result<()>

Create a copy of a model with a new name

§Arguments
  • source_name - The name of the source model
  • target_name - The name of the target model
§Returns
  • Result<()> - Ok if the model was copied successfully, an error otherwise
Source

pub fn validate_model(&self, name: &str) -> Result<()>

Validate a model

§Arguments
  • name - The name of the model
§Returns
  • Result<()> - Ok if the model is valid, an error otherwise
Source

pub fn get_model_dir(&self) -> &Path

Get the model directory

§Returns
  • &Path - The model directory

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.