Crate no_std_strings

Source
Expand description

no_std version of crate fixedstr: strings of fixed maximum lengths that can be copied and stack-allocated using const generics. The types provided by this crate are zstr and tstr. However, tstr is not directly exported and can only be directly referenced through the type aliases str4-str256. Each zstr<N> represents a zero-terminated string of exactly N bytes, accommodating all strings of lengths up to N-1 bytes. A tstr<N> can likewise hold all strings of up to N-1 bytes, but it stores the length of the string in the first byte. Thus the const generic parameter N cannot exceed 256. Since there is still no stable way to contrain N at compile time, the tstr type can only be referenced using the aliases. With few exceptions the tstr type implement the same functions and traits as zstr.

Compared to their counterparts in fixedstr, some functions were omitted to accommodate the #![no_std] requirement.

Optional serde serialization support is enabled by --features serde.

Modules§

tiny_internal 🔒
no_std version of crate fixedstr: strings of fixed maximum lengths that can be copied and stack-allocated using const generics.
zero_terminated 🔒
This module implements the no_std version of zstr, which are zero-terminated strings of fixed maximum lengths.
Type zstr<N> can store strings consisting of up to N-1 bytes Also, it is assumed that the zstr may carray non-textul data and therefore implements some of the traits differently.

Macros§

str_format
creates a formated string of given type (by implementing core::fmt::Write):
try_format
version of str_format! that returns an Option of the given type.

Structs§

zstr
zstr<N>: zero-terminated utf8 strings of size up to N bytes. Note that zstr supports unicode, so that the length of string in characters may be less than N.

Type Aliases§

str4
strings of up to three 8-bit chars, good enough to represent abbreviations such as those for states and airports. Each str<4> is exactly 32 bits.
str8
Types for small strings that use a more efficient representation underneath. A str8 can hold a string of up to 7 bytes (7 ascii chars). The same functions for zstr are provided for these types so the documentation for the other types also applies. The size of str8 is 8 bytes.
str12
str16
A str16 can hold a string of up to 15 bytes. See docs for zstr. The size of str16 is 16 bytes, which is the same as for &str on 64bit systems.
str24
str32
A str32 can hold a string of up to 31 bytes. See docs for zstr
str48
str64
A str64 can hold a string of up to 63 bytes. See docs for zstr
str96
str128
A str28 can hold a string of up to 127 bytes. See docs for zstr
str192
str256
Each type strN is represented underneath by a [u8;N] with N<=256. The first byte of the array always holds the length of the string. Each such type can hold a string of up to N-1 bytes, with max size=255.
In addition, the str4-str128 types implement core::ops::Add, allowing for string concatenation of strings of the same type. For example, two str8 strings will always concatenate to str16, and similarly for all other strN types up to str128.
ztr8
types for small strings
ztr16
ztr32
ztr64