Skip to content

Commit

Permalink
Implement the new traits on reference types (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull authored Mar 20, 2023
1 parent f550b4e commit b06ee8d
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions src/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,76 @@ pub trait HasDisplayHandle {
'active: 'this;
}

impl<T: HasDisplayHandle + ?Sized> HasDisplayHandle for &T {
fn active(&self) -> Option<Active<'_>> {
(**self).active()
}

fn display_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> DisplayHandle<'this>
where
'active: 'this,
{
(**self).display_handle(active)
}
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T: HasDisplayHandle + ?Sized> HasDisplayHandle for alloc::boxed::Box<T> {
fn active(&self) -> Option<Active<'_>> {
(**self).active()
}

fn display_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> DisplayHandle<'this>
where
'active: 'this,
{
(**self).display_handle(active)
}
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T: HasDisplayHandle + ?Sized> HasDisplayHandle for alloc::rc::Rc<T> {
fn active(&self) -> Option<Active<'_>> {
(**self).active()
}

fn display_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> DisplayHandle<'this>
where
'active: 'this,
{
(**self).display_handle(active)
}
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T: HasDisplayHandle + ?Sized> HasDisplayHandle for alloc::sync::Arc<T> {
fn active(&self) -> Option<Active<'_>> {
(**self).active()
}

fn display_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> DisplayHandle<'this>
where
'active: 'this,
{
(**self).display_handle(active)
}
}

/// The handle to the display controller of the windowing system.
///
/// Get the underlying raw display handle with the `HasRawDisplayHandle` trait.
Expand Down Expand Up @@ -206,6 +276,60 @@ pub trait HasWindowHandle {
'active: 'this;
}

impl<T: HasWindowHandle + ?Sized> HasWindowHandle for &T {
fn window_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> WindowHandle<'this>
where
'active: 'this,
{
(**self).window_handle(active)
}
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T: HasWindowHandle + ?Sized> HasWindowHandle for alloc::boxed::Box<T> {
fn window_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> WindowHandle<'this>
where
'active: 'this,
{
(**self).window_handle(active)
}
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T: HasWindowHandle + ?Sized> HasWindowHandle for alloc::rc::Rc<T> {
fn window_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> WindowHandle<'this>
where
'active: 'this,
{
(**self).window_handle(active)
}
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T: HasWindowHandle + ?Sized> HasWindowHandle for alloc::sync::Arc<T> {
fn window_handle<'this, 'active>(
&'this self,
active: &'active Active<'_>,
) -> WindowHandle<'this>
where
'active: 'this,
{
(**self).window_handle(active)
}
}

/// The handle to a window.
///
/// This handle is guaranteed to be safe and valid. Get the underlying
Expand Down

0 comments on commit b06ee8d

Please sign in to comment.