Expand description
§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
);
},
};Structs§
- Client to call API methods.
- API returned error.
- Parameters for
detectAPI method. - Response from
detectAPI method. - Parameters for
getLangsAPI method. - Response from
getLangsAPI method. - Parameters for
translateAPI method. - Response from
translateAPI method.
Enums§
- Possible types of errors.
Traits§
- Request to be executed.
- API method response.