9 个稳定版本
| 新增 1.5.1 | 2024 年 8 月 18 日 |
|---|---|
| 1.4.0 | 2024 年 7 月 18 日 |
| 1.3.0 | 2024 年 3 月 25 日 |
| 1.1.1 | 2024 年 2 月 23 日 |
#314 在 Rust 模式 中
每月 219 次下载
用于 9 个 crate
25KB
91 行
rst-common
快速访问常用 Rust crate。
动机
创建此 crate 的原因是由于我需要在每个项目中安装大量的常用 crate 库,而且我习惯了使用很多常用库。
所以我一直在想,与其重复我的活动,比如查找库、手动注册等,不如只安装一个包含所有我喜欢的 crate 的单个 crate 会更好。
安装
标准用法
[dependencies]
rst-common = {version = "1.5.0"}
示例安装 with-tokio 功能
[dependencies]
rst-common = {version = "1.3.0", features: ["with-tokio"]}
示例
您可以通过查看 examples 目录来了解如何使用此库。
代码
use rst_common::standard::uuid::Uuid;
fn main() {
let uid = Uuid::new_v4();
println!("{}", uid)
}
特殊 Crates
警告
特殊 Crates 意味着,它们有特定的使用方法,例如
thiserror和serde。这些 crate 需要特殊的用法,因为它们使用了proc_macro。
警告
删除包
mockall
thiserror
use rst_common::with_errors::thiserror:{self, Error};
#[derive(Error)]
enum MyError {
#[error("general error")]
GeneralError,
}
需要使用 self,这会向编译器发出信号,表示 Error 宏来自 thiserror,并且 crate 存在
serde
use rst_common::standard::serde::{self, Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(crate = "self::serde")]
struct Message {
msg: String,
}
针对 serde crate,由于此 crate 依赖于 serde_derive,它调用 serde::,我们需要显式地告诉 serde 使用的 crate 路径。
版本要求
所有使用的 crate 都将遵循这些要求
- 所有低于
1.x(<1.0.0) 的 crate 将保持版本直到次版本,例如:~0.1,这意味着所有新的更新patch版本应自动更新,但不是minor版本。版本~0.1将自动更新到0.1.1等,只要次版本相同。此规则背后的原因是,任何低于1.0.0的版本都假定仍在积极开发中,为了保持兼容性,它将使用其minor版本来保护。 - 所有等于或高于
1.x的 crate 将使用其主版本来维护版本,例如:~1。例如,如果我们使用一个版本为1.0.1的 crate,此规则应自动更新为下一个版本:1.0.2或甚至1.1.0,但它不会遵循版本2.0.0(假定主版本的更改将给我们带来破坏性兼容性)
信息
如果有任何支持 crate 的更新版本,它将通过此库手动更新
例如,现在我们支持 tokio: ~1,这意味着如果 tokio 库发布其新的主要版本:2.0.0,此 crate 将手动更新以支持最新版本
类别(功能标志)
标准完整包含-tokio包含-tracing包含-logging包含-errors包含-tests包含-http-tokio包含-cryptography
此库实际上只是根据您选择的 功能 重新导出所有已安装的常用 crate。
standard 功能
#[cfg(feature = "standard")]
pub mod standard {
pub use async_trait;
pub use chrono;
pub use dyn_clone;
pub use erased_serde;
pub use futures;
pub use serde;
pub use serde_json;
pub use uuid;
}
full 功能
#[cfg(feature = "full")]
pub mod full {
pub use async_trait;
pub use chrono;
pub use dyn_clone;
pub use erased_serde;
pub use futures;
pub use serde;
pub use serde_json;
pub use uuid;
pub use tokio;
pub use tracing;
pub use tracing_subscriber;
pub use env_logger;
pub use log;
pub use anyhow;
pub use thiserror;
pub use mockall;
pub use table_test;
pub use axum;
pub use hyper;
pub use hyper_util;
pub use tower;
pub use tower_http;
pub use rand;
pub use rand_chacha;
pub use hex;
pub use chacha20poly1305;
pub use blake3;
pub use argon2;
pub use ring;
pub use ed25519_dalek;
pub use x25519_dalek;
}
with-tokio 功能
#[cfg(feature = "with-tokio")]
pub mod with_tokio {
pub use tokio;
}
with-tracing 功能
#[cfg(feature = "with-tracing")]
pub mod with_tracing {
pub use tracing;
pub use tracing_subscriber;
}
with-logging 功能
#[cfg(feature = "with-logging")]
pub mod with_logging {
pub use env_logger;
pub use log;
}
with-errors 功能
#[cfg(feature = "with-errors")]
pub mod with_errors {
pub use anyhow;
pub use thiserror;
}
with-tests 功能
#[cfg(feature = "with-tests")]
pub mod with_tests {
pub use table_test;
}
with-http-tokio 功能
#[cfg(feature = "with-http-tokio")]
pub mod with_http_tokio {
pub use axum;
pub use hyper;
pub use hyper_util;
pub use tower;
pub use tower_http;
}
with-cryptography 功能
#[cfg(feature = "with-cryptography")]
pub mod with_cryptography {
pub use rand;
pub use rand_chacha;
pub use hex;
pub use chacha20poly1305;
pub use blake3;
pub use argon2;
pub use ring;
pub use sha2;
pub use ed25519_dalek;
pub use x25519_dalek;
}
依赖项
~5–21MB
~348K SLoC