pub struct NtUnicodeString { /* private fields */ }
alloc
only.Expand description
An allocated, owned, and growable variant of UNICODE_STRING
(equivalent of String
).
See the module-level documentation for more details.
Implementations§
Source§impl NtUnicodeString
impl NtUnicodeString
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty NtUnicodeString
.
This operation won’t allocate any buffer. Therefore, length and capacity will both be zero.
Sourcepub fn as_unicode_str_mut(&mut self) -> &mut NtUnicodeStrMut<'static>
pub fn as_unicode_str_mut(&mut self) -> &mut NtUnicodeStrMut<'static>
Returns a mutable NtUnicodeStrMut
reference for this string.
Sourcepub fn try_from_u16(buffer: &[u16]) -> Result<Self>
pub fn try_from_u16(buffer: &[u16]) -> Result<Self>
Creates an NtUnicodeString
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 NtUnicodeString
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: &[u16]) -> Result<Self>
pub fn try_from_u16_until_nul(buffer: &[u16]) -> Result<Self>
Creates an NtUnicodeString
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 NtUnicodeString
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.
Sourcepub fn try_push(&mut self, c: char) -> Result<()>
pub fn try_push(&mut self, c: char) -> Result<()>
Appends the given char
to the end of this string.
Returns an NtStringError::BufferSizeExceedsU16
error if the resulting string would exceed
65532 bytes.
This is due to the fact that a UNICODE_STRING
internally uses a 16-bit field to store the length.
Additionally, this function allocates one more character for NUL termination of the internal
buffer.
See the module-level documentation for the implications of that.
Note that every UTF-16 character consumes 2 or 4 bytes.
Sourcepub fn try_push_str(&mut self, s: &str) -> Result<()>
pub fn try_push_str(&mut self, s: &str) -> Result<()>
Appends the given string slice to the end of this string.
Returns an NtStringError::BufferSizeExceedsU16
error if the resulting string would exceed
65532 bytes.
This is due to the fact that a UNICODE_STRING
internally uses a 16-bit field to store the length.
Additionally, this function allocates one more character for NUL termination of the internal
buffer.
See the module-level documentation for the implications of that.
Note that every UTF-16 character consumes 2 or 4 bytes.
Sourcepub fn try_push_u16(&mut self, buffer: &[u16]) -> Result<()>
pub fn try_push_u16(&mut self, buffer: &[u16]) -> Result<()>
Appends the given u16
string buffer (without a terminating NUL character) to the end of this string.
The string is expected to consist of valid UTF-16 characters.
Returns an NtStringError::BufferSizeExceedsU16
error if the resulting string would exceed
65532 bytes.
This is due to the fact that a UNICODE_STRING
internally uses a 16-bit field to store the length.
Additionally, this function allocates one more character for NUL termination of the internal
buffer.
See the module-level documentation for the implications of that.
Note that every UTF-16 character consumes 2 or 4 bytes.
This function has O(1) complexity.
See try_push_u16_until_nul
or try_push_u16cstr
if you have a NUL-terminated buffer.
Sourcepub fn try_push_u16_until_nul(&mut self, buffer: &[u16]) -> Result<()>
pub fn try_push_u16_until_nul(&mut self, buffer: &[u16]) -> Result<()>
Appends the given u16
string buffer, which contains at least one NUL character,
to the end of this string.
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.
Returns an NtStringError::BufferSizeExceedsU16
error if the resulting string would exceed
65532 bytes.
This is due to the fact that a UNICODE_STRING
internally uses a 16-bit field to store the length.
Additionally, this function allocates one more character for NUL termination of the internal
buffer.
See the module-level documentation for the implications of that.
Note that every UTF-16 character consumes 2 or 4 bytes.
Use try_push_u16
if you have a buffer that is not NUL-terminated.
You can also push a NUL-terminated U16CStr
in O(1) via try_push_u16cstr
.
Sourcepub fn try_push_u16cstr(&mut self, u16cstr: &U16CStr) -> Result<()>
pub fn try_push_u16cstr(&mut self, u16cstr: &U16CStr) -> Result<()>
Appends the given U16CStr
to the end of this string.
Returns an NtStringError::BufferSizeExceedsU16
error if the resulting string would exceed
65532 bytes.
This is due to the fact that a UNICODE_STRING
internally uses a 16-bit field to store the length.
Additionally, this function allocates one more character for NUL termination of the internal
buffer.
See the module-level documentation for the implications of that.
Note that every UTF-16 character consumes 2 or 4 bytes.
This function has O(1) complexity.
Sourcepub fn try_push_u16str(&mut self, u16str: &U16Str) -> Result<()>
pub fn try_push_u16str(&mut self, u16str: &U16Str) -> Result<()>
Appends the given U16Str
to the end of this string.
Returns an NtStringError::BufferSizeExceedsU16
error if the resulting string would exceed
65532 bytes.
This is due to the fact that a UNICODE_STRING
internally uses a 16-bit field to store the length.
Additionally, this function allocates one more character for NUL termination of the internal
buffer.
See the module-level documentation for the implications of that.
Note that every UTF-16 character consumes 2 or 4 bytes.
This function has O(1) complexity.
Sourcepub fn try_reserve(&mut self, additional: u16) -> Result<()>
pub fn try_reserve(&mut self, additional: u16) -> Result<()>
Reserves capacity for additional
bytes more than the current length.
Returns an NtStringError::BufferSizeExceedsU16
error if the resulting capacity would exceed
65535 bytes.
Note that every UTF-16 character consumes 2 or 4 bytes.
Sourcepub fn with_capacity(capacity: u16) -> Self
pub fn with_capacity(capacity: u16) -> Self
Creates an empty NtUnicodeString
with at least the specified capacity.
This will preallocate a buffer with the given capacity.
If the given capacity is 0
, no allocation will occur, and this method is identical to the new
method.
Methods from Deref<Target = NtUnicodeStrMut<'static>>§
Sourcepub fn as_mut_ptr(&mut self) -> *mut Self
pub fn as_mut_ptr(&mut self) -> *mut Self
Returns a *mut NtUnicodeStrMut
pointer
(mainly for non-Rust interfaces that expect a mutable UNICODE_STRING*
).
Sourcepub fn as_mut_slice(&mut self) -> &'a mut [u16]
pub fn as_mut_slice(&mut self) -> &'a mut [u16]
Returns a mutable slice to the raw u16
codepoints of the string.
Sourcepub fn as_mut_u16str(&mut self) -> &'a U16Str
pub fn as_mut_u16str(&mut self) -> &'a U16Str
Sourcepub fn as_unicode_str(&'a self) -> &NtUnicodeStr<'a>
pub fn as_unicode_str(&'a self) -> &NtUnicodeStr<'a>
Returns an immutable NtUnicodeStr
reference for this string.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Truncates this string, removing all contents.
While this means the string will have a length of zero, it does not touch its capacity.
Sourcepub fn pop(&mut self) -> Option<Result<char>>
pub fn pop(&mut self) -> Option<Result<char>>
Removes the last character from the string and returns it.
An NtStringError::UnpairedUtf16Surrogate
error is returned if the last character is an unpaired surrogate.
In that case, the unpaired surrogate codepoint is removed from the string anyway.
None
is returned if this string is empty.
Methods from Deref<Target = 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.
Trait Implementations§
Source§impl Add<&U16CStr> for NtUnicodeString
impl Add<&U16CStr> for NtUnicodeString
Source§impl Add<&U16Str> for NtUnicodeString
impl Add<&U16Str> for NtUnicodeString
Source§impl Add<&str> for NtUnicodeString
impl Add<&str> for NtUnicodeString
Source§impl AddAssign<&U16CStr> for NtUnicodeString
impl AddAssign<&U16CStr> for NtUnicodeString
Source§fn add_assign(&mut self, rhs: &U16CStr)
fn add_assign(&mut self, rhs: &U16CStr)
+=
operation. Read moreSource§impl AddAssign<&U16Str> for NtUnicodeString
impl AddAssign<&U16Str> for NtUnicodeString
Source§fn add_assign(&mut self, rhs: &U16Str)
fn add_assign(&mut self, rhs: &U16Str)
+=
operation. Read moreSource§impl AddAssign<&str> for NtUnicodeString
impl AddAssign<&str> for NtUnicodeString
Source§fn add_assign(&mut self, rhs: &str)
fn add_assign(&mut self, rhs: &str)
+=
operation. Read moreSource§impl Clone for NtUnicodeString
impl Clone for NtUnicodeString
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Creates a copy of this NtUnicodeString
.
This implementation keeps the original capacity.
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for NtUnicodeString
impl Debug for NtUnicodeString
Source§impl Default for NtUnicodeString
impl Default for NtUnicodeString
Source§impl Deref for NtUnicodeString
impl Deref for NtUnicodeString
Source§impl DerefMut for NtUnicodeString
impl DerefMut for NtUnicodeString
Source§impl Display for NtUnicodeString
impl Display for NtUnicodeString
Source§impl Drop for NtUnicodeString
impl Drop for NtUnicodeString
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 From<char> for NtUnicodeString
impl From<char> for NtUnicodeString
Source§impl Ord for NtUnicodeString
impl Ord for NtUnicodeString
Source§impl<'a, 'b> PartialEq<&str> for NtUnicodeString
impl<'a, 'b> PartialEq<&str> for NtUnicodeString
Source§impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeString
impl<'a, 'b> PartialEq<NtUnicodeStr<'a>> for NtUnicodeString
Source§impl<'a, 'b> PartialEq<NtUnicodeStrMut<'a>> for NtUnicodeString
impl<'a, 'b> PartialEq<NtUnicodeStrMut<'a>> for NtUnicodeString
Source§impl<'a, 'b> PartialEq<NtUnicodeString> for &str
impl<'a, 'b> PartialEq<NtUnicodeString> for &str
Source§impl<'a, 'b> PartialEq<NtUnicodeString> for NtUnicodeStr<'a>
impl<'a, 'b> PartialEq<NtUnicodeString> for NtUnicodeStr<'a>
Source§impl<'a, 'b> PartialEq<NtUnicodeString> for NtUnicodeStrMut<'a>
impl<'a, 'b> PartialEq<NtUnicodeString> for NtUnicodeStrMut<'a>
Source§impl<'a, 'b> PartialEq<NtUnicodeString> for str
impl<'a, 'b> PartialEq<NtUnicodeString> for str
Source§impl<'a, 'b> PartialEq<str> for NtUnicodeString
impl<'a, 'b> PartialEq<str> for NtUnicodeString
Source§impl<'a, 'b> PartialEq for NtUnicodeString
impl<'a, 'b> PartialEq for NtUnicodeString
Source§impl<'a, 'b> PartialOrd<&str> for NtUnicodeString
impl<'a, 'b> PartialOrd<&str> for NtUnicodeString
Source§impl<'a, 'b> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeString
impl<'a, 'b> PartialOrd<NtUnicodeStr<'a>> for NtUnicodeString
Source§impl<'a, 'b> PartialOrd<NtUnicodeStrMut<'a>> for NtUnicodeString
impl<'a, 'b> PartialOrd<NtUnicodeStrMut<'a>> for NtUnicodeString
Source§impl<'a, 'b> PartialOrd<NtUnicodeString> for &str
impl<'a, 'b> PartialOrd<NtUnicodeString> for &str
Source§impl<'a, 'b> PartialOrd<NtUnicodeString> for NtUnicodeStr<'a>
impl<'a, 'b> PartialOrd<NtUnicodeString> for NtUnicodeStr<'a>
Source§impl<'a, 'b> PartialOrd<NtUnicodeString> for NtUnicodeStrMut<'a>
impl<'a, 'b> PartialOrd<NtUnicodeString> for NtUnicodeStrMut<'a>
Source§impl<'a, 'b> PartialOrd<NtUnicodeString> for str
impl<'a, 'b> PartialOrd<NtUnicodeString> for str
Source§impl<'a, 'b> PartialOrd<str> for NtUnicodeString
impl<'a, 'b> PartialOrd<str> for NtUnicodeString
Source§impl<'a, 'b> PartialOrd for NtUnicodeString
impl<'a, 'b> PartialOrd for NtUnicodeString
Source§impl<'a> TryExtend<&'a U16CStr> for NtUnicodeString
impl<'a> TryExtend<&'a U16CStr> for NtUnicodeString
Source§type Error = NtStringError
type Error = NtStringError
Source§fn try_extend<I: IntoIterator<Item = &'a U16CStr>>(
&mut self,
iter: I,
) -> Result<()>
fn try_extend<I: IntoIterator<Item = &'a U16CStr>>( &mut self, iter: I, ) -> Result<()>
Source§impl<'a> TryExtend<&'a U16Str> for NtUnicodeString
impl<'a> TryExtend<&'a U16Str> for NtUnicodeString
Source§type Error = NtStringError
type Error = NtStringError
Source§fn try_extend<I: IntoIterator<Item = &'a U16Str>>(
&mut self,
iter: I,
) -> Result<()>
fn try_extend<I: IntoIterator<Item = &'a U16Str>>( &mut self, iter: I, ) -> Result<()>
Source§impl<'a> TryExtend<&'a str> for NtUnicodeString
impl<'a> TryExtend<&'a str> for NtUnicodeString
Source§type Error = NtStringError
type Error = NtStringError
Source§fn try_extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I) -> Result<()>
fn try_extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I) -> Result<()>
Source§impl TryExtend<char> for NtUnicodeString
impl TryExtend<char> for NtUnicodeString
Source§type Error = NtStringError
type Error = NtStringError
Source§fn try_extend<I: IntoIterator<Item = char>>(&mut self, iter: I) -> Result<()>
fn try_extend<I: IntoIterator<Item = char>>(&mut self, iter: I) -> Result<()>
Source§impl TryFrom<&String> for NtUnicodeString
impl TryFrom<&String> for NtUnicodeString
Source§fn try_from(s: &String) -> Result<Self>
fn try_from(s: &String) -> Result<Self>
Converts a String
reference into an owned NtUnicodeString
.
This allocates a buffer of matching size on the heap and NUL-terminates it internally. See the module-level documentation for the implications of that.
Source§type Error = NtStringError
type Error = NtStringError
Source§impl TryFrom<&U16CStr> for NtUnicodeString
impl TryFrom<&U16CStr> for NtUnicodeString
Source§fn try_from(value: &U16CStr) -> Result<Self>
fn try_from(value: &U16CStr) -> Result<Self>
Converts a U16CStr
reference into an owned NtUnicodeString
.
The internal buffer will be NUL-terminated. See the module-level documentation for the implications of that.
Source§type Error = NtStringError
type Error = NtStringError
Source§impl TryFrom<&U16Str> for NtUnicodeString
impl TryFrom<&U16Str> for NtUnicodeString
Source§fn try_from(value: &U16Str) -> Result<Self>
fn try_from(value: &U16Str) -> Result<Self>
Converts a U16Str
reference into an owned NtUnicodeString
.
The internal buffer will NOT be NUL-terminated. See the module-level documentation for the implications of that.
Source§type Error = NtStringError
type Error = NtStringError
Source§impl TryFrom<&str> for NtUnicodeString
impl TryFrom<&str> for NtUnicodeString
Source§fn try_from(s: &str) -> Result<Self>
fn try_from(s: &str) -> Result<Self>
Converts a string slice into an owned NtUnicodeString
.
This allocates a buffer of matching size on the heap and NUL-terminates it internally. See the module-level documentation for the implications of that.
Source§type Error = NtStringError
type Error = NtStringError
Source§impl TryFrom<String> for NtUnicodeString
impl TryFrom<String> for NtUnicodeString
Source§fn try_from(s: String) -> Result<Self>
fn try_from(s: String) -> Result<Self>
Converts a String
into an owned NtUnicodeString
.
This allocates a buffer of matching size on the heap and NUL-terminates it internally. See the module-level documentation for the implications of that.