1个不稳定版本
0.1.0 | 2021年7月28日 |
---|
#40 in #event-handling
49 个月下载量
15KB
188 代码行数,不含注释
DList.top Rust客户端
官方 dlist.top 网关客户端,适用于Rust。
安装
[dependencies]
dlist_top = "*"
设置
要获取您的令牌,请参阅 DList.top 文档。
使用方法
use dlist_top::{Client, EventHandler};
use dlist_top::events::{VoteData, RateData};
use dlist_top::entity::Entity;
use async_trait::async_trait;
use tracing_subscriber::FmtSubscriber;
use tracing::Level;
struct DlistEvents;
#[async_trait]
impl EventHandler for DlistEvents {
async fn on_ready(&self, _entity: &Entity) {
println!("DList.top ready!");
}
async fn on_disconnect(&self, reason: &str) {
println!("DList.top disconnected with reason: {}", reason)
}
async fn on_vote(&self, data: VoteData) {
println!("vote! {:?}", data);
}
async fn on_rate(&self, data: RateData) {
println!("rate! {:?}", data);
}
}
#[tokio::main]
async fn main() {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
tracing::subscriber::set_global_default(subscriber)
.expect("setting default subscriber failed");
let mut client = Client::new("TOKEN", DlistEvents);
client.connect().await;
}
依赖项
~19–32MB
~578K 额外代码行数