mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Merge pull request #536 from icefoxen/master
Added a from_read() method to RWops
This commit is contained in:
+5
-2
@@ -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<Rect>, dst: Option<Rect>) {
|
||||
pub fn copy(&mut self, texture: &Texture, src: Option<Rect>, dst: Option<Rect>)
|
||||
-> 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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T>(r: &mut T, buffer: &'a mut Vec<u8>) -> Result<RWops<'a>, 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.
|
||||
|
||||
Reference in New Issue
Block a user