FStr: stack-allocated fixed-length string type
This crate provides a thin wrapper for [u8; N]
to handle a stack-allocated byte array as a
fixed-length, String
-like type through common traits such as Display
, PartialEq
, and
Deref<Target = str>
.
use FStr;
let x = from_inner?;
println!; // "foo"
assert_eq!;
assert_eq!;
assert_eq!;
assert!;
assert!;
let mut y = from_inner?;
assert_eq!;
y.make_ascii_uppercase;
assert_eq!;
const K: = from_str_unwrap;
assert_eq!;
Unlike String
, this type manages fixed-length strings only. The type parameter takes the
exact length (in bytes) of a concrete type, and the concrete type only holds the string values
of that size. Accordingly, this type is useful only when the length is considered an integral
part of a string type.
let s = "Lorem Ipsum ✨";
assert_eq!;
assert!; // just right
assert!; // too small
assert!; // too large
let x: = from_str_unwrap;
let y: = from_str_unwrap;
// This code does not compile because `FStr` of different lengths cannot mix.
if x != y
Crate features
std
(optional; enabled by default) enables the integration withstd
. Disable default features to operate this crate underno_std
environments.serde
(optional) enables the serialization and deserialization ofFStr
throughserde
.
License
Licensed under the Apache License, Version 2.0.