Sunbeam Studios

Our open-source projects, here for you!

tinystr (0.8.2)

Published 2026-03-26 10:35:52 +00:00 by siennathesane

Installation

[registry]
default = "gitea"

[registries.gitea]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add tinystr@0.8.2

About this package

A small ASCII-only bounded length string representation.

tinystr crates.io

tinystr is a utility crate of the ICU4X project.

It includes [TinyAsciiStr], a core API for representing small ASCII-only bounded length strings.

It is optimized for operations on strings of size 8 or smaller. When use cases involve comparison and conversion of strings for lowercase/uppercase/titlecase, or checking numeric/alphabetic/alphanumeric, TinyAsciiStr is the edge performance library.

Examples

use tinystr::TinyAsciiStr;

let s1: TinyAsciiStr<4> = "tEsT".parse().expect("Failed to parse.");

assert_eq!(s1, "tEsT");
assert_eq!(s1.to_ascii_uppercase(), "TEST");
assert_eq!(s1.to_ascii_lowercase(), "test");
assert_eq!(s1.to_ascii_titlecase(), "Test");
assert!(s1.is_ascii_alphanumeric());
assert!(!s1.is_ascii_numeric());

let s2 = TinyAsciiStr::<8>::try_from_raw(*b"New York")
    .expect("Failed to parse.");

assert_eq!(s2, "New York");
assert_eq!(s2.to_ascii_uppercase(), "NEW YORK");
assert_eq!(s2.to_ascii_lowercase(), "new york");
assert_eq!(s2.to_ascii_titlecase(), "New york");
assert!(!s2.is_ascii_alphanumeric());

Details

When strings are of size 8 or smaller, the struct transforms the strings as u32/u64 and uses bitmasking to provide basic string manipulation operations:

  • is_ascii_numeric
  • is_ascii_alphabetic
  • is_ascii_alphanumeric
  • to_ascii_lowercase
  • to_ascii_uppercase
  • to_ascii_titlecase
  • PartialEq

TinyAsciiStr will fall back to u8 character manipulation for strings of length greater than 8.

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Dependencies

ID Version
databake ^0.2.0
displaydoc ^0.2.3
serde_core ^1.0.220
zerovec ^0.11.3
bincode ^1.3.1
postcard ^1.0.3
rand ^0.9
serde_json ^1.0.45
criterion ^0.5.0

Keywords

string str small tiny no_std
Details
Cargo
2026-03-26 10:35:52 +00:00
0
The ICU4X Project Developers
Unicode-3.0
23 KiB
Assets (1)
Versions (1) View all
0.8.2 2026-03-26