Struct PotentialUtf8
struct PotentialUtf8(120)
A byte slice that is expected to be a UTF-8 string but does not enforce that invariant.
Use this type instead of str if you don't need to enforce UTF-8 during deserialization. For
example, strings that are keys of a map don't need to ever be reified as strs.
PotentialUtf8 derefs to [u8]. To obtain a str, use [Self::try_as_str()].
The main advantage of this type over [u8] is that it serializes as a string in
human-readable formats like JSON.
Examples
Using an PotentialUtf8 as the key of a ZeroMap:
use PotentialUtf8;
use ZeroMap;
// This map is cheap to deserialize, as we don't need to perform UTF-8 validation.
let map: =
.into_iter
.collect;
let key = "abc";
let value = map.get_copied;
assert_eq!;
Implementations
impl PotentialUtf8
const fn from_bytes(other: &[u8]) -> &SelfCreate a
PotentialUtf8from a byte slice.const fn from_str(s: &str) -> &SelfCreate a
PotentialUtf8from a string slice.const fn as_bytes(self: &Self) -> &[u8]Get the bytes from a [`PotentialUtf8].
fn try_as_str(self: &Self) -> Result<&str, Utf8Error>Attempt to convert a
PotentialUtf8to astr.Examples
use PotentialUtf8; static A: &PotentialUtf8 = from_bytes; let b = A.try_as_str.unwrap; assert_eq!;
impl Debug for PotentialUtf8
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Deref for PotentialUtf8
fn deref(self: &Self) -> &<Self as >::Target
impl Eq for PotentialUtf8
impl Freeze for PotentialUtf8
impl Ord for PotentialUtf8
fn cmp(self: &Self, other: &PotentialUtf8) -> Ordering
impl PartialEq for PotentialUtf8
fn eq(self: &Self, other: &PotentialUtf8) -> bool
impl PartialEq for PotentialUtf8
fn eq(self: &Self, other: &str) -> bool
impl PartialOrd for PotentialUtf8
fn partial_cmp(self: &Self, other: &PotentialUtf8) -> Option<Ordering>
impl PartialOrd for PotentialUtf8
fn partial_cmp(self: &Self, other: &str) -> Option<Ordering>
impl RefUnwindSafe for PotentialUtf8
impl Send for PotentialUtf8
impl Sized for PotentialUtf8
impl StructuralPartialEq for PotentialUtf8
impl Sync for PotentialUtf8
impl Unpin for PotentialUtf8
impl UnsafeUnpin for PotentialUtf8
impl UnwindSafe for PotentialUtf8
impl VarULE for PotentialUtf8
fn validate_bytes(_: &[u8]) -> Result<(), UleError>unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self
impl<P, T> Receiver for PotentialUtf8
impl<T> Any for PotentialUtf8
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for PotentialUtf8
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for PotentialUtf8
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> EncodeAsVarULE for PotentialUtf8
fn encode_var_ule_as_slices<R>(self: &Self, cb: impl FnOnce(&[&[u8]]) -> R) -> R