1 个不稳定版本
0.1.0 | 2019年1月27日 |
---|
#46 in #org
39KB
644 行
一个非官方的 Rust 库,作为 Discord Bot List API 的包装器,提供对同步和异步 reqwest (v0.9) 的实现。
编译功能
- reqwest-sync-support: 与支持同步的
reqwest
编译(默认) - reqwest-async-support: 与支持异步的
reqwest
编译
请注意,reqwest-async-support
需要 nightly 以使用不稳定的 core::future
API。
安装
此库需要至少 Rust 1.31.0。
将以下内容添加到您的 Cargo.toml
文件中
[dependencies]
discord-bots-org = "0.1"
要启用异步和同步的 reqwest-async
和 reqwest-sync
支持
[dependencies.discord-bots-org]
version = "0.1"
features = ["reqwest-async-support", "reqwest-sync-support"]
要启用 reqwest-async-support
但不支持 reqwest-sync-support
[dependencies.discord-bots-org]
version = "0.1"
default-features = false
features = ["reqwest-async-support"]
示例
使用 reqwest 同步请求一个机器人
extern crate discord_bot_list;
extern crate reqwest;
use discord_bot_list::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(())
}
异步 reqwest 的示例很少。假设如果你使用不稳定异步 Rust API,你已经很熟练。
更多示例请参阅 示例 文件夹。
许可证
ISC。查看完整许可证 此处。
依赖项
~2.7–7MB
~162K SLoC