Crate urbandictionary[][src]

ci-badge license-badge docs-badge

urbandictionary.rs

Unofficial Rust crate for the Urbandictionary API.

Documentation

Installation

Add the following dependency to your Cargo.toml:

urbandictionary = "0.3"

And include it in your project:

extern crate urbandictionary;

Examples

Using hyper with the hyper-tls HTTPS connector, retrieve a list of definitions for a word and print the example of the second definition if it exists:

extern crate futures;
extern crate hyper;
extern crate hyper_tls;
extern crate tokio_core;
extern crate urbandictionary;

use futures::Future;
use hyper::client::{Client, HttpConnector};
use hyper_tls::HttpsConnector;
use tokio_core::reactor::Core;
use urbandictionary::HyperUrbanDictionaryRequester;

let mut core = Core::new()?;
let client = Client::configure()
    .connector(HttpsConnector::new(4, &core.handle())?)
    .build(&core.handle());

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");

Using reqwest, print the definition of the word "cat":

extern crate reqwest;
extern crate urbandictionary;


use reqwest::Client;
use urbandictionary::ReqwestUrbanDictionaryRequester;

let client = Client::new();
let response = client.define("cat")?;

if let Some(definition) = response {
    println!("The definition of cat is: {}", definition.definition);
} else {
    println!("No definition found");
}

License

License info in LICENSE.md. Long story short, ISC.

Re-exports

pub use bridge::reqwest::UrbanDictionaryRequester as ReqwestUrbanDictionaryRequester;

Modules

bridge

Bridged support between different HTTP clients.

model

Models mapping the UrbanDictionary API's response types.

Enums

Error

Common error type used throughout the library, to be used as a holder for errors from various other libraries.

Type Definitions

Result

Common result type used throughout the library.