microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.1k stars 473 forks source link

Add `ToUtf8String` and `ToUtf16String` extensions, as well as `From<String>` trait implementations for `PCSTR` and `PCWSTR`. #3134

Closed ay0ks closed 1 week ago

ay0ks commented 1 week ago

This update adds two extension traits and From<String> implementations for PCSTR/PCWSTR.

use windows::core::{ToUtf8String, ToUtf16String, PCSTR, PCWSTR};

fn main() {
    let source_string = "Hello, World!".to_string();

    let utf8_string = source_string.clone().to_utf8_string();
    let utf16_string = source_string.clone().to_utf16_string();

    // Also
    let utf8_string = PCSTR::from(source_string.clone());
    let utf16_string = PCWSTR::from(source_string.clone());
}
ay0ks commented 1 week ago

@ay0ks please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

kennykerr commented 1 week ago

Please search the issues or create a new issue before opening a PR to avoid wasted effort.

Related: #3105