Add DerefMut for Rect on ll::SDL_Rect (#599)

This commit is contained in:
Geordon Worley
2017-02-02 20:25:03 +01:00
committed by Cobrand
parent 6b01841020
commit 79e3abf7de
+15 -1
View File
@@ -4,7 +4,7 @@
use sys::rect as ll;
use std::mem;
use std::ptr;
use std::ops::{Deref, Add, BitAnd, BitOr, Div, Mul, Neg, Sub};
use std::ops::{Deref, DerefMut, Add, BitAnd, BitOr, Div, Mul, Neg, Sub};
use std::convert::{AsRef, AsMut};
/// The maximal integer value that can be used for rectangles.
@@ -439,6 +439,20 @@ impl Deref for Rect {
}
}
impl DerefMut for Rect {
/// # Example
///
/// ```rust
/// use sdl2::rect::Rect;
/// let mut rect = Rect::new(2, 3, 4, 5);
/// rect.x = 60;
/// assert_eq!(60, rect.x);
/// ```
fn deref_mut(&mut self) -> &mut ll::SDL_Rect {
&mut self.raw
}
}
impl Into<(i32, i32, u32, u32)> for Rect {
fn into(self) -> (i32, i32, u32, u32) {
(self.raw.x, self.raw.y, self.raw.w as u32, self.raw.h as u32)