pub fn is_valid(s: &str) -> bool
Expand description

Returns true if a string slice contains UTF-8 data that is also valid MUTF-8. This is mainly used in testing if a string slice needs to be explicitly encoded using encode.

If is_valid() returns false, it implies that &str.as_bytes() is directly equivalent to the string slice’s MUTF-8 representation.

Examples

Basic usage:

// Code points below U+10400 encoded in UTF-8 IS valid MUTF-8.
assert!(mutf8::is_valid("Hello, world!"));

// Any code point above U+10400 encoded in UTF-8 IS NOT valid MUTF-8.
assert!(!mutf8::is_valid("\u{10400}"));

// The use of a null character IS NOT valid MUTF-8.
assert!(!mutf8::is_valid("\0"));