From cfbde6073c2bb5219448685ce1065ed5379ae863 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Thu, 26 May 2022 08:37:11 -0700 Subject: [PATCH 1/2] Add `impl AsRef for GraphicsContext`. This will allow code which works with windows generically (such as an event loop which can work with `softbuffer` or another graphics library) to be able to access the underlying window without knowing about `softbuffer` in particular. --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index d179924..081f7a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,6 +109,13 @@ impl GraphicsContext { } } +impl AsRef for GraphicsContext { + /// Equivalent to [`self.window()`](Self::window()). + fn as_ref(&self) -> &W { + self.window() + } +} + trait GraphicsContextImpl { unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16); } From 3529b2054b798d93ced7c425b7ead4bfc0d8fffb Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Tue, 23 Aug 2022 19:00:00 -0700 Subject: [PATCH 2/2] `#[inline]` for the AsRef implementation. This may be redundant since the function is generic and generic functions are, in the current Rust compiler, always inlinable, but it follows the general recommended practice of making trivial accessor functions inlinable. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 081f7a0..b64eeee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,6 +111,7 @@ impl GraphicsContext { impl AsRef for GraphicsContext { /// Equivalent to [`self.window()`](Self::window()). + #[inline] fn as_ref(&self) -> &W { self.window() }