Skip to content

Commit

Permalink
no-std
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Dec 9, 2024
1 parent f79d13d commit b2ac221
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
5 changes: 1 addition & 4 deletions crates/libs/bindgen/src/types/cpp_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,17 @@ impl CppInterface {
}
}
}
#[cfg(feature = "std")]
#cfg
struct #implvtbl_ident<T: #impl_name> (core::marker::PhantomData<T>);
#[cfg(feature = "std")]
#cfg
impl<T: #impl_name> #implvtbl_ident<T> {
const VTABLE: #vtbl_name = #vtbl_name::new::<T>();
}
#[cfg(feature = "std")]
#cfg
impl #name {
pub fn new<'a, T: #impl_name>(this: &'a T) -> windows_core::ScopedInterface<'a, Self> {
let this = windows_core::ScopedHeap { vtable: &#implvtbl_ident::<T>::VTABLE as *const _ as *const _, this: this as *const _ as *const _ };
let this = core::mem::ManuallyDrop::new(Box::new(this));
let this = core::mem::ManuallyDrop::new(windows_core::imp::Box::new(this));
unsafe { windows_core::ScopedInterface::new(core::mem::transmute(&this.vtable)) }
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/types/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Delegate {
invoke,
};
unsafe {
core::mem::transmute(Box::new(com))
core::mem::transmute(windows_core::imp::Box::new(com))
}
}
#invoke
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Delegate {
let remaining = (*this).count.release();

if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}

remaining
Expand Down
5 changes: 4 additions & 1 deletion crates/libs/windows/src/extensions/Foundation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#[cfg(feature = "std")]
pub mod Async;
#[cfg(feature = "std")]
pub mod AsyncReady;
#[cfg(feature = "std")]
pub mod AsyncSpawn;
#[cfg(feature = "Foundation_Collections")]
#[cfg(all(feature = "std", feature = "Foundation_Collections"))]
pub mod Collections;
#[cfg(feature = "Foundation_Numerics")]
pub mod Numerics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ impl Vector2 {
pub fn length_squared(&self) -> f32 {
self.dot(self)
}
#[cfg(feature = "std")]
pub fn length(&self) -> f32 {
self.length_squared().sqrt()
}
#[cfg(feature = "std")]
pub fn distance(&self, value: &Self) -> f32 {
(self - value).length()
}
pub fn distance_squared(&self, value: &Self) -> f32 {
(self - value).length_squared()
}
#[cfg(feature = "std")]
pub fn normalize(&self) -> Self {
self / self.length()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ impl Vector3 {
pub fn length_squared(&self) -> f32 {
self.dot(self)
}
#[cfg(feature = "std")]
pub fn length(&self) -> f32 {
self.length_squared().sqrt()
}
#[cfg(feature = "std")]
pub fn distance(&self, value: &Self) -> f32 {
(self - value).length()
}
pub fn distance_squared(&self, value: &Self) -> f32 {
(self - value).length_squared()
}
#[cfg(feature = "std")]
pub fn normalize(&self) -> Self {
self / self.length()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ impl Vector4 {
pub fn length_squared(&self) -> f32 {
self.dot(self)
}
#[cfg(feature = "std")]
pub fn length(&self) -> f32 {
self.length_squared().sqrt()
}
#[cfg(feature = "std")]
pub fn distance(&self, value: &Self) -> f32 {
(self - value).length()
}
pub fn distance_squared(&self, value: &Self) -> f32 {
(self - value).length_squared()
}
#[cfg(feature = "std")]
pub fn normalize(&self) -> Self {
self / self.length()
}
Expand Down
4 changes: 4 additions & 0 deletions crates/tests/misc/no_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ default-features = false
[dependencies.windows]
path = "../../../libs/windows"
default-features = false
features = [
"Foundation_Collections",
"Win32_Graphics_Direct3D",
]

[lints]
workspace = true

0 comments on commit b2ac221

Please sign in to comment.