Crates.io | rocstr |
lib.rs | rocstr |
version | 0.6.1 |
source | src |
created_at | 2024-06-28 22:36:36.958175 |
updated_at | 2024-07-05 13:21:14.511515 |
description | An immutable fixed capacity stack based generic copy string |
homepage | https://github.com/OuiCloud/rocstr |
repository | https://github.com/OuiCloud/rocstr |
max_upload_size | |
id | 1287057 |
size | 78,308 |
Rust OuiCloud Str
An immutable fixed capacity stack based generic copy string.
The RocStr is a string backed by a fixed size array.
It keeps track of its length, and is parameterized by SIZE for the maximum capacity.
SIZE is of type usize but is range limited to u32::MAX; attempting to create RocStr with larger capacity will panic.
cargo install rocstr
pub struct Customer {
id: u32,
first_name: RocStr<64>,
last_name: RocStr<64>,
}
let alice = Customer {id: 1, first_name: "Alice".into(), last_name: "Adams".into()};
let bob = Customer {id: 2, first_name: "Bob".into(), last_name: "Bennett".into()};
let alice_name = alice.first_name + " " + alice.last_name;
let bob_name = bob.first_name + " " + bob.last_name;
assert_eq!(alice_name, "Alice Adams");
assert_eq!(bob_name, "Bob Bennett");
Yet another copy string type for Rust.
But, this one is particularly shaped to ease async programming :
&str
Copy
trait, unlike Rust standard String
, which means fast and implicit copyMore over, it was designed to cover web full stack programming range, from full featured back-end server to WASM front-end.
Library | owned | impl Copy | immut. API | no std | no unsafe | Note |
---|---|---|---|---|---|---|
core::str | ❌ | ❌ | ❌ | ✅ | ➖ | core immutable string |
std::String | ✅ | ❌ | ❌ | ❌ | ➖ | std string |
imstr::ImString | ✅ | ❌ | ❌ | ❌ | ❌ | use Arc<String> under the hood |
smol_str::SmolStr | ✅ | ❌ | ❌ | ✅ | ❌ | rust-analyzer string |
bytestring::ByteString | ✅ | ❌ | ❌ | ✅ | ❌ | actix string |
flexstr::FlexStr | ✅ | ❌ | ❌ | ✅ | ❌ | |
copstr::Str | ✅ | ✅ | ❌ | ❌ | ❌ | |
copystr::sXX | ✅ | ✅ | ❌ | ❌ | ✅ | old impl before const generic |
arraystring::ArrayString | ✅ | ✅ | ❌ | ✅ | ❌ | old impl before const generic |
tinystr::TinyAsciiStr | ✅ | ✅ | ❌ | ✅ | ❌ | ascii only |
arrayvec::ArrayString | ✅ | ✅ | ❌ | ✅ | ❌ | unfortunately, it uses unsafe |
rocstr::RocStr | ✅ | ✅ | ✅ | ✅ | ✅ | this crate |
The target use case is web full stack programming :
The current MSRV is 1.60.
This crate uses #![forbid(unsafe_code)]
to ensure everything is implemented in 100% Safe Rust.
RocStr is built with these features enabled by default:
Optionally, the following dependencies can be enabled:
RocStr supports no_std mode (enabled via default-features = false)
RocStr is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.