Struct nt_string::unicode_string::NtUnicodeStr
source · #[repr(transparent)]pub struct NtUnicodeStr<'a> { /* private fields */ }
Expand description
An immutable reference to a UNICODE_STRING
(equivalent of &str
).
See the module-level documentation for more details.
Implementations§
source§impl<'a> NtUnicodeStr<'a>
impl<'a> NtUnicodeStr<'a>
sourcepub fn as_ptr(&self) -> *const Self
pub fn as_ptr(&self) -> *const Self
Returns a *const NtUnicodeStr
pointer
(mainly for non-Rust interfaces that expect an immutable UNICODE_STRING*
).
sourcepub fn capacity(&self) -> u16
pub fn capacity(&self) -> u16
Returns the capacity (also known as “maximum length”) of this string, in bytes.
sourcepub fn chars(&self) -> Chars<'_> ⓘ
pub fn chars(&self) -> Chars<'_> ⓘ
Returns an iterator over the char
s of this string.
As the string may contain invalid UTF-16 characters (unpaired surrogates), the returned iterator is an
iterator over Result<char>
.
Unpaired surrogates are returned as an NtStringError::UnpairedUtf16Surrogate
error.
If you would like a lossy iterator over char
s directly, use chars_lossy
instead.
sourcepub fn chars_lossy(&self) -> CharsLossy<'_> ⓘ
pub fn chars_lossy(&self) -> CharsLossy<'_> ⓘ
Returns an iterator over the char
s of this string.
Any invalid UTF-16 characters (unpaired surrogates) are automatically replaced by
U+FFFD REPLACEMENT CHARACTER
(�).
If you would like to treat them differently, use chars
instead.
sourcepub const unsafe fn from_raw_parts(
buffer: *const u16,
length: u16,
maximum_length: u16
) -> Self
pub const unsafe fn from_raw_parts( buffer: *const u16, length: u16, maximum_length: u16 ) -> Self
Creates an NtUnicodeStr
from a u16
string buffer, a byte length of the string,
and a buffer capacity in bytes (also known as “maximum length”).
The string is expected to consist of valid UTF-16 characters.
The buffer may or may not be NUL-terminated.
In any case, length
does NOT include the terminating NUL character.
This function is unsafe
and you are advised to use any of the safe try_from_*
functions over this one if possible.
Safety
Behavior is undefined if any of the following conditions are violated:
length
must be less than or equal tomaximum_length
.buffer
must be valid for at leastmaximum_length
bytes.buffer
must point tolength
consecutive properly initialized bytes.buffer
must be valid for the duration of lifetime'a
.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if this string has a length of zero, and false
otherwise.
sourcepub fn len(&self) -> u16
pub fn len(&self) -> u16
Returns the length of this string, in bytes.
Note that a single character may occupy more than one byte. In other words, the returned value might not be what a human considers the length of the string.
sourcepub fn try_from_u16(buffer: &'a [u16]) -> Result<Self>
pub fn try_from_u16(buffer: &'a [u16]) -> Result<Self>
Creates an NtUnicodeStr
from an existing u16
string buffer without a terminating NUL character.
The string is expected to consist of valid UTF-16 characters.
The given buffer becomes the internal buffer of the NtUnicodeStr
and therefore won’t be NUL-terminated.
See the module-level documentation for the implications of that.
This function has O(1) complexity.
If you have a NUL-terminated buffer, either use try_from_u16_until_nul
or convert from a U16CStr
using the corresponding TryFrom
implementation.
sourcepub fn try_from_u16_until_nul(buffer: &'a [u16]) -> Result<Self>
pub fn try_from_u16_until_nul(buffer: &'a [u16]) -> Result<Self>
Creates an NtUnicodeStr
from an existing u16
string buffer that contains at least one NUL character.
The string is expected to consist of valid UTF-16 characters.
The string will be terminated at the NUL character.
An NtStringError::NulNotFound
error is returned if no NUL character could be found.
As a consequence, this function has O(n) complexity.
The resulting internal buffer
of NtUnicodeStr
will be NUL-terminated.
See the module-level documentation for the implications of that.
Use try_from_u16
if you have a buffer that is not NUL-terminated.
You can also convert from a NUL-terminated U16CStr
in O(1) via the corresponding TryFrom
implementation.
Trait Implementations§
source§impl<'a> Clone for NtUnicodeStr<'a>
impl<'a> Clone for NtUnicodeStr<'a>
source§fn clone(&self) -> NtUnicodeStr<'a>
fn clone(&self) -> NtUnicodeStr<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for NtUnicodeStr<'a>
impl<'a> Debug for NtUnicodeStr<'a>
source§impl<'a> Display for NtUnicodeStr<'a>
impl<'a> Display for NtUnicodeStr<'a>
source§impl<'a> From<&NtUnicodeStr<'a>> for NtUnicodeString
impl<'a> From<&NtUnicodeStr<'a>> for NtUnicodeString
source§fn from(unicode_str: &NtUnicodeStr<'_>) -> Self
fn from(unicode_str: &NtUnicodeStr<'_>) -> Self
Creates an NtUnicodeString
from an existing NtUnicodeStr
.
This implementation keeps the original capacity.
source§impl<'a> Ord for NtUnicodeStr<'a>
impl<'a> Ord for NtUnicodeStr<'a>
source§impl<'a> PartialEq<&str> for NtUnicodeStr<'a>
impl<'a> PartialEq<&str> for NtUnicodeStr<'a>
source§impl<'a> PartialEq<NtUnicodeStr<'a>> for &str
impl<'a> PartialEq<NtUnicodeStr<'a>> for &str
source§fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeStr<'b>
impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeStr<'b>
source§impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeStrMut<'b>
impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeStrMut<'b>
source§fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeString
impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeString
source§fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a> PartialEq<NtUnicodeStr<'a>> for str
impl<'a> PartialEq<NtUnicodeStr<'a>> for str
source§fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
fn eq(&self, other: &NtUnicodeStr<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a, 'b> PartialEq<NtUnicodeStrMut<'a>> for NtUnicodeStr<'b>
impl<'a, 'b> PartialEq<NtUnicodeStrMut<'a>> for NtUnicodeStr<'b>
source§fn eq(&self, other: &NtUnicodeStrMut<'a>) -> bool
fn eq(&self, other: &NtUnicodeStrMut<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a, 'b> PartialEq<NtUnicodeString> for NtUnicodeStr<'a>
impl<'a, 'b> PartialEq<NtUnicodeString> for NtUnicodeStr<'a>
source§fn eq(&self, other: &NtUnicodeString) -> bool
fn eq(&self, other: &NtUnicodeString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a> PartialEq<str> for NtUnicodeStr<'a>
impl<'a> PartialEq<str> for NtUnicodeStr<'a>
source§impl<'a> PartialOrd<&str> for NtUnicodeStr<'a>
impl<'a> PartialOrd<&str> for NtUnicodeStr<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<NtUnicodeStr<'a>> for &str
impl<'a> PartialOrd<NtUnicodeStr<'a>> for &str
source§fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeStr<'a>
impl<'a> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeStr<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a, 'b> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeStrMut<'b>
impl<'a, 'b> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeStrMut<'b>
source§fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a, 'b> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeString
impl<'a, 'b> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeString
source§fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<NtUnicodeStr<'a>> for str
impl<'a> PartialOrd<NtUnicodeStr<'a>> for str
source§fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &NtUnicodeStr<'a>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a, 'b> PartialOrd<NtUnicodeStrMut<'a>> for NtUnicodeStr<'b>
impl<'a, 'b> PartialOrd<NtUnicodeStrMut<'a>> for NtUnicodeStr<'b>
source§fn partial_cmp(&self, other: &NtUnicodeStrMut<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &NtUnicodeStrMut<'a>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a, 'b> PartialOrd<NtUnicodeString> for NtUnicodeStr<'a>
impl<'a, 'b> PartialOrd<NtUnicodeString> for NtUnicodeStr<'a>
source§fn partial_cmp(&self, other: &NtUnicodeString) -> Option<Ordering>
fn partial_cmp(&self, other: &NtUnicodeString) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<str> for NtUnicodeStr<'a>
impl<'a> PartialOrd<str> for NtUnicodeStr<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a> TryFrom<&'a U16CStr> for NtUnicodeStr<'a>
impl<'a> TryFrom<&'a U16CStr> for NtUnicodeStr<'a>
source§fn try_from(value: &'a U16CStr) -> Result<Self>
fn try_from(value: &'a U16CStr) -> Result<Self>
Converts a U16CStr
reference into an NtUnicodeStr
.
The internal buffer will be NUL-terminated. See the module-level documentation for the implications of that.
§type Error = NtStringError
type Error = NtStringError
source§impl<'a> TryFrom<&'a U16Str> for NtUnicodeStr<'a>
impl<'a> TryFrom<&'a U16Str> for NtUnicodeStr<'a>
source§fn try_from(value: &'a U16Str) -> Result<Self>
fn try_from(value: &'a U16Str) -> Result<Self>
Converts a U16Str
reference into an NtUnicodeStr
.
The internal buffer will NOT be NUL-terminated. See the module-level documentation for the implications of that.