urbandictionary

Crates.iourbandictionary
lib.rsurbandictionary
version0.4.0-alpha.1
sourcesrc
created_at2016-08-22 00:40:05.34526
updated_at2019-10-10 21:34:34.167423
descriptionUnofficial Rust wrapper for the UrbanDictionary API
homepagehttps://github.com/zeyla/urbandictionary.rs
repositoryhttps://github.com/zeyla/urbandictionary.rs.git
max_upload_size
id6060
size15,145
Zeyla Hellyer (zeyla)

documentation

https://docs.rs/crate/urbandictionary

README

ci-badge license-badge docs-badge rust badge

urbandictionary.rs

Unofficial async Rust client for the Urbandictionary API.

Documentation

Installation

This library requires at least Rust 1.39.

Add the following dependency to your Cargo.toml:

urbandictionary = "0.4.0-alpha.1"

Examples

Retrieve a list of definitions for a word and print the example of the first 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 std::error::Error;
use tokio_core::reactor::Core;
use urbandictionary::HyperUrbanDictionaryRequester;

fn try_main() -> Result<(), Box<Error>> {
    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");

    Ok(())
}

fn main() {
    try_main().unwrap();
}

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

extern crate reqwest;
extern crate urbandictionary;

use reqwest::Client;
use std::error::Error;
use urbandictionary::ReqwestUrbanDictionaryRequester;


fn try_main() -> Result<(), Box<Error>> {
    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");
    }

    Ok(())
}

fn main() {
    try_main().unwrap();
}
Commit count: 0

cargo fmt