Provides a newtype wrapper MaybeString
and its slice counterpart MaybeStr
that represents a byte vector that may be a valid UTF-8 string.
These wrappers are useful when working with data that may be a valid UTF-8 string and you want to delay or conditionally skip its conversion to the string.
They are also useful for debugging data that may be displayed as a string.
The Debug
output will provide string representation when the wrapped byte vector is a valid UTF-8 string.
Usage examples
Debugging byte vectors
use MaybeString;
// invalid UTF-8 bytes
let ms = MaybeString;
assert_eq!;
// valid UTF-8 bytes
let ms = MaybeString;
assert_eq!;
Converting to a string
use MaybeString;
// invalid UTF-8 bytes
let ms = MaybeString;
assert_eq!;
// valid UTF-8 bytes
let ms = MaybeString;
assert_eq!;