Skip to content

Commit

Permalink
Add extra impls for HasRawWindowHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
maroider committed Nov 15, 2021
1 parent dc8ad18 commit 5593f6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## 0.4.0 (?)
## 0.4.1 (?)

* Added an impl of `HasRawWindowHandle` for `&T`, `Rc<T>`, and `Arc<T>`.

## 0.4.0 (2021-11-15)

* **Breaking:** Remove `_do_not_use` tags to use `#[non_exhaustive]` macro
* **Breaking:** `RawWindowHandle` variants are no longer cfg-guarded by platform.
Expand Down
19 changes: 18 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
//! be used along with the struct update syntax to construct it. See each specific struct for
//! examples.

extern crate alloc;

mod android;
mod appkit;
mod redox;
Expand Down Expand Up @@ -52,6 +54,22 @@ pub unsafe trait HasRawWindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle;
}

unsafe impl<'a, T: HasRawWindowHandle> HasRawWindowHandle for &'a T {
fn raw_window_handle(&self) -> RawWindowHandle {
(*self).raw_window_handle()
}
}
unsafe impl<T: HasRawWindowHandle> HasRawWindowHandle for alloc::rc::Rc<T> {
fn raw_window_handle(&self) -> RawWindowHandle {
(**self).raw_window_handle()
}
}
unsafe impl<T: HasRawWindowHandle> HasRawWindowHandle for alloc::sync::Arc<T> {
fn raw_window_handle(&self) -> RawWindowHandle {
(**self).raw_window_handle()
}
}

/// An enum to simply combine the different possible raw window handle variants.
///
/// # Variant Availability
Expand Down Expand Up @@ -130,4 +148,3 @@ pub enum RawWindowHandle {
/// This variant is used on Android targets.
AndroidNdk(AndroidNdkHandle),
}

0 comments on commit 5593f6e

Please sign in to comment.