Crates.io | faststr |
lib.rs | faststr |
version | 0.2.23 |
source | src |
created_at | 2022-12-05 13:35:02.722398 |
updated_at | 2024-09-05 09:43:15.026462 |
description | Faststr is a string library that reduces the cost of clone. |
homepage | |
repository | https://github.com/volo-rs/faststr |
max_upload_size | |
id | 730328 |
size | 496,016 |
faststr
is a string library that try to avoid the cost of clone.
In Rust, the String type is commonly used, but it has the following problems:
Therefore, we have created the FastStr
type. By sacrificing immutability, we can avoid the overhead of cloning Strings and better integrate with Rust's asynchronous, microservice, and network programming ecosystems.
FastStr
?FastStr
implements From
trait for various types, so you can easily migrate to FastStr
by replacing String
with FastStr
and adding .into()
.
For example, if your API is something like this:
fn need_a_string(s: String)
You may change it to:
fn need_a_string<S: Into<FastStr>>(s: S)
This will not be a break change for users.
serde
: Enable serde support.serde-unsafe
: Enable serde support with utf8 validation disabled.redis
: Enable redis support.redis-unsafe
: Enable redis support with utf8 validation disabled.$ cargo bench
empty faststr time: [2.0188 ns 2.0271 ns 2.0356 ns]
empty string time: [2.1306 ns 2.1333 ns 2.1365 ns]
static faststr time: [2.0458 ns 2.0589 ns 2.0709 ns]
inline faststr time: [2.2270 ns 2.2332 ns 2.2399 ns]
string hello world time: [12.553 ns 12.575 ns 12.597 ns]
512B faststr time: [3.8373 ns 3.8454 ns 3.8540 ns]
512B string time: [36.895 ns 37.007 ns 37.121 ns]
4096B faststr time: [3.8205 ns 3.8260 ns 3.8317 ns]
4096B string time: [55.275 ns 55.355 ns 55.446 ns]
16384B faststr time: [3.8191 ns 3.8246 ns 3.8306 ns]
16384B string time: [338.18 ns 352.36 ns 365.02 ns]
65536B faststr time: [3.8169 ns 3.8221 ns 3.8277 ns]
65536B string time: [662.52 ns 663.75 ns 664.96 ns]
524288B faststr time: [3.8140 ns 3.8178 ns 3.8219 ns]
524288B string time: [6.2681 µs 6.2755 µs 6.2827 µs]
1048576B faststr time: [3.8235 ns 3.8290 ns 3.8348 ns]
1048576B string time: [12.422 µs 12.438 µs 12.453 µs]
empty faststr time: [4.3325 ns 4.3330 ns 4.3335 ns]
empty string time: [4.6413 ns 4.6422 ns 4.6434 ns]
static faststr time: [4.3328 ns 4.3333 ns 4.3339 ns]
inline faststr time: [4.6567 ns 4.6580 ns 4.6593 ns]
string hello world time: [12.897 ns 12.929 ns 12.954 ns]
512B faststr time: [4.4218 ns 4.4253 ns 4.4291 ns]
512B string time: [16.087 ns 16.094 ns 16.105 ns]
4096B faststr time: [4.4066 ns 4.4099 ns 4.4141 ns]
4096B string time: [96.905 ns 97.401 ns 97.879 ns]
16384B faststr time: [4.4150 ns 4.4277 ns 4.4414 ns]
16384B string time: [229.25 ns 229.30 ns 229.34 ns]
65536B faststr time: [4.4562 ns 4.4623 ns 4.4690 ns]
65536B string time: [1.3325 µs 1.3328 µs 1.3332 µs]
524288B faststr time: [4.4167 ns 4.4240 ns 4.4326 ns]
524288B string time: [18.268 µs 18.277 µs 18.287 µs]
1048576B faststr time: [4.4275 ns 4.4385 ns 4.4494 ns]
1048576B string time: [32.839 µs 33.777 µs 34.554 µs]
See CONTRIBUTING.md for more information.
All contributions are welcomed!
faststr
is dual-licensed under the MIT license and the Apache License (Version 2.0).
See LICENSE-MIT and LICENSE-APACHE for details.
faststr
copied and used some code from smol_str
, which is also licensed under the MIT license and the Apache License (Version 2.0).
We really appreciate the work of smol_str
team.
Email: volo@cloudwego.io
How to become a member: COMMUNITY MEMBERSHIP
Issues: Issues
Feishu: Scan the QR code below with Feishu or click this link to join our CloudWeGo Volo user group.