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 LPWSTR mut pointer to the internal UTF-16 string buffer, to be passed to native Win32 functions. This is useful to receive strings.

Panics

Panics if the buffer wasn’t previously allocated. Be sure to alloc enough room, otherwise a buffer overrun may occur.

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 u16 buffer. This is useful to receive strings.

Panics

Panics if the buffer wasn’t previously allocated. Be sure to alloc enough room, otherwise a buffer overrun may occur.

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.

Wrapper to lstrlen.

Returns the number of u16 characters stored in the internal buffer, not counting the terminating null.

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.

Guesses the Encoding of the given data, also returning the size of its BOM, if any.

Guesses the encoding with WString::guess_encoding and parses the data as string.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.