From 3c62e22269a4f97d866b7de1abe37e42998014f0 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Tue, 20 Sep 2016 15:12:31 -0400 Subject: [PATCH 1/2] Added a from_read() method to RWops The ownership is a little squirrelly but this seems the best way. --- src/sdl2/rwops.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sdl2/rwops.rs b/src/sdl2/rwops.rs index f54063a1..b69768f2 100644 --- a/src/sdl2/rwops.rs +++ b/src/sdl2/rwops.rs @@ -59,6 +59,21 @@ impl<'a> RWops<'a> { } } + /// Reads a `Read` object into a buffer and then passes it to `RWops.from_bytes`. + /// + /// The buffer must be provided to this function and must live as long as the + /// `RWops`, but the `RWops` does not take ownership of it. + pub fn from_read(r: &mut T, buffer: &'a mut Vec) -> Result, String> + where T: io::Read + Sized { + match r.read_to_end(buffer) { + Ok(_size) => RWops::from_bytes(buffer), + Err(ioerror) => { + let msg = format!("IO error: {}", ioerror); + Err(msg) + } + } + } + /// Prepares a read-write memory buffer for use with `RWops`. /// /// This method can only fail if the buffer size is zero. From 418fdf2a5be1e6954abd44590d1cf716a6239817 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Mon, 26 Sep 2016 15:59:02 -0400 Subject: [PATCH 2/2] Updated Renderer::copy return type to match Renderer::copy_ex --- src/sdl2/render.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 34b4469c..73e672fb 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -777,7 +777,8 @@ impl<'a> Renderer<'a> { /// # Panics /// Panics if drawing fails for any reason (e.g. driver failure), /// or if the provided texture does not belong to the renderer. - pub fn copy(&mut self, texture: &Texture, src: Option, dst: Option) { + pub fn copy(&mut self, texture: &Texture, src: Option, dst: Option) + -> Result<(), String> { texture.check_renderer(); let ret = unsafe { @@ -796,7 +797,9 @@ impl<'a> Renderer<'a> { }; if ret != 0 { - panic!("Error copying texture: {}", get_error()) + Err(get_error()) + } else { + Ok(()) } }