Trait Api

Source
pub trait Api {
    // Required methods
    fn new() -> Self;
    fn translate(
        &self,
        text: String,
        source_language: InputLanguage,
        target_language: Language,
    ) -> Result<String, Error>;
}
Expand description

A trait defining a translate API.

Implements new() to return a new API, and translate() to translate a text.

Required Methods§

Source

fn new() -> Self

Returns a new API struct, without initiating it.

Source

fn translate( &self, text: String, source_language: InputLanguage, target_language: Language, ) -> Result<String, Error>

Translates text between two languages.

Takes in input the selected text and two enums:

  • source_language: InputLanguage, representing either automatic language detection or a defined language;
  • target_language: Language, representing a defined language to output to.

Returns a Result containing either a String with the translated text, or an Error that happened during the process.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> Api for Yandex<'a>