pub trait Translator<VarId, ScopeId, Message>: Send + Sync {
// Required methods
fn name(&self) -> String;
fn translate(
&self,
variable: &VariableMeta<VarId, ScopeId>,
value: &VariableValue,
) -> Result<TranslationResult>;
fn variable_info(
&self,
variable: &VariableMeta<VarId, ScopeId>,
) -> Result<VariableInfo>;
fn translates(
&self,
variable: &VariableMeta<VarId, ScopeId>,
) -> Result<TranslationPreference>;
// Provided methods
fn set_wave_source(&self, _wave_source: Option<WaveSource>) { ... }
fn translate_numeric(
&self,
variable: &VariableMeta<VarId, ScopeId>,
value: &VariableValue,
) -> Option<f64> { ... }
fn reload(&self, _sender: Sender<Message>) { ... }
fn variable_name_info(
&self,
variable: &VariableMeta<VarId, ScopeId>,
) -> Option<VariableNameInfo> { ... }
}Expand description
The most general translator trait.
Required Methods§
Sourcefn translate(
&self,
variable: &VariableMeta<VarId, ScopeId>,
value: &VariableValue,
) -> Result<TranslationResult>
fn translate( &self, variable: &VariableMeta<VarId, ScopeId>, value: &VariableValue, ) -> Result<TranslationResult>
Translate the specified variable value into a human-readable form
Sourcefn variable_info(
&self,
variable: &VariableMeta<VarId, ScopeId>,
) -> Result<VariableInfo>
fn variable_info( &self, variable: &VariableMeta<VarId, ScopeId>, ) -> Result<VariableInfo>
Return information about the structure of a variable, see VariableInfo.
Sourcefn translates(
&self,
variable: &VariableMeta<VarId, ScopeId>,
) -> Result<TranslationPreference>
fn translates( &self, variable: &VariableMeta<VarId, ScopeId>, ) -> Result<TranslationPreference>
Return TranslationPreference based on if the translator can handle this variable.
Provided Methods§
Sourcefn set_wave_source(&self, _wave_source: Option<WaveSource>)
fn set_wave_source(&self, _wave_source: Option<WaveSource>)
Notify the translator that the wave source has changed to the specified source
Sourcefn translate_numeric(
&self,
variable: &VariableMeta<VarId, ScopeId>,
value: &VariableValue,
) -> Option<f64>
fn translate_numeric( &self, variable: &VariableMeta<VarId, ScopeId>, value: &VariableValue, ) -> Option<f64>
Translate a variable value to a numeric f64 for analog rendering.
Returns NAN_UNDEF for undefined values and NAN_HIGHIMP for high-impedance.
The default implementation calls Self::translate and parses the result.
Translators that produce numeric output should override this for
efficient analog signal rendering without string round-trip.
Sourcefn reload(&self, _sender: Sender<Message>)
fn reload(&self, _sender: Sender<Message>)
By default translators are stateless, but if they need to reload, they can
do by defining this method.
Long running translators should run the reloading in the background using perform_work
Sourcefn variable_name_info(
&self,
variable: &VariableMeta<VarId, ScopeId>,
) -> Option<VariableNameInfo>
fn variable_name_info( &self, variable: &VariableMeta<VarId, ScopeId>, ) -> Option<VariableNameInfo>
Returns a VariableNameInfo about the specified variable which will be applied globally.
Most translators should simply return None here, see the
documentation VariableNameInfo for exceptions to this rule.