Skip to content

Commit

Permalink
block less non-windows usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jun 25, 2024
1 parent 09cbe9a commit c65e7f3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/msrv-windows-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
strategy:
matrix:
rust: [1.70.0, stable, nightly]
runs-on: windows-latest
runs-on:
- windows-latest
- ubuntu-latest
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
38 changes: 19 additions & 19 deletions crates/libs/strings/src/hstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl HSTRING {
}

/// Get the contents of this `HSTRING` as a OsString.
#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
pub fn to_os_string(&self) -> std::ffi::OsString {
std::os::windows::ffi::OsStringExt::from_wide(self.as_wide())
}
Expand Down Expand Up @@ -159,14 +159,14 @@ impl From<&String> for HSTRING {
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl From<&std::path::Path> for HSTRING {
fn from(value: &std::path::Path) -> Self {
value.as_os_str().into()
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl From<&std::ffi::OsStr> for HSTRING {
fn from(value: &std::ffi::OsStr) -> Self {
unsafe {
Expand All @@ -179,14 +179,14 @@ impl From<&std::ffi::OsStr> for HSTRING {
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl From<std::ffi::OsString> for HSTRING {
fn from(value: std::ffi::OsString) -> Self {
value.as_os_str().into()
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl From<&std::ffi::OsString> for HSTRING {
fn from(value: &std::ffi::OsString) -> Self {
value.as_os_str().into()
Expand Down Expand Up @@ -291,28 +291,28 @@ impl PartialEq<&HSTRING> for String {
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<std::ffi::OsString> for HSTRING {
fn eq(&self, other: &std::ffi::OsString) -> bool {
*self == **other
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<std::ffi::OsString> for &HSTRING {
fn eq(&self, other: &std::ffi::OsString) -> bool {
**self == **other
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<&std::ffi::OsString> for HSTRING {
fn eq(&self, other: &&std::ffi::OsString) -> bool {
*self == ***other
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<std::ffi::OsStr> for HSTRING {
fn eq(&self, other: &std::ffi::OsStr) -> bool {
self.as_wide()
Expand All @@ -322,56 +322,56 @@ impl PartialEq<std::ffi::OsStr> for HSTRING {
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<std::ffi::OsStr> for &HSTRING {
fn eq(&self, other: &std::ffi::OsStr) -> bool {
**self == *other
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<&std::ffi::OsStr> for HSTRING {
fn eq(&self, other: &&std::ffi::OsStr) -> bool {
*self == **other
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<HSTRING> for std::ffi::OsStr {
fn eq(&self, other: &HSTRING) -> bool {
*other == *self
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<HSTRING> for &std::ffi::OsStr {
fn eq(&self, other: &HSTRING) -> bool {
*other == **self
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<&HSTRING> for std::ffi::OsStr {
fn eq(&self, other: &&HSTRING) -> bool {
**other == *self
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<HSTRING> for std::ffi::OsString {
fn eq(&self, other: &HSTRING) -> bool {
*other == **self
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<HSTRING> for &std::ffi::OsString {
fn eq(&self, other: &HSTRING) -> bool {
*other == ***self
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl PartialEq<&HSTRING> for std::ffi::OsString {
fn eq(&self, other: &&HSTRING) -> bool {
**other == **self
Expand All @@ -394,14 +394,14 @@ impl TryFrom<HSTRING> for String {
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl<'a> From<&'a HSTRING> for std::ffi::OsString {
fn from(hstring: &HSTRING) -> Self {
hstring.to_os_string()
}
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", windows))]
impl From<HSTRING> for std::ffi::OsString {
fn from(hstring: HSTRING) -> Self {
Self::from(&hstring)
Expand Down
1 change: 0 additions & 1 deletion crates/libs/strings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![cfg(windows)]
#![allow(non_snake_case)]
#![cfg_attr(
windows_debugger_visualizer,
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/linux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ doctest = false

[dependencies.windows-result]
path = "../../libs/result"

[dependencies.windows-core]
path = "../../libs/core"
16 changes: 16 additions & 0 deletions crates/tests/linux/tests/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use windows_core::*;

#[interface("d888acaa-fb67-46a4-bb35-87cb37db5830")]
unsafe trait ITest: IUnknown {}

#[implement(ITest)]
struct Test;

impl ITest_Impl for Test_Impl {}

#[test]
fn test() {
let object = ComObject::new(Test);
let unknown: IUnknown = object.to_interface();
let _test: ITest = unknown.cast().expect("QueryInterface for ITest");
}
File renamed without changes.

0 comments on commit c65e7f3

Please sign in to comment.