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 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§
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>
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 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.