#string #str #small #tiny #no-std

no-std tinystr

A small ASCII-only bounded length string representation

21 releases

Uses new Rust 2021

0.6.1 Aug 4, 2022
0.6.0 May 10, 2022
0.5.0 Feb 10, 2022
0.4.12 Nov 22, 2021
0.3.2 Oct 28, 2019

#25 in Data structures

Download history 19091/week @ 2022-04-22 18595/week @ 2022-04-29 17473/week @ 2022-05-06 17949/week @ 2022-05-13 20942/week @ 2022-05-20 19252/week @ 2022-05-27 20719/week @ 2022-06-03 20173/week @ 2022-06-10 20564/week @ 2022-06-17 23159/week @ 2022-06-24 21463/week @ 2022-07-01 23580/week @ 2022-07-08 25241/week @ 2022-07-15 24290/week @ 2022-07-22 28649/week @ 2022-07-29 23322/week @ 2022-08-05

105,636 downloads per month
Used in 169 crates (24 directly)

Unicode-DFS-2016

390KB
3K SLoC

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_eq!(s1.is_ascii_alphanumeric(), true);
assert_eq!(s1.is_ascii_numeric(), false);

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_eq!(s2.is_ascii_alphanumeric(), false);

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