Expand description
§KRNLSTRING
KRNLSTRING
is a Rust crate that provides safe abstractions for working with Windows Unicode strings UNICODE_STRING
.
This crate is designed to be used in #![no_std]
environments, making it suitable for drivers or other low-level
programming where the Rust standard library cannot be used. It leverages the alloc
crate for dynamic memory
management without requiring the full standard library.
§Features
- Safe wrapper for
UNICODE_STRING
that owns its buffer. - Ensures the UTF-16 buffer remains valid as long as the
OwnedUnicodeString
instance exists. - Provides conversion utilities to and from Rust strings (
&str
), as well as Windows string types (PCWSTR
,PWSTR
). - Compatible with
#![no_std]
environments. - Supports concatenation of
OwnedUnicodeString
instances and Rust strings using theAdd
trait. - Enables comparison between
OwnedUnicodeString
instances using thePartialEq
trait.
§Usage Example
use krnlstring::OwnedUnicodeString;
let mut my_string = OwnedUnicodeString::from("Hello, world!");
println!("{}", my_string);
§Performance
KRNLSTRING
is optimized for minimal memory copying and efficient buffer management.
The OwnedUnicodeString
struct directly owns its UTF-16 buffer using a Vec<u16>
, which reduces the need for
unnecessary memory allocations and deallocations.
Unlike other implementations that might require converting the UTF-16 buffer to a Rust String
for display,
which would involve a memory copy, KRNLSTRING
provides a zero-copy formatter. This formatter allows
the OwnedUnicodeString
to be formatted and displayed directly without converting the entire buffer to a String
,
thereby saving both memory and processing time.
When converting from Rust strings (&str
) to OwnedUnicodeString
, the crate encodes the string directly into
UTF-16 format without intermediate copies. Similarly, when converting to Windows string types (PCWSTR
and PWSTR
),
it ensures that the buffer is used as-is, with only necessary modifications to ensure null-termination.
§Safety
This crate aims to provide memory-safe abstractions for working with Windows Unicode strings. All functions and methods ensure that buffers are properly managed to avoid memory safety issues such as dangling pointers or buffer overflows.
Structs§
- Owned
Unicode String - A safe wrapper around Windows
UNICODE_STRING
that owns its UTF-16 buffer.