[−][src]Struct text_translator::Yandex
Yandex Translate API
A struct representing the Yandex Translate API.
This API needs a key, which can be provided at this page.
It implements:
- language translation, with the default
Api
trait - language detection, with the
ApiDetect
trait - API key, with the
ApiKey
trait
To use it, first construct the struct with a defined API key, then do the desired function calls.
Examples
Important: In order to use those examples, you need to get a free API Key on the
Yandex website and replace the YANDEX_API_KEY
const with it.
Text translation
Translate a text from an unknown language to Japanese:
use text_translator::*; // set your personnal API key const YANDEX_API_KEY: &str = "trnsl.1.1.20200507T202428Z.5e03932d06f63e6a.6ca69498c3b22bff94f6eda9ad8c21b4c3320078"; // construct the struct let translator: Yandex = Yandex::with_key(YANDEX_API_KEY); let text: String = "Hello, my name is Naruto Uzumaki!".to_string(); // translate the text, returns a `Result<String, Error>` let translated_text: String = match translator.translate(text, InputLanguage::Automatic, Language::Japanese) { Ok(result) => result, Err(err) => panic!("API error, could not translate text : {:#?}", err) }; assert_eq!(translated_text, "こんにちは、鳴門のうずまき!")
Language detection
Detect the language of a text:
use text_translator::*; const YANDEX_API_KEY: &str = "trnsl.1.1.20200507T202428Z.5e03932d06f63e6a.6ca69498c3b22bff94f6eda9ad8c21b4c3320078"; let translator: Yandex = Yandex::with_key(YANDEX_API_KEY); let text: String = "Bonjour, je m'appelle Naruto Uzumaki!".to_string(); // detect the language, returns a `Result<Option<Language>, Error>` let detected_language: Language = match translator.detect(text) { Ok(response) => match response { Some(language) => language, None => panic!("Could detect language : unknown language"), }, Err(err) => panic!("API error, could not detect language : {:#?}", err) }; assert_eq!(detected_language, Language::French)
Implementations
impl<'a> Yandex<'a>
[src]
pub const fn with_key(key: &'a str) -> Self
[src]
Returns a new Yandex
struct with the given API key.
Can be used in constant definitions.
Trait Implementations
impl<'a> Api for Yandex<'a>
[src]
fn new() -> Self
[src]
fn translate(
&self,
text: String,
source_language: InputLanguage,
target_language: Language
) -> Result<String, Error>
[src]
&self,
text: String,
source_language: InputLanguage,
target_language: Language
) -> Result<String, Error>
impl<'a> ApiDetect for Yandex<'a>
[src]
impl<'a> ApiKey<'a> for Yandex<'a>
[src]
impl<'a> Clone for Yandex<'a>
[src]
impl<'a> Copy for Yandex<'a>
[src]
impl<'a> Debug for Yandex<'a>
[src]
impl<'a> Eq for Yandex<'a>
[src]
impl<'a> Ord for Yandex<'a>
[src]
fn cmp(&self, other: &Yandex<'a>) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a> PartialEq<Yandex<'a>> for Yandex<'a>
[src]
impl<'a> PartialOrd<Yandex<'a>> for Yandex<'a>
[src]
fn partial_cmp(&self, other: &Yandex<'a>) -> Option<Ordering>
[src]
fn lt(&self, other: &Yandex<'a>) -> bool
[src]
fn le(&self, other: &Yandex<'a>) -> bool
[src]
fn gt(&self, other: &Yandex<'a>) -> bool
[src]
fn ge(&self, other: &Yandex<'a>) -> bool
[src]
impl<'a> StructuralEq for Yandex<'a>
[src]
impl<'a> StructuralPartialEq for Yandex<'a>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Yandex<'a>
impl<'a> Send for Yandex<'a>
impl<'a> Sync for Yandex<'a>
impl<'a> Unpin for Yandex<'a>
impl<'a> UnwindSafe for Yandex<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,