pub trait Calc:
Send
+ Sync
+ Debug
+ Serialize
+ Deserialize {
// Required methods
fn init(
&mut self,
ctx: ControllerCtx,
input_indices: Vec<usize>,
output_range: Range<usize>,
) -> Result<(), String>;
fn terminate(&mut self) -> Result<(), String>;
fn eval(&mut self, tape: &mut [f64]) -> Result<(), String>;
fn get_input_map(&self) -> BTreeMap<CalcInputName, FieldName>;
fn update_input_map(
&mut self,
field: &str,
source: &str,
) -> Result<(), String>;
fn get_save_outputs(&self) -> bool;
fn set_save_outputs(&mut self, save_outputs: bool);
fn get_config(&self) -> BTreeMap<String, f64>;
fn set_config(&mut self, cfg: &BTreeMap<String, f64>) -> Result<(), String>;
fn get_input_names(&self) -> Vec<CalcInputName> ⓘ;
fn get_output_names(&self) -> Vec<CalcOutputName> ⓘ;
// Provided method
fn kind(&self) -> String { ... }
}Expand description
A calculation that takes some inputs and produces some outputs at each timestep, and may have some persistent internal state.
Required Methods§
Sourcefn init(
&mut self,
ctx: ControllerCtx,
input_indices: Vec<usize>,
output_range: Range<usize>,
) -> Result<(), String>
fn init( &mut self, ctx: ControllerCtx, input_indices: Vec<usize>, output_range: Range<usize>, ) -> Result<(), String>
Reset internal state and register calc tape indices
Sourcefn get_input_map(&self) -> BTreeMap<CalcInputName, FieldName>
fn get_input_map(&self) -> BTreeMap<CalcInputName, FieldName>
Map from input field names (like v, without prefix) to the state name
that the input should draw from (like peripheral_0.output_1, with prefix)
Sourcefn update_input_map(&mut self, field: &str, source: &str) -> Result<(), String>
fn update_input_map(&mut self, field: &str, source: &str) -> Result<(), String>
Change a value in the input map
Sourcefn get_save_outputs(&self) -> bool
fn get_save_outputs(&self) -> bool
Get flag for whether to save outputs
Sourcefn set_save_outputs(&mut self, save_outputs: bool)
fn set_save_outputs(&mut self, save_outputs: bool)
Set flag for whether to save outputs
Sourcefn get_config(&self) -> BTreeMap<String, f64>
fn get_config(&self) -> BTreeMap<String, f64>
Get config field values
Sourcefn set_config(&mut self, cfg: &BTreeMap<String, f64>) -> Result<(), String>
fn set_config(&mut self, cfg: &BTreeMap<String, f64>) -> Result<(), String>
Apply config field values
Sourcefn get_input_names(&self) -> Vec<CalcInputName> ⓘ
fn get_input_names(&self) -> Vec<CalcInputName> ⓘ
List of input field names in the order that they will be consumed
Sourcefn get_output_names(&self) -> Vec<CalcOutputName> ⓘ
fn get_output_names(&self) -> Vec<CalcOutputName> ⓘ
List of output field names in the order that they will be written out
Provided Methods§
Trait Implementations§
Source§impl Clone for Box<dyn Calc>
Clone isn’t inherently object-safe, so to be able to clone dyn trait objects,
we send it for a loop through the serde typetag system, which provides an
automatically-assembled vtable to determine the downcasted type and clone into it.
impl Clone for Box<dyn Calc>
Clone isn’t inherently object-safe, so to be able to clone dyn trait objects, we send it for a loop through the serde typetag system, which provides an automatically-assembled vtable to determine the downcasted type and clone into it.
Source§impl<'a, 'py> FromPyObject<'a, 'py> for Box<dyn Calc>
Glue for passing dyn Trait objects from Python to Rust via json
to handle the fact that they are concrete types on the Python side,
but dyn Trait objects on the Rust side.
impl<'a, 'py> FromPyObject<'a, 'py> for Box<dyn Calc>
Glue for passing dyn Trait objects from Python to Rust via json to handle the fact that they are concrete types on the Python side, but dyn Trait objects on the Rust side.