rustplex 0.3.0

A linear programming solver based on the Simplex algorithm for Rust
Documentation
use crate::common::expression::{impl_expr_display, impl_expr_ops, ExprVariable};
use slotmap::new_key_type;
use std::fmt;

new_key_type! {
    pub struct StandardVariableKey;
}

impl fmt::Display for StandardVariableKey {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "StandardVariableKey({:?})", self.0)
    }
}

impl ExprVariable for StandardVariableKey {}

impl_expr_ops!(StandardVariableKey);
impl_expr_display!(StandardVariableKey);

#[derive(Debug, Clone)]
pub struct StandardVariable {
    name: Option<String>,
}

// Public Getters for Read-Only Access
impl StandardVariable {
    pub fn new() -> Self {
        Self { name: None }
    }

    pub fn with_name(mut self, name: impl Into<String>) -> Self {
        self.name = Some(name.into());
        self
    }

    /// Returns the name of the standard variable.
    pub fn name(&self) -> &str {
        self.name.as_deref().unwrap_or("<unnamed>")
    }
}

impl Default for StandardVariable {
    fn default() -> Self {
        Self { name: None }
    }
}

impl fmt::Display for StandardVariable {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "StandardVariable({})", self.name())
    }
}