2 个版本 (1 个稳定版)
1.0.0 | 2022 年 6 月 23 日 |
---|---|
0.1.0 | 2022 年 6 月 22 日 |
#2120 in 网页编程
23KB
269 行
animality.rs
一个简单的 Rust API 包装器,用于生成任何动物的图片和事实。
安装
将以下内容添加到您的 Cargo.toml 文件's 依赖项:
animality = "1.0.0"
阻塞请求
extern crate animality;
use animality::{Animality, Animal};
fn main() {
let client = Animality::new("your token here");
// request with the `Animal` enum
let dog_image = client.image(Animal::Dog).unwrap();
let dog_fact = client.fact(Animal::Dog).unwrap();
// request from a string (case-insensitive)
let cat: Animal = "cat".parse().unwrap();
let cat_image = client.image(cat).unwrap();
let cat_fact = client.fact(cat).unwrap();
}
异步请求
extern crate animality;
extern crate tokio;
use animality::{Animality, Animal, RequestError};
#[tokio::main]
async fn main() -> Result<(), RequestError> {
let client = Animality::new("your token here");
// request with the `Animal` enum
let dog_image = client.image_async(Animal::Dog).await?;
let dog_fact = client.fact_async(Animal::Dog).await?;
// request from a string (case-insensitive)
let cat: Animal = "cat".parse().unwrap();
let cat_image = client.image_async(cat).await?;
let cat_fact = client.fact_async(cat).await?;
Ok(())
}
依赖项
~0.6–9MB
~92K SLoC