Function mutf8::is_valid_mutf8[][src]

pub fn is_valid_mutf8(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 to_mutf8.

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

Examples

Basic usage:

use mutf8::is_valid_mutf8;

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

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

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