6个版本

0.1.7 2022年10月6日
0.1.6 2022年10月3日
0.1.1 2022年9月30日

#1424异步

每月 25 次下载

MIT 许可证

27KB
426

假日API Rust库

License Test Status Crates.io wakatime

不官方的假日API库,用Rust编写。此仓库实现了此处看到的原始假日API端点的接口。

致谢

此项目深受holidayapi-nodeholiday-api-rust存储库的启发。

安装

将以下内容添加到您的Cargo.toml

[dependencies]
holidayapi_rust = "0.1.7"

或者使用cargo CLI

$ cargo add holidayapi_rust

用法

基本

use holidayapi_rust::prelude::*;

let holiday_api = HolidayAPI::new("00000000-0000-0000-0000-000000000000").unwrap();

async fn main() {
	// Fetch supported countries and subdivisions
	let countries: Vec<Country> = holiday_api.countries().get().await.unwrap();

	// Fetch supported languages
	let languages: Vec<Language> = holiday_api.languages().get().await.unwrap();

	// Fetch holidays with minimum parameters
	let holidays: Vec<Holiday> = holiday_api.holidays("US", 2020).get().await.unwrap();
}

构建器模式

use holidayapi_rust::prelude::*;

let holiday_api = HolidayAPI::new(VALID_KEY).unwrap();

// Holidays
let specific_request: Vec<Holiday> = holiday_api
	.holidays("jp", 2021)
	.pretty(true)
	.language("cn")
	.public(true)
	.get()
	.await; 

// Countries
let specific_request: Vec<Country> = holiday_api
	.countries()
	.search("hello world")
	.country("US")
	.public(true)
	.get()
	.await
	.unwrap();

// Languages
let specific_request: Vec<Language> = holiday_api
	.languages()
	.search("chinese")
	.pretty(true)
	.get()
	.await
	.unwrap();

未来想法

  • 使用IntoFuture重构异步调用,以移除不必要的.get()调用。
  • 实现了API调用的缓存。
  • 在原始API之上添加新的实用函数。

依赖项

~7–22MB
~315K SLoC