Version: dev

This is the documentation for the development version. For the latest release, see v0.11.0.

variable_bound

Stable type · Other

Tier: stable · Kind: type · Topic: Other

JuliaTypeScriptPythonRustGo
not exportednot exportednot exportedVariableBoundVariableBound

Julia

Julia does not export this type.

TypeScript

TypeScript does not export this type.

Python

Python does not export this type.

Rust

pub enum VariableBound {
    Number(Number),
    Reference(String),
    Expression(Expr),
}

impl VariableBound { pub fn as_number(&self) -> Option<f64> }

impl VariableBound { pub fn as_reference(&self) -> Option<&str> }

impl VariableBound { pub fn map_references(&self, f: impl FnOnce(&Expr) -> Expr) -> VariableBound }

One bound of a model variable (esm-spec §6.3.2): the lb or ub field.

#[serde(untagged)], so a number round-trips as the number written (held as a serde_json::Number, so 0 stays 0 and 0.5 stays 0.5) and a reference as the string written.

Source · Rust docs

Go

type VariableBound struct {
	Number any
	Ref    *string
}

func (b VariableBound) MarshalJSON() ([]byte, error)

func (b *VariableBound) UnmarshalJSON(data []byte) error

VariableBound is one bound of a model variable (esm-spec §6.3.2): a number in the variable’s declared units, or a reference to another variable, written and resolved as a variable reference in the model’s expressions. Exactly one of Number and Ref is set.

Number holds an int64 or a float64, decoded by the int/float rule every numeric literal follows (normalizeJSONNumber): a token with ‘.’, ’e’ or ‘E’ is a float64, any other an int64 (a float64 only beyond the int64 range). So a bound stays the number written (esm-spec §6.3.2, “Round-trip”): an integer keeps every digit, and a float is emitted as a float — 1.0 stays 1.0 rather than collapsing to 1 as the document form does elsewhere. A reference is emitted as the string written.

Methods

func (b VariableBound) MarshalJSON() ([]byte, error)

MarshalJSON writes the bound as a JSON number or a JSON string.

func (b *VariableBound) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a bound that is a JSON number or a JSON string. Whether the string names a variable is the validator’s question, not the decoder’s.

Source · Go docs