Skip to content

Commit 162441b

Browse files
mdsteeleCobrand
authored andcommitted
Add Hash impls for Point and Rect
1 parent 9cce8ed commit 162441b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/sdl2/rect.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::mem;
66
use std::ptr;
77
use std::ops::{Deref, DerefMut, Add, BitAnd, BitOr, Div, Mul, Neg, Sub};
88
use std::convert::{AsRef, AsMut};
9+
use std::hash::{Hash, Hasher};
910

1011
/// The maximal integer value that can be used for rectangles.
1112
///
@@ -80,6 +81,15 @@ impl PartialEq for Rect {
8081

8182
impl Eq for Rect {}
8283

84+
impl Hash for Rect {
85+
fn hash<H: Hasher>(&self, state: &mut H) {
86+
self.raw.x.hash(state);
87+
self.raw.y.hash(state);
88+
self.raw.w.hash(state);
89+
self.raw.h.hash(state);
90+
}
91+
}
92+
8393
impl Rect {
8494
/// Creates a new rectangle from the given values.
8595
///
@@ -656,6 +666,13 @@ impl PartialEq for Point {
656666

657667
impl Eq for Point {}
658668

669+
impl Hash for Point {
670+
fn hash<H: Hasher>(&self, state: &mut H) {
671+
self.raw.x.hash(state);
672+
self.raw.y.hash(state);
673+
}
674+
}
675+
659676
impl Deref for Point {
660677
type Target = sys::SDL_Point;
661678

@@ -1034,4 +1051,4 @@ mod test {
10341051
Point::new(-11, 5) / 3
10351052
);
10361053
}
1037-
}
1054+
}

0 commit comments

Comments
 (0)