Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use internal Decode helper in a few more places #1918

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ jobs:
cargo clippy -p test_event &&
cargo clippy -p test_handles &&
cargo clippy -p test_helpers &&
cargo clippy -p test_hstring &&
cargo clippy -p test_identity &&
cargo clippy -p test_implement &&
cargo clippy -p test_interface &&
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ jobs:
cargo test --target ${{ matrix.target }} -p test_event &&
cargo test --target ${{ matrix.target }} -p test_handles &&
cargo test --target ${{ matrix.target }} -p test_helpers &&
cargo test --target ${{ matrix.target }} -p test_hstring &&
cargo test --target ${{ matrix.target }} -p test_identity &&
cargo test --target ${{ matrix.target }} -p test_implement &&
cargo test --target ${{ matrix.target }} -p test_interface &&
Expand Down
6 changes: 1 addition & 5 deletions crates/libs/bindgen/src/replacements/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ pub fn gen() -> TokenStream {
}
impl ::core::fmt::Display for BSTR {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
use ::core::fmt::Write;
for c in ::core::char::decode_utf16(self.as_wide().iter().cloned()) {
f.write_char(c.map_err(|_| ::core::fmt::Error)?)?
}
Ok(())
::core::write!(f, "{}", ::windows::core::Decode(|| ::core::char::decode_utf16(self.as_wide().iter().cloned())))
}
}
impl ::core::fmt::Debug for BSTR {
Expand Down
6 changes: 1 addition & 5 deletions crates/libs/windows/src/Windows/Win32/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,7 @@ impl ::core::default::Default for BSTR {
}
impl ::core::fmt::Display for BSTR {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
use core::fmt::Write;
for c in ::core::char::decode_utf16(self.as_wide().iter().cloned()) {
f.write_char(c.map_err(|_| ::core::fmt::Error)?)?
}
Ok(())
::core::write!(f, "{}", ::windows::core::Decode(|| ::core::char::decode_utf16(self.as_wide().iter().cloned())))
}
}
impl ::core::fmt::Debug for BSTR {
Expand Down
6 changes: 1 addition & 5 deletions crates/libs/windows/src/core/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,11 +1227,7 @@ impl ::core::default::Default for BSTR {
}
impl ::core::fmt::Display for BSTR {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
use core::fmt::Write;
for c in ::core::char::decode_utf16(self.as_wide().iter().cloned()) {
f.write_char(c.map_err(|_| ::core::fmt::Error)?)?
}
Ok(())
::core::write!(f, "{}", ::windows::core::Decode(|| ::core::char::decode_utf16(self.as_wide().iter().cloned())))
}
}
impl ::core::fmt::Debug for BSTR {
Expand Down
6 changes: 1 addition & 5 deletions crates/libs/windows/src/core/strings/hstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ unsafe impl Sync for HSTRING {}

impl core::fmt::Display for HSTRING {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use core::fmt::Write;
for c in core::char::decode_utf16(self.as_wide().iter().cloned()) {
f.write_char(c.unwrap_or(core::char::REPLACEMENT_CHARACTER))?
}
Ok(())
write!(f, "{}", Decode(|| core::char::decode_utf16(self.as_wide().iter().cloned())))
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/libs/windows/src/core/strings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ pub use pwstr::*;
use super::*;

extern "C" {
#[doc(hidden)]
pub fn strlen(s: PCSTR) -> usize;
#[doc(hidden)]
pub fn wcslen(s: PCWSTR) -> usize;
}

/// An internal helper for decoding an iterator of chars and displaying them
struct Decode<F>(F);
#[doc(hidden)]
pub struct Decode<F>(pub F);

impl<F, R, E> core::fmt::Display for Decode<F>
where
Expand Down
7 changes: 7 additions & 0 deletions crates/tests/core/tests/hstrings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ fn display_format() {
assert!(format!("{}", value) == "Hello world");
}

#[test]
fn display_invalid_format() {
let s = HSTRING::from_wide(&[0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0xDD1E, 0x0069, 0x0063, 0xD834]);
let d = format!("{}", s);
assert_eq!(d, "𝄞mus�ic�");
}

#[test]
fn debug_format() {
let value = HSTRING::from("Hello world");
Expand Down
8 changes: 0 additions & 8 deletions crates/tests/hstring/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion crates/tests/hstring/src/lib.rs

This file was deleted.

8 changes: 0 additions & 8 deletions crates/tests/hstring/tests/display.rs

This file was deleted.