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

  • no_std version of crate fixedstr: strings of fixed maximum lengths that can be copied and stack-allocated using const generics.
  • 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

Structs

  • 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 Definitions

  • 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.
  • 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.
  • 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.
  • A str32 can hold a string of up to 31 bytes. See docs for zstr
  • A str64 can hold a string of up to 63 bytes. See docs for zstr
  • A str28 can hold a string of up to 127 bytes. See docs for zstr
  • 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.
  • types for small strings