3 个版本 (1 个稳定版)
1.0.0 | 2023 年 4 月 5 日 |
---|---|
0.1.1 | 2023 年 1 月 5 日 |
0.1.0 | 2022 年 12 月 14 日 |
#787 in 文本处理
每月下载 21 次
145KB
3K SLoC
fast-str
FastStr:针对 map 键优化。
什么是 FastStr
?
FastStr
是一个只读字符串包装器。你可以将其视为一个所有权的 &str
类型。FastStr 使用三种 &str
、Arc<String>
和 StackString
的变体,并自动选择最佳的存储方法;优化字符串克隆和字符串比较。
它是用于什么的?
只要不经常需要修改字符串和连接字符串,FastStr
比字符串更好。
如何使用它?
可以将 String
常量轻松包装到统一的 FastStr
类型中。对于其他字符串类型,将自动选择不同的存储类型。
use fast_str::FastStr;
// compile-time constants
const EMPTY_STR: FastStr = FastStr::new();
const STATIC_STR: FastStr = FastStr::from_static("💙❤");
let str1: FastStr = "🍷 wink".into();
// String storage is used in 32-bit machines,
// and stack memory is used in 64 bit machines to store strings
let str2 = FastStr::from_ref("😆 Happy");
// You can use the operator '+' to connect strings.
let str3: FastStr = str1 + str2;
// O(1) Clone() of time complexity.
let str4: FastStr = str3.clone();
// You can use String as the storage variant of FastStr,
// and when FastStr has the sole ownership of the String variant,
// no performance consumption is converted to the String type.
let from_string = FastStr::from_string(String::from("hello world"));
let from_faststr = String::from(from_string);
特性标志
fast-str
通过 Cargo 特性标志提供了对以下 crate 的可选支持。你可以在 Cargo.toml
文件中启用它们,如下所示
[dependencies]
fast-str = { version = "*", features = ["rocket", "serde"] }
特性 | 描述 |
---|---|
arbitrary |
Arbitrary 实现 FastStr 。 |
actix-web |
Responder 实现 FastStr 。 |
serde |
Serialize 和 Deserialize 实现 FastStr 。 |
diffus |
Same 和 Deserialize 的 FastStr 实现。 |
许可证
根据以下任一许可证授权:
- MIT 许可证 (http://opensource.org/licenses/MIT)
您自行选择。
依赖项
~0–13MB
~129K SLoC