[![Latest Version]][crates.io] [![Documentation]][docs.rs] ![License] 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 ```rust use maybe_string::MaybeString; // invalid UTF-8 bytes let ms = MaybeString(vec![0, 159, 146, 150]); assert_eq!(&format!("{:?}", ms), "[00, 9f, 92, 96]"); // valid UTF-8 bytes let ms = MaybeString(vec![240, 159, 146, 150]); assert_eq!(&format!("{:?}", ms), "\"💖\""); ``` ## Converting to a string ```rust use maybe_string::MaybeString; // invalid UTF-8 bytes let ms = MaybeString(vec![0, 159, 146, 150]); assert_eq!(ms.into_string(), Err(vec![0, 159, 146, 150])); // valid UTF-8 bytes let ms = MaybeString(vec![240, 159, 146, 150]); assert_eq!(ms.into_string(), Ok("💖".to_string())); ``` [crates.io]: https://crates.io/crates/maybe-string [Latest Version]: https://img.shields.io/crates/v/maybe-string.svg [Documentation]: https://docs.rs/maybe-string/badge.svg [docs.rs]: https://docs.rs/maybe-string [License]: https://img.shields.io/crates/l/maybe-string.svg