Struct ZString Copy item path Source pub struct ZString { }Available on crate feature alloc only.
Expand description Owning and non-null pointer to zero-terminated textual data.
Because this is a thin pointer it’s suitable for direct FFI usage.
The bytes pointed to should be utf-8 encoded, but the [CharDecoder] used
to convert the bytes to char values is safe to use even when the bytes are
not proper utf-8.
§ Safety
This is repr(transparent) over a NonNull<u8> .
The wrapped pointer points at a sequence of valid-to-read non-zero byte
values followed by at least one zero byte.
The ZString owns the data, and will free it on drop.
Converts a Box<str> into a ZString without any additional
checking.
§ Safety
The data must have exactly one null byte at the end.
The data must not contain interior null bytes.
Breaking either of the above rules will cause the wrong amount to be freed
when the ZString drops.
Borrows this ZString as a ZStr.
Gets the raw pointer to this data.
An iterator over the bytes of this ZStr.
This iterator excludes the terminating 0 byte.
An iterator over the decoded char values of this ZStr.
Clones the value
let zstring1 = ZString::try_from("abc" ).unwrap();
let zstring2 = zstring1.clone();
assert! (zstring1.chars().eq(zstring2.chars()));Performs copy-assignment from
source.
Read more Debug formats with outer " around the string.
let zstring = ZString::try_from("foo" ).unwrap();
let s = format! ("{zstring:?}" );
assert_eq! ("\"foo\"" , s);Display formats the string (without outer ").
let zstring = ZString::try_from("foo" ).unwrap();
let s = format! ("{zstring}" );
assert_eq! ("foo" , s);Executes the destructor for this type.
Read more This is like a “to owned’ style operation.
const FOO: ZStr<'static > = ZStr::from_lit("foo\0" );
let zstring = ZString::from(FOO);
assert_eq! (zstring, FOO);A ZStr equals a &str if the bytes match.
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
A ZString equals a ZStr by calling ZString::as_zstr
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
An ArrayZString<N> equals a ZString when they contain the same bytes.
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
A ZStr equals a ZString by calling ZString::as_zstr
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Two ZString are considered equal if they point at the exact same byte
sequence .
This is much faster to compute when the bytes are valid UTF-8, though it
is stricter if the bytes are not valid UTF-8 (the character replacement
process during decoding could make two different byte sequences have the
same character sequence).
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Compares based on the byte sequence pointed to.
Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Compares based on the byte sequence pointed to.
Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more An ArrayZString<N> compares to a ZString by bytes.
Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Compares based on the byte sequence pointed to.
Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Compares based on the byte sequence pointed to.
Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Formats the wrapped pointer value.
Trims any trailing nulls and then makes a ZString from what’s left.
let zstring1 = ZString::try_from("abc" ).unwrap();
assert! ("abc" .chars().eq(zstring1.chars()));
let zstring2 = ZString::try_from("foo\0\0\0\0" ).unwrap();
assert! ("foo" .chars().eq(zstring2.chars()));§ Failure
If there are any interior nulls.
assert! (ZString::try_from("ab\0c" ).is_err());The type returned in the event of a conversion error.
Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more Converts the given value to a
String.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.