Crate kitsu [] [src]

kitsu.rs

An unofficial Rust library acting as a wrapper around the Kitsu API, offering implementations for both asynchronous hyper (v0.11) and synchronous reqwest (v0.8).

note: The library supports retrieval from the API, but does not currently support authenticated requests.

Compile features

  • hyper-support: Compiles with hyper support
  • reqwest-support: Compliles with reqwest support (default)

Installation

Add the following to your Cargo.toml file:

[dependencies]
kitsu = "0.1"

To enable both hyper and reqwest support:

[dependencies.kitsu]
version = "0.1"
features = ["hyper-support", "reqwest-support"]

To enable hyper but not reqwest support:

[dependencies.kitsu]
version = "0.1"
default-features = false
features = ["hyper-support"]

Examples

Using reqwest, search for an anime using a string taken from user input:

extern crate kitsu;
extern crate reqwest;


use kitsu::KitsuReqwestRequester;
use reqwest::Client;
use std::io::{self, Write};

// Create the reqwest Client.
let client = Client::new();

// Read an anime name to search for from the users input.
let mut input = String::new();
print!("Enter an anime name to search for:\n>");
let _ = io::stdout().flush();
io::stdin().read_line(&mut input).expect("Error reading input");
let input_trimmed = input.trim();

// Search for the anime.
let anime = client.search_anime(|f| f.filter("text", input_trimmed))
    .expect("Error searching for anime");

// Print out the response of the request.
if let Some(ref picked) = anime.data.first() {
    let title = &picked.attributes.canonical_title;

    if let Some(ref rating) = picked.attributes.average_rating {
        println!("Found Anime: {} - {}", title, rating);
    } else {
       println!("Found Anime: {} - ??", title);
    }
} else {
    println!("No Anime Found.");
}

For more examples, refer to the examples folder.

License

ISC. View the full license here.

Re-exports

pub use bridge::reqwest::KitsuRequester as KitsuReqwestRequester;

Modules

bridge

Briding support between the library and various HTTP clients.

builder

A set of builders for ease of use with optional parameters around the API.

model

Models in struct form, parsed out from JSON in response bodies.

Enums

Error

An error type to compose a singular error enum between various dependencies' errors.

Constants

API_URL

Kitsu API Url

Type Definitions

Result

A result type to compose a successful value and the library's Error type.