Expand description
A fixed–capacity, null–padded UTF‑8 string type for predictable layout and safe truncation.
FixedStr<N>
always stores exactly N
bytes in a [u8; N]
array.
The visible content is defined as the bytes up to the first null byte (\0
), which is used for
comparisons, hashing, and display.
§Behavior
- Shorter input: Input that is shorter than
N
is null‑padded to fill the buffer. - Longer input: Input that exceeds
N
is safely truncated at the last valid UTF‑8 boundary. - Null byte in input: If a null byte is present in the input, the effective string ends there, and any subsequent bytes are ignored.
§Philosophy
- String-first semantics: The type treats the content as a genuine string rather than merely a raw byte array.
- Lossy by default: Truncation prioritizes preserving valid UTF‑8 over preserving every byte.
- Strict by choice: Methods like
TryFrom
, the builder (FixedStrBuf
), and unsafe functions provide stricter control when needed. - Const-ready: Use
FixedStr::new_const
for compile-time construction, which performs silent truncation.
Also included:
FixedStrBuf<N>
: A builder for incrementally constructingFixedStr
values with boundary-aware methods such astry_push_str()
andpush_str_lossy()
.- Optional integrations for
serde
,binrw
, and support forno_std
environments.
Re-exports§
pub use effective_bytes::EffectiveBytes;
pub use effective_bytes::EffectiveBytesIter;
pub use fs_buffer::FixedStrBuf;
pub use fs_core::FixedStr;
pub use fs_error::FixedStrError;
pub use string_helpers::copy_into_buffer;
pub use string_helpers::dump_as_hex;
pub use string_helpers::fast_format_hex;
pub use string_helpers::find_first_null;
pub use string_helpers::find_valid_boundary;
pub use string_helpers::find_valid_utf8_len;
pub use string_helpers::panic_on_zero;
pub use string_helpers::truncate_utf8_lossy;
pub use string_helpers::BufferCopyMode;
Modules§
- effective_
bytes - Exposes the effective (non‑zero) bytes of a
FixedStr
. - fs_
buffer - Provides the builder type
FixedStrBuf
for constructing fixed‑capacity strings. - fs_core
- Contains the core implementation of the
FixedStr
type. - fs_
error - Defines custom error types for the
FixedStr
library. - fs_impl
- Implements various trait implementations for
FixedStr
. - serialize_
ext - Provides optional integrations for binary and serialization support (
binrw
andserde
). - string_
helpers - Contains helper functions for byte copying, UTF‑8 boundary detection, and hex formatting.