Unofficial async Rust client for the Urbandictionary API.
This library requires at least Rust 1.39.
Add the following dependency to your Cargo.toml:
toml
urbandictionary = "0.4.0-alpha.1"
Retrieve a list of definitions for a word and print the example of the first definition, if it exists:
```rust extern crate futures; extern crate hyper; extern crate hypertls; extern crate tokiocore; extern crate urbandictionary;
use futures::Future; use hyper::client::{Client, HttpConnector}; use hypertls::HttpsConnector; use std::error::Error; use tokiocore::reactor::Core; use urbandictionary::HyperUrbanDictionaryRequester;
fn try_main() -> Result<(), Box
let done = client.definitions("cat").and_then(|response| {
if let Some(definition) = response.definitions.get(1) {
println!("Examples: {}", definition.example);
}
Ok(())
}).map_err(|_| ());
core.run(done).expect("Error running core");
Ok(())
}
fn main() { try_main().unwrap(); } ```
Using reqwest, print the definition of the word "cat"
:
```rust extern crate reqwest; extern crate urbandictionary;
use reqwest::Client; use std::error::Error; use urbandictionary::ReqwestUrbanDictionaryRequester;
fn try_main() -> Result<(), Box
if let Some(definition) = response {
println!("The definition of cat is: {}", definition.definition);
} else {
println!("No definition found");
}
Ok(())
}
fn main() { try_main().unwrap(); } ```