3 releases
0.1.2 | Jul 21, 2019 |
---|---|
0.1.1 | Jan 7, 2019 |
0.1.0 | Oct 7, 2018 |
#11 in #yandex
19KB
414 lines
ytr
Yandex.Translate API wrapper for Rust
- Documentation
- crates.io
- About Yandex.Translate API (in Russian)
Usage example
let key = String::from("my-api-key");
let api = ytr::ApiClient::new(key);
let result = api.translate("Hello!", "ru") // required parameters
.format("plain") // optional parameter
.get(); // execute the request
match result {
Ok(response) => {
println!("{}", response.text); // prints "Привет!"
println!("{}", response.lang); // prints "en-ru"
},
Err(error) => {
eprintln!(
"An error has occurred: {:?}",
error
);
},
};
License
Licensed under MIT license
Contribution
You are free to propose changes and contribute. Any input is welcome =)
lib.rs
:
ytr
This crate is a Yandex.Translate API wrapper for Rust. It helps to use machine translations in your Rust application. A detailed description of the Yandex.Translate API and its methods is available in the official documentation (in Russian).
Usage
To work with the API you will need an ApiClient
instance holding your API key.
ApiClient
defines several methods that correspond to API methods. They are called with the
required parameters and return a request object, which can then be configured with optional
parameters and executed using the get()
method.
The execution of the request returns Result<T, ytr::Error>
, where T is a response object.
If the request was successful, the returned data will be contained in the public fields of the
response. Some data is returned only when the optional parameters are set, so the fields for
it contain the Option<T>
.
Usage example
let key = String::from("my-api-key");
let api = ytr::ApiClient::new(key);
let result = api.translate("Hello!", "ru") // required parameters
.format("plain") // optional parameter
.get(); // execute the request
match result {
Ok(response) => {
println!("{}", response.text); // prints "Привет!"
println!("{}", response.lang); // prints "en-ru"
},
Err(error) => {
eprintln!(
"An error has occurred: {:?}",
error
);
},
};
Dependencies
~22MB
~451K SLoC