Struct winsafe::WString [−][src]
pub struct WString { /* fields omitted */ }
Expand description
Stores a Vec<u16>
buffer for a null-terminated
Unicode UTF-16
wide string natively used by Windows.
Performs UTF-8 conversions and can be used as a buffer to low-level Win32 functions.
This is struct is mostly used internally by the library, as a bridge between Windows and Rust strings.
Implementations
Creates and stores a new UTF-16 string from an optional
&str
.
The string will be stored with a terminating null.
If s
is None
, the internal buffer is not allocated.
Creates and stores a new UTF-16 string from an ordinary
&str
.
The string will be stored with a terminating null.
Creates and stores a new UTF-16 string from a
Vec
of ordinary
strings. This new string will be stored as sequential null-separated
strings, terminated with two nulls. That means that further retrieval
operations will “see” only the first string.
This method is intended to pass multi-strings to native APIs, not to retrieve them.
Creates a new UTF-16 string by copying from a buffer, specifying the number of existing chars, not counting a terminating null.
The string will be stored with a terminating null.
Creates a new UTF-16 string by copying from a null-terminated buffer.
The string will be stored with a terminating null.
Creates a new UTF-16 string by copying from a slice.
The string will be stored with a terminating null.
Creates a new UTF-16 buffer allocated with an specific length. All UTF-16 chars will be set to zero.
Returns a
LPCWSTR
const pointer to the internal UTF-16 string buffer, to be passed to
native Win32 functions.
Note: Returns a null pointer if the buffer wasn’t previously
allocated. Make sure the WString
object outlives the function call,
otherwise it will point to an invalid memory location.
Returns a slice to the internal UTF-16 string buffer.
Panics
Panics if the buffer wasn’t previously allocated. Make sure the
WString
object outlives the function call, otherwise it will point to
an invalid memory location.
Returns the size of the allocated internal buffer.
If the buffer was not allocated yet, returns zero.
Copies the content into an external buffer. A terminating null will be appended.
If dest
is smaller, the string will be truncated.
Panics
Panics if dest
has zero length. If length is 1, the buffer will
receive a single null char.
Fills the entire buffer with zero values. The buffer size is not changed.
Tells whether the internal buffer is storing a null string pointer, or if it’s holding a string with a length of zero.
Tells whether the internal buffer is storing a null string pointer.
Resizes the internal buffer, to be used as a buffer for native Win32 functions. All UTF-16 chars will be set to zero.
If the new size is zero, the internal buffer is deallocated.
Note: The internal memory can move after a realloc, so if you’re using a pointer or reference to the internal buffer, they may then point to an invalid memory location. After a realloc, the following methods must be called again:
Converts into
String
. An
internal null pointer will simply be converted into an empty string.
Panics
Panics if any invalid character is found.
If you’re parsing raw data which may contain errors, prefer using
to_string_checked
instead.
Converts into
String
by
calling
String::from_utf16
.
An internal null pointer will simply be converted into an empty string.
This method is useful if you’re parsing raw data which may contain
invalid characters. If you’re dealing with a string known to be valid,
to_string
is more practical.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for WString
impl UnwindSafe for WString
Blanket Implementations
Mutably borrows from an owned value. Read more