From 5593f6ee82ee15912da006bf111a099342e406fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20R=C3=B8yset?= Date: Mon, 15 Nov 2021 22:01:38 +0100 Subject: [PATCH] Add extra impls for `HasRawWindowHandle` --- CHANGELOG.md | 6 +++++- src/lib.rs | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e54ca9..49d7f7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog -## 0.4.0 (?) +## 0.4.1 (?) + +* Added an impl of `HasRawWindowHandle` for `&T`, `Rc`, and `Arc`. + +## 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. diff --git a/src/lib.rs b/src/lib.rs index 7c22f3e..2d33c67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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 HasRawWindowHandle for alloc::rc::Rc { + fn raw_window_handle(&self) -> RawWindowHandle { + (**self).raw_window_handle() + } +} +unsafe impl HasRawWindowHandle for alloc::sync::Arc { + fn raw_window_handle(&self) -> RawWindowHandle { + (**self).raw_window_handle() + } +} + /// An enum to simply combine the different possible raw window handle variants. /// /// # Variant Availability @@ -130,4 +148,3 @@ pub enum RawWindowHandle { /// This variant is used on Android targets. AndroidNdk(AndroidNdkHandle), } -