Skip to content

Commit

Permalink
m: Make sure traits are uniform across WindowHandle and DisplayHandle
Browse files Browse the repository at this point in the history
Make sure both implement Hash, PartialEq, Eq, Copy and Clone.
  • Loading branch information
notgull authored Jun 24, 2023
1 parent def17a3 commit 59d3ad2
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions src/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! These should be 100% safe to pass around and use, no possibility of dangling or invalidity.
use core::fmt;
use core::hash::{Hash, Hasher};
use core::marker::PhantomData;

use crate::{
Expand Down Expand Up @@ -79,7 +78,7 @@ impl<H: HasDisplayHandle + ?Sized> HasDisplayHandle for alloc::sync::Arc<H> {
///
/// Get the underlying raw display handle with the [`HasRawDisplayHandle`] trait.
#[repr(transparent)]
#[derive(PartialEq, Eq, Hash)]
#[derive(PartialEq, Eq, Hash, Copy, Clone)]
pub struct DisplayHandle<'a> {
raw: RawDisplayHandle,
_marker: PhantomData<&'a *const ()>,
Expand All @@ -91,15 +90,6 @@ impl fmt::Debug for DisplayHandle<'_> {
}
}

impl<'a> Clone for DisplayHandle<'a> {
fn clone(&self) -> Self {
Self {
raw: self.raw,
_marker: PhantomData,
}
}
}

impl<'a> DisplayHandle<'a> {
/// Create a `DisplayHandle` from a [`RawDisplayHandle`].
///
Expand All @@ -122,7 +112,7 @@ unsafe impl HasRawDisplayHandle for DisplayHandle<'_> {

impl<'a> HasDisplayHandle for DisplayHandle<'a> {
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
Ok(self.clone())
Ok(*self)
}
}

Expand Down Expand Up @@ -207,7 +197,7 @@ impl<H: HasWindowHandle + ?Sized> HasWindowHandle for alloc::sync::Arc<H> {
///
/// This handle is guaranteed to be safe and valid. Get the underlying raw window handle with the
/// [`HasRawWindowHandle`] trait.
#[derive(Clone)]
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
pub struct WindowHandle<'a> {
raw: RawWindowHandle,
_marker: PhantomData<&'a *const ()>,
Expand All @@ -219,20 +209,6 @@ impl fmt::Debug for WindowHandle<'_> {
}
}

impl PartialEq for WindowHandle<'_> {
fn eq(&self, other: &Self) -> bool {
self.raw == other.raw
}
}

impl Eq for WindowHandle<'_> {}

impl Hash for WindowHandle<'_> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.raw.hash(state);
}
}

impl<'a> WindowHandle<'a> {
/// Borrow a `WindowHandle` from a [`RawWindowHandle`].
///
Expand All @@ -255,7 +231,7 @@ unsafe impl HasRawWindowHandle for WindowHandle<'_> {

impl HasWindowHandle for WindowHandle<'_> {
fn window_handle(&self) -> Result<Self, HandleError> {
Ok(self.clone())
Ok(*self)
}
}

Expand Down

0 comments on commit 59d3ad2

Please sign in to comment.