Struct widestring::WideStr [] [src]

pub struct WideStr { /* fields omitted */ }

Wide string reference for WideString.

WideStr is aware of nul values. Strings may or may not be nul-terminated, and may contain invalid and ill-formed UTF-16 data. These strings are intended to be used with FFI functions (such as Windows API) that directly use string length, where the strings are known to have proper nul-termination already, or where strings are merely being passed through without modification.

WideCStr should be used instead of nul-aware strings are required.

WideStr can be converted to many other string types, including OsString and String, making proper Unicode Windows FFI safe and easy.

Methods

impl WideStr
[src]

[src]

Coerces a value into a WideStr.

[src]

Constructs a WideStr from a u16 pointer and a length.

The len argument is the number of u16 elements, not the number of bytes.

Safety

This function is unsafe as there is no guarantee that the given pointer is valid for len elements.

Panics

This function panics if p is null.

Caveat

The lifetime for the returned string is inferred from its usage. To prevent accidental misuse, it's suggested to tie the lifetime to whichever source lifetime is safe in the context, such as by providing a helper function taking the lifetime of a host value for the string, or by explicit annotation.

[src]

Constructs a WideStr from a slice of u16 code points.

No checks are performed on the slice.

[src]

Decodes a wide string to an owned OsString.

This makes a string copy of the WideStr. Since WideStr makes no guarantees that it is valid UTF-16, there is no guarantee that the resulting OsString will be valid data.

Examples

use widestring::WideString;
use std::ffi::OsString;
let s = "MyString";
// Create a wide string from the string
let wstr = WideString::from_str(s);
// Create an OsString from the wide string
let osstr = wstr.to_os_string();

assert_eq!(osstr, OsString::from(s));

[src]

Copies the wide string to a new owned WideString.

[src]

Copies the wide string to a String if it contains valid UTF-16 data.

Failures

Returns an error if the string contains any invalid UTF-16 data.

Examples

use widestring::WideString;
let s = "MyString";
// Create a wide string from the string
let wstr = WideString::from_str(s);
// Create a regular string from the wide string
let s2 = wstr.to_string().unwrap();

assert_eq!(s2, s);

[src]

Copies the wide string to a String.

Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.

Examples

use widestring::WideString;
let s = "MyString";
// Create a wide string from the string
let wstr = WideString::from_str(s);
// Create a regular string from the wide string
let lossy = wstr.to_string_lossy();

assert_eq!(lossy, s);

[src]

Converts to a slice of the wide string.

[src]

Returns a raw pointer to the wide string.

The pointer is valid only as long as the lifetime of this reference.

[src]

Returns the length of the wide string as number of UTF-16 code units (not code points and not number of bytes).

[src]

Returns whether this wide string contains no data.

[src]

Converts a Box<WideStr> into a WideString without copying or allocating.

Trait Implementations

impl Debug for WideStr
[src]

[src]

Formats the value using the given formatter. Read more

impl PartialEq for WideStr
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Eq for WideStr
[src]

impl PartialOrd for WideStr
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for WideStr
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Hash for WideStr
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialEq<WideStr> for WideString
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl PartialOrd<WideStr> for WideString
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> PartialEq<&'a WideStr> for WideString
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a> PartialOrd<&'a WideStr> for WideString
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Borrow<WideStr> for WideString
[src]

[src]

Immutably borrows from an owned value. Read more

impl ToOwned for WideStr
[src]

[src]

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

[src]

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<'a> From<&'a WideStr> for Cow<'a, WideStr>
[src]

[src]

Performs the conversion.

impl AsRef<WideStr> for WideStr
[src]

[src]

Performs the conversion.

impl AsRef<WideStr> for WideString
[src]

[src]

Performs the conversion.

impl AsRef<[u16]> for WideStr
[src]

[src]

Performs the conversion.

impl<'a> From<&'a WideStr> for Box<WideStr>
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl Send for WideStr

impl Sync for WideStr