8个版本 (4个破坏性更新)
0.5.2 | 2024年8月5日 |
---|---|
0.5.1 | 2024年5月24日 |
0.5.0 | 2023年10月18日 |
0.4.1 | 2022年12月14日 |
0.1.0 | 2022年3月29日 |
在Web编程中排名第563
每月下载量115次
17KB
184 行
世界时间包装器
这是一个对World Time API的简单包装。这个crate基于Dulatr的WorldTimeAPI包装器。
用法
要使用此crate,将worldtimeapi
添加到您的Cargo.toml
[dependencies]
worldtimeapi = "0.5.1"
然后为端点创建一个客户端(目前它们只提供"ip"和"timezone")
use std::collections::HashMap;
use worldtimeapi::service::{Client, Endpoint};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = Client::new(Endpoint::Timezone).await?;
let mut payload = HashMap::new();
payload.insert("area", "America");
payload.insert("location", "New_York");
let result = client.get(payload).await?;
println!("{}", result.datetime());
Ok(())
}
要获取地区和位置列表,请使用regions
方法
use worldtimeapi::service::{Client, Endpoint};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = Client::new(Endpoint::Timezone).await?;
let regions = client.regions();
println!("{:?}", regions);
Ok(())
}
依赖关系
~5–17MB
~242K SLoC