staticstr

Crates.iostaticstr
lib.rsstaticstr
version0.0.1
created_at2025-05-25 21:43:36.207239+00
updated_at2025-05-25 21:43:36.207239+00
descriptionA string type that can hold both static and owned strings
homepage
repositoryhttps://github.com/SergeyKasmy/fetcher/crates/static-str
max_upload_size
id1688715
size5,865
Ciren (SergeyKasmy)

documentation

README

staticstr

[StaticStr] - a string type that can handle both static and owned strings.

Overview

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.

Use Cases

  • Configuration values that are usually hardcoded but sometimes need to be generated
  • Message templates with occasional dynamic content
  • Any situation where you frequently use &'static str but occasionally need String

Example

use 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

Commit count: 927

cargo fmt