| Crates.io | staticstr |
| lib.rs | staticstr |
| version | 0.0.1 |
| created_at | 2025-05-25 21:43:36.207239+00 |
| updated_at | 2025-05-25 21:43:36.207239+00 |
| description | A string type that can hold both static and owned strings |
| homepage | |
| repository | https://github.com/SergeyKasmy/fetcher/crates/static-str |
| max_upload_size | |
| id | 1688715 |
| size | 5,865 |
[StaticStr] - a string type that can handle both static and owned strings.
The [StaticStr] type is designed to optimize string handling in scenarios where most strings are static
(known at compile time) but some need to be dynamically generated. It internally uses a Cow to avoid
unnecessary allocations when working with static strings while still maintaining the flexibility to handle
owned strings when needed.
&'static str but occasionally need Stringuse staticstr::StaticStr;
// Use with static strings - no allocation
let static_message: StaticStr = "Hello, World!".into();
// Use with owned strings - allocates only when needed
let dynamic_message: StaticStr = format!("Hello, {}!", "User").into();
// Both types can be used the same way
println!("{}", static_message); // Hello, World!
println!("{}", dynamic_message); // Hello, User!
License: MPL-2.0