use crate::variables::core::{VarId, Val, Vars};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(hidden)]
pub enum ViewType {
Integer,
Float,
}
#[allow(private_bounds)]
pub trait View: ViewRaw {
fn get_underlying_var(self) -> Option<VarId> {
self.get_underlying_var_raw()
}
fn min(self, ctx: &Context) -> Val {
self.min_raw(&ctx.vars)
}
fn max(self, ctx: &Context) -> Val {
self.max_raw(&ctx.vars)
}
fn contains(self, ctx: &Context, val: Val) -> bool {
self.contains_raw(&ctx.vars, val)
}
fn is_fixed(self, ctx: &Context) -> bool {
self.is_fixed_raw(&ctx.vars)
}
fn assigned_value(self, ctx: &Context) -> Option<Val> {
if self.is_fixed(ctx) {
Some(self.min(ctx))
} else {
None
}
}
fn view_type(self) -> ViewType;
}
#[doc(hidden)]
pub trait ViewRaw: Copy + core::fmt::Debug + 'static {
fn get_underlying_var_raw(self) -> Option<VarId>;
fn min_raw(self, vars: &Vars) -> Val;
fn max_raw(self, vars: &Vars) -> Val;
fn contains_raw(self, vars: &Vars, val: Val) -> bool;
fn is_fixed_raw(self, vars: &Vars) -> bool;
}
#[doc(hidden)]
#[derive(Clone, Debug)]
pub struct Context {
pub vars: Vars,
}
impl Context {
pub fn new(vars: Vars) -> Self {
Self { vars }
}
}