Trait Translator

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

Source

fn name(&self) -> String

Source

fn translate( &self, variable: &VariableMeta<VarId, ScopeId>, value: &VariableValue, ) -> Result<TranslationResult>

Source

fn variable_info( &self, variable: &VariableMeta<VarId, ScopeId>, ) -> Result<VariableInfo>

Source

fn translates( &self, variable: &VariableMeta<VarId, ScopeId>, ) -> Result<TranslationPreference>

Return TranslationPreference based on if the translator can handle this variable.

Provided Methods§

Source

fn set_wave_source(&self, _wave_source: Option<WaveSource>)

Notify the translator that the wave source has changed to the specified source

Source

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

Source

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.

Implementors§