[][src]Crate discord_bots_org

travis-badge license-badge docs-badge rust badge

An unofficial Rust library acting as a wrapper around the Discord Bot List API, offering implementations for both sync and async reqwest (v0.9).

Compile features

  • reqwest-sync-support: Compliles with sync reqwest support (default)
  • reqwest-async-support: Compiles with async reqwest support

Note that reqwest-async-support requires nightly for the unstable core::future API.

Installation

This library requires at least Rust 1.31.0.

Add the following to your Cargo.toml file:

[dependencies]
discord-bots-org = "0.1"

To enable both async reqwest-async and reqwest-sync support:

[dependencies.discord-bots-org]
version = "0.1"
features = ["reqwest-async-support", "reqwest-sync-support"]

To enable reqwest-async-support but not reqwest-sync-support:

[dependencies.discord-bots-org]
version = "0.1"
default-features = false
features = ["reqwest-async-support"]

Examples

Using reqwest synchronously, request a bot by ID:

extern crate discord_bots_org;
extern crate reqwest;

use discord_bots_org::ReqwestSyncClient as ApiClient;
use reqwest::Client as ReqwestClient;
use std::{
    error::Error,
    sync::Arc,
};

fn main() -> Result<(), Box<Error>> {
    // Create the Reqwest Client.
    let reqwest_client = Arc::new(ReqwestClient::new());

    // Create the API Client.
    let client = ApiClient::new(Arc::clone(&reqwest_client));

    // Request the bot information.
    let bot = client.get_bot(270_198_738_570_444_801)?;

    println!("The bot's name is: {}", bot.username);

    Ok(())
}

Examples are sparse for asynchronous reqwest. It is assumed that if you're using unstable asynchronous Rust APIs that you're already proficient in them.

For more examples, refer to the examples folder.

License

ISC. View the full license here.

Re-exports

pub use self::bridge::reqwest::async::Client as ReqwestAsyncClient;
pub use self::bridge::reqwest::sync::Client as ReqwestSyncClient;

Modules

bridge

Bridging support between the library and various HTTP clients.

builder

A set of builders useful for building optional portions of request parameters and other miscellaneous tasks.

model

Models mapping the Discord Bot List API.

Enums

Error

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

Type Definitions

Result

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