From fc093c38b146de5d71c6107d5ce6211428ab41fb Mon Sep 17 00:00:00 2001 From: Greg M Date: Sat, 24 May 2014 13:15:48 -0400 Subject: [PATCH] Update rust, ~str to StrBuf, std lib changes --- src/codegen/branchify.rs | 8 ++--- src/codegen/keycode.rs | 17 ++++----- src/codegen/main.rs | 4 +-- src/codegen/scancode.rs | 17 ++++----- src/sdl2/audio.rs | 18 +++++----- src/sdl2/event.rs | 12 +++---- src/sdl2/keyboard.rs | 4 +-- src/sdl2/mouse.rs | 6 ++-- src/sdl2/render.rs | 78 ++++++++++++++++++++-------------------- src/sdl2/rwops.rs | 4 +-- src/sdl2/sdl.rs | 2 +- src/sdl2/surface.rs | 12 +++---- src/sdl2/version.rs | 2 +- src/sdl2/video.rs | 46 ++++++++++++------------ 14 files changed, 116 insertions(+), 114 deletions(-) diff --git a/src/codegen/branchify.rs b/src/codegen/branchify.rs index cfb7dfd3..1e6e7b1c 100644 --- a/src/codegen/branchify.rs +++ b/src/codegen/branchify.rs @@ -7,7 +7,7 @@ use std::vec::Vec; struct ParseBranch { matches: Vec, - result: Option<~str>, + result: Option, children: Vec, } @@ -112,14 +112,14 @@ pub fn generate_branchified_method( let next_prefix = format!("{}{}", prefix, c as char); wf!("Some(b) if b == '{}' as u8 => match {} \\{", c as char, read_call); for b in branch.children.iter() { - r(writer, b, next_prefix, indent + 1, read_call, end, max_len, valid, unknown); + r(writer, b, next_prefix.as_slice(), indent + 1, read_call, end, max_len, valid, unknown); } match branch.result { Some(ref result) => wf!(" Some(b) if b == SP => return Some({}),", *result), None => wf!(" Some(b) if b == SP => return Some({}),", - unknown.replace("{}", format!("~\"{}\"", next_prefix))), + unknown.replace("{}", format!("~\"{}\"", next_prefix.as_slice()).as_slice())), } - wf!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix); + wf!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix.as_slice()); wf!(" _ => return None,"); wf!("\\},"); } diff --git a/src/codegen/keycode.rs b/src/codegen/keycode.rs index 1897aa9b..f0afb833 100644 --- a/src/codegen/keycode.rs +++ b/src/codegen/keycode.rs @@ -1,4 +1,5 @@ use std::io::{IoResult,Writer}; +use std::path::BytesContainer; use super::get_writer; struct Key { @@ -44,12 +45,12 @@ fn Key(code: uint, ident: &'static str) -> Key { } impl Key { - fn ident(&self) -> ~str { + fn ident(&self) -> StrBuf { self.ident.to_owned() } - fn padded_ident(&self) -> ~str { - self.ident() + " ".repeat(unsafe { longest_ident } - self.ident().len()) + fn padded_ident(&self) -> StrBuf { + self.ident().append(" ".repeat(unsafe { longest_ident } - self.ident().len()).as_slice()) } } @@ -313,7 +314,7 @@ use std::num::ToPrimitive; pub enum KeyCode { ".as_bytes())); for &entry in entries.iter() { - try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).into_bytes())); + try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).container_as_bytes())); } try!(out.write(" @@ -332,7 +333,7 @@ impl KeyCode { match *self { ".as_bytes())); for &entry in entries.iter() { - try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).into_bytes())); + try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).container_as_bytes())); } try!(out.write(" } @@ -346,7 +347,7 @@ impl ToPrimitive for KeyCode { for primitive_type in types.iter() { try!(out.write(format!("fn to_{}(&self) -> Option<{}> \\{ Some(self.code() as {}) - \\}\n", *primitive_type, *primitive_type, *primitive_type).into_bytes())); + \\}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes())); } try!(out.write(" @@ -364,9 +365,9 @@ impl FromPrimitive for KeyCode { try!(out.write(format!(" fn from_{}(n: {}) -> Option \\{ match n \\{ -", *primitive_type, *primitive_type).into_bytes())); +", *primitive_type, *primitive_type).container_as_bytes())); for &entry in entries.iter() { - try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).into_bytes())); + try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).container_as_bytes())); } try!(out.write(" _ => { Some(UnknownKey) } diff --git a/src/codegen/main.rs b/src/codegen/main.rs index e4e1a306..0852efc0 100644 --- a/src/codegen/main.rs +++ b/src/codegen/main.rs @@ -27,12 +27,12 @@ fn main() { Ok(_) => {}, }; - if "keycode.rs" == *args.get(1) { + if "keycode.rs" == args.get(1).as_slice() { match keycode::generate(&output_dir) { Ok(_) => {}, Err(e) => fail!("Could not automatically generate sources for keycodes: {:s}", e.desc), }; - } else if "scancode.rs" == *args.get(1) { + } else if "scancode.rs" == args.get(1).as_slice() { match scancode::generate(&output_dir) { Ok(_) => {}, Err(e) => fail!("Could not automatically generate sources for scancodes: {:s}", e.desc), diff --git a/src/codegen/scancode.rs b/src/codegen/scancode.rs index 93f55bb8..cbb160af 100644 --- a/src/codegen/scancode.rs +++ b/src/codegen/scancode.rs @@ -1,4 +1,5 @@ use std::io::{IoResult,Writer}; +use std::path::BytesContainer; use super::get_writer; struct ScanCode { @@ -43,12 +44,12 @@ fn ScanCode(code: uint, ident: &'static str) -> ScanCode { } impl ScanCode { - fn ident(&self) -> ~str { + fn ident(&self) -> StrBuf { self.ident.to_owned() } - fn padded_ident(&self) -> ~str { - self.ident() + " ".repeat(unsafe { longest_ident } - self.ident().len()) + fn padded_ident(&self) -> StrBuf { + self.ident().append(" ".repeat(unsafe { longest_ident } - self.ident().len()).as_slice()) } } @@ -319,7 +320,7 @@ use std::num::ToPrimitive; pub enum ScanCode { ".as_bytes())); for &entry in entries.iter() { - try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).into_bytes())); + try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).container_as_bytes())); } try!(out.write(" @@ -338,7 +339,7 @@ impl ScanCode { match *self { ".as_bytes())); for &entry in entries.iter() { - try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).into_bytes())); + try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).container_as_bytes())); } try!(out.write(" @@ -355,7 +356,7 @@ impl ToPrimitive for ScanCode { for primitive_type in types.iter() { try!(out.write(format!("fn to_{}(&self) -> Option<{}> \\{ Some(self.code() as {}) - \\}\n", *primitive_type, *primitive_type, *primitive_type).into_bytes())); + \\}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes())); } try!(out.write(" @@ -374,10 +375,10 @@ impl FromPrimitive for ScanCode { try!(out.write(format!(" fn from_{}(n: {}) -> Option \\{ match n \\{ -", *primitive_type, *primitive_type).into_bytes())); +", *primitive_type, *primitive_type).container_as_bytes())); for &entry in entries.iter() { - try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).into_bytes())); + try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).container_as_bytes())); } try!(out.write(" diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 7702f616..0241f159 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -152,7 +152,7 @@ pub fn get_num_audio_drivers() -> int { unsafe { ll::SDL_GetNumAudioDrivers() as int } } -pub fn get_audio_driver(index: int) -> ~str { +pub fn get_audio_driver(index: int) -> StrBuf { unsafe { let buf = ll::SDL_GetAudioDriver(index as c_int); CString::new(buf, false).as_str().unwrap().into_owned() @@ -163,14 +163,14 @@ pub fn get_num_audio_devices(iscapture: int) -> int { unsafe { ll::SDL_GetNumAudioDevices(iscapture as c_int) as int } } -pub fn get_audio_device_name(index: int, iscapture: int) -> ~str { +pub fn get_audio_device_name(index: int, iscapture: int) -> StrBuf { unsafe { let buf = ll::SDL_GetAudioDeviceName(index as c_int, iscapture as c_int); CString::new(buf, false).as_str().unwrap().into_owned() } } -pub fn audio_init(name: &str) -> Result<(), ~str> { +pub fn audio_init(name: &str) -> Result<(), StrBuf> { let ret = name.with_c_str(|buf| { unsafe { ll::SDL_AudioInit(buf) } }); @@ -185,7 +185,7 @@ pub fn audio_quit() { unsafe { ll::SDL_AudioQuit() } } -pub fn get_current_audio_driver() -> ~str { +pub fn get_current_audio_driver() -> StrBuf { unsafe { let buf = ll::SDL_GetCurrentAudioDriver(); CString::new(buf, false).as_str().unwrap().into_owned() @@ -221,11 +221,11 @@ extern "C" fn c_audio_callback(userdata: *c_void, stream: *uint8_t, len: c_int) impl<'a> AudioSpec<'a> { - pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec), ~str> { + pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec), StrBuf> { AudioSpec::load_wav_rw(&try!(RWops::from_file(path, "rb"))) } - pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec), ~str> { + pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec), StrBuf> { assert_eq!(mem::size_of::(), mem::size_of::()); let mut spec = unsafe { mem::uninit::() }; let audio_buf = ptr::null::(); @@ -261,7 +261,7 @@ impl AudioDevice { } } - pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> Result<(AudioDevice, AudioSpec), ~str> { + pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> Result<(AudioDevice, AudioSpec), StrBuf> { //! SDL_OpenAudioDevice let obtained = unsafe { mem::uninit::() }; unsafe { @@ -331,7 +331,7 @@ impl Drop for AudioCVT { impl AudioCVT { pub fn new(src_format: AudioFormat, src_channels: u8, src_rate: int, - dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result { + dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result { unsafe { let c_cvt_p = libc::malloc(mem::size_of::() as size_t) as *mut ll::SDL_AudioCVT; let ret = ll::SDL_BuildAudioCVT(c_cvt_p, @@ -345,7 +345,7 @@ impl AudioCVT { } } - pub fn convert(&self, src: CVec) -> Result, ~str> { + pub fn convert(&self, src: CVec) -> Result, StrBuf> { //! Convert audio data to a desired audio format. unsafe { diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index 465a45ba..b2b99146 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -563,9 +563,9 @@ pub enum Event { KeyDownEvent(uint, video::Window, KeyCode, ScanCode, Mod), KeyUpEvent(uint, video::Window, KeyCode, ScanCode, Mod), /// (timestamp, window, text, start, length) - TextEditingEvent(uint, video::Window, ~str, int, int), + TextEditingEvent(uint, video::Window, StrBuf, int, int), /// (timestamp, window, text) - TextInputEvent(uint, video::Window, ~str), + TextInputEvent(uint, video::Window, StrBuf), /// (timestamp, window, which, [MouseState], x, y, xrel, yrel) MouseMotionEvent(uint, video::Window, uint, MouseState, int, int, @@ -614,7 +614,7 @@ pub enum Event { ClipboardUpdateEvent(uint), /// (timestamp, filename) - DropFileEvent(uint, ~str), + DropFileEvent(uint, StrBuf), /// (timestamp, Window, type, code) UserEvent(uint, video::Window, uint, int), @@ -1062,7 +1062,7 @@ pub fn poll_event() -> Event { } /// Wait indefinitely for the next available event. -pub fn wait_event() -> Result { +pub fn wait_event() -> Result { let raw = null_event(); let success = unsafe { ll::SDL_WaitEvent(&raw) == 1 as c_int }; @@ -1071,7 +1071,7 @@ pub fn wait_event() -> Result { } /// Wait until the specified timeout (in milliseconds) for the next available event. -pub fn wait_event_timeout(timeout: int) -> Result { +pub fn wait_event_timeout(timeout: int) -> Result { let raw = null_event(); let success = unsafe { ll::SDL_WaitEventTimeout(&raw, timeout as c_int) == 1 as c_int }; @@ -1133,7 +1133,7 @@ pub fn register_events(num: int) -> Option { } /// add an event to the event queue -pub fn push_event(event: Event) -> Result<(), ~str> { +pub fn push_event(event: Event) -> Result<(), StrBuf> { match event.to_ll() { Some(raw_event) => { let ok = unsafe { ll::SDL_PushEvent(&raw_event) == 1 }; diff --git a/src/sdl2/keyboard.rs b/src/sdl2/keyboard.rs index 212c38d8..050b097a 100644 --- a/src/sdl2/keyboard.rs +++ b/src/sdl2/keyboard.rs @@ -114,7 +114,7 @@ pub fn get_scancode_from_key(key: KeyCode) -> ScanCode { } } -pub fn get_scancode_name(scancode: ScanCode) -> ~str { +pub fn get_scancode_name(scancode: ScanCode) -> StrBuf { unsafe { str::raw::from_c_str(ll::SDL_GetScancodeName(scancode.code() as u32)) } @@ -128,7 +128,7 @@ pub fn get_scancode_from_name(name: &str) -> ScanCode { } } -pub fn get_key_name(key: KeyCode) -> ~str { +pub fn get_key_name(key: KeyCode) -> StrBuf { unsafe { str::raw::from_c_str(ll::SDL_GetKeyName(key.code())) } diff --git a/src/sdl2/mouse.rs b/src/sdl2/mouse.rs index 7753e1e6..9453a292 100644 --- a/src/sdl2/mouse.rs +++ b/src/sdl2/mouse.rs @@ -87,7 +87,7 @@ impl Drop for Cursor { } impl Cursor { - pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result { + pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result { unsafe { let raw = ll::SDL_CreateCursor(data.as_ptr(), mask.as_ptr(), @@ -103,7 +103,7 @@ impl Cursor { } // TODO: figure out how to pass Surface in here correctly - pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> Result { + pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> Result { unsafe { let raw = ll::SDL_CreateColorCursor(surface.raw, hot_x as i32, hot_y as i32); @@ -116,7 +116,7 @@ impl Cursor { } } - pub fn from_system(cursor: SystemCursor) -> Result { + pub fn from_system(cursor: SystemCursor) -> Result { unsafe { let raw = ll::SDL_CreateSystemCursor(cursor as u32); diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index c9750824..8221c60a 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -158,7 +158,7 @@ bitflags!(flags RendererFlags: u32 { #[deriving(Eq)] pub struct RendererInfo { - pub name: ~str, + pub name: StrBuf, pub flags: RendererFlags, pub texture_formats: Vec, pub max_texture_width: int, @@ -219,7 +219,7 @@ impl Drop for Renderer { } impl Renderer { - pub fn from_window(window: Window, index: RenderDriverIndex, renderer_flags: RendererFlags) -> Result, ~str> { + pub fn from_window(window: Window, index: RenderDriverIndex, renderer_flags: RendererFlags) -> Result, StrBuf> { let index = match index { DriverAuto => -1, DriverIndex(x) => x @@ -236,7 +236,7 @@ impl Renderer { } } - pub fn new_with_window(width: int, height: int, window_flags: video::WindowFlags) -> Result, ~str> { + pub fn new_with_window(width: int, height: int, window_flags: video::WindowFlags) -> Result, StrBuf> { let raw_window: *video::ll::SDL_Window = ptr::null(); let raw_renderer: *ll::SDL_Renderer = ptr::null(); let result = unsafe { ll::SDL_CreateWindowAndRenderer(width as c_int, height as c_int, window_flags.bits(), &raw_window, &raw_renderer) == 0}; @@ -257,7 +257,7 @@ impl Renderer { } impl Renderer { - pub fn from_surface(surface: surface::Surface) -> Result, ~str> { + pub fn from_surface(surface: surface::Surface) -> Result, StrBuf> { let result = unsafe { ll::SDL_CreateSoftwareRenderer(surface.raw) }; if result == ptr::null() { Ok(Renderer { @@ -281,7 +281,7 @@ impl Renderer { mem::replace(&mut self.parent, None).unwrap() } - pub fn set_draw_color(&self, color: pixels::Color) -> Result<(), ~str> { + pub fn set_draw_color(&self, color: pixels::Color) -> Result<(), StrBuf> { let ret = match color { pixels::RGB(r, g, b) => { unsafe { ll::SDL_SetRenderDrawColor(self.raw, r, g, b, 255) } @@ -294,7 +294,7 @@ impl Renderer { else { Err(get_error()) } } - pub fn get_draw_color(&self) -> Result { + pub fn get_draw_color(&self) -> Result { let r: u8 = 0; let g: u8 = 0; let b: u8 = 0; @@ -307,7 +307,7 @@ impl Renderer { } } - pub fn clear(&self) -> Result<(), ~str> { + pub fn clear(&self) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderClear(self.raw) }; if ret == 0 { Ok(()) } else { Err(get_error()) } @@ -317,7 +317,7 @@ impl Renderer { unsafe { ll::SDL_RenderPresent(self.raw) } } - pub fn get_output_size(&self) -> Result<(int, int), ~str> { + pub fn get_output_size(&self) -> Result<(int, int), StrBuf> { let width: c_int = 0; let height: c_int = 0; @@ -330,7 +330,7 @@ impl Renderer { } } - pub fn create_texture(&self, format: pixels::PixelFormatFlag, access: TextureAccess, width: int, height: int) -> Result { + pub fn create_texture(&self, format: pixels::PixelFormatFlag, access: TextureAccess, width: int, height: int) -> Result { let result = unsafe { ll::SDL_CreateTexture(self.raw, format as uint32_t, access as c_int, width as c_int, height as c_int) }; if result == ptr::null() { Err(get_error()) @@ -339,7 +339,7 @@ impl Renderer { } } - pub fn create_texture_from_surface(&self, surface: &surface::Surface) -> Result { + pub fn create_texture_from_surface(&self, surface: &surface::Surface) -> Result { let result = unsafe { ll::SDL_CreateTextureFromSurface(self.raw, surface.raw) }; if result == ptr::null() { Err(get_error()) @@ -352,7 +352,7 @@ impl Renderer { unsafe { ll::SDL_RenderTargetSupported(self.raw) == 1 } } - pub fn set_render_target(&self, texture: Option<&Texture>) -> Result<(), ~str> { + pub fn set_render_target(&self, texture: Option<&Texture>) -> Result<(), StrBuf> { unsafe { let actual_texture = match texture { Some(texture) => mem::transmute(texture.raw), @@ -366,7 +366,7 @@ impl Renderer { } } - pub fn get_render_target(&self) -> Result { + pub fn get_render_target(&self) -> Result { let raw = unsafe { ll::SDL_GetRenderTarget(self.raw) }; if raw == ptr::null() { @@ -379,7 +379,7 @@ impl Renderer { } } - pub fn set_logical_size(&self, width: int, height: int) -> Result<(), ~str> { + pub fn set_logical_size(&self, width: int, height: int) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderSetLogicalSize(self.raw, width as c_int, height as c_int) }; if ret == 0 { Ok(()) } @@ -396,7 +396,7 @@ impl Renderer { (width as int, height as int) } - pub fn set_viewport(&self, rect: &Rect) -> Result<(), ~str> { + pub fn set_viewport(&self, rect: &Rect) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderSetViewport(self.raw, rect) }; if ret == 0 { Ok(()) } @@ -414,7 +414,7 @@ impl Renderer { rect } - pub fn set_clip_rect(&self, rect: &Rect) -> Result<(), ~str> { + pub fn set_clip_rect(&self, rect: &Rect) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderSetClipRect(self.raw, rect) }; if ret == 0 { Ok(()) } @@ -432,7 +432,7 @@ impl Renderer { rect } - pub fn set_scale(&self, scale_x: f64, scale_y: f64) -> Result<(), ~str> { + pub fn set_scale(&self, scale_x: f64, scale_y: f64) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderSetScale(self.raw, scale_x as c_float, scale_y as c_float) }; if ret == 0 { Ok(()) } @@ -446,14 +446,14 @@ impl Renderer { (scale_x as f64, scale_y as f64) } - pub fn draw_point(&self, point: Point) -> Result<(), ~str> { + pub fn draw_point(&self, point: Point) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderDrawPoint(self.raw, point.x, point.y) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn draw_points(&self, points: &[Point]) -> Result<(), ~str> { + pub fn draw_points(&self, points: &[Point]) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderDrawPoints(self.raw, mem::transmute(points.as_ptr()), points.len() as c_int) }; @@ -462,14 +462,14 @@ impl Renderer { else { Err(get_error()) } } - pub fn draw_line(&self, start: Point, end: Point) -> Result<(), ~str> { + pub fn draw_line(&self, start: Point, end: Point) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderDrawLine(self.raw, start.x, start.y, end.x, end.y) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn draw_lines(&self, points: &[Point]) -> Result<(), ~str> { + pub fn draw_lines(&self, points: &[Point]) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderDrawLines(self.raw, mem::transmute(points.as_ptr()), points.len() as c_int) }; @@ -478,14 +478,14 @@ impl Renderer { else { Err(get_error()) } } - pub fn draw_rect(&self, rect: &Rect) -> Result<(), ~str> { + pub fn draw_rect(&self, rect: &Rect) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderDrawRect(self.raw, rect) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn draw_rects(&self, rects: &[Rect]) -> Result<(), ~str> { + pub fn draw_rects(&self, rects: &[Rect]) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderDrawRects(self.raw, mem::transmute(rects.as_ptr()), rects.len() as c_int) }; @@ -494,14 +494,14 @@ impl Renderer { else { Err(get_error()) } } - pub fn fill_rect(&self, rect: &Rect) -> Result<(), ~str> { + pub fn fill_rect(&self, rect: &Rect) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderFillRect(self.raw, rect) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn fill_rects(&self, rects: &[Rect]) -> Result<(), ~str> { + pub fn fill_rects(&self, rects: &[Rect]) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderFillRects(self.raw, mem::transmute(rects.as_ptr()), rects.len() as c_int) }; @@ -510,7 +510,7 @@ impl Renderer { else { Err(get_error()) } } - pub fn copy(&self, texture: &Texture, src: Option, dst: Option) -> Result<(), ~str> { + pub fn copy(&self, texture: &Texture, src: Option, dst: Option) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderCopy( self.raw, @@ -531,7 +531,7 @@ impl Renderer { } //TODO: Check whether RendererFlip is supposed to be combinable - pub fn copy_ex(&self, texture: &Texture, src: Option, dst: Option, angle: f64, center: Option, flip: RendererFlip) -> Result<(), ~str> { + pub fn copy_ex(&self, texture: &Texture, src: Option, dst: Option, angle: f64, center: Option, flip: RendererFlip) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_RenderCopyEx( self.raw, @@ -557,7 +557,7 @@ impl Renderer { else { Err(get_error()) } } - pub fn read_pixels(&self, rect: Option, format: pixels::PixelFormatFlag) -> Result, ~str> { + pub fn read_pixels(&self, rect: Option, format: pixels::PixelFormatFlag) -> Result, StrBuf> { unsafe { let (actual_rect, w, h) = match rect { Some(rect) => (mem::transmute(&rect), rect.w as uint, rect.h as uint), @@ -606,7 +606,7 @@ impl Drop for Texture { impl Texture { - pub fn query(&self) -> Result { + pub fn query(&self) -> Result { let format: uint32_t = 0; let access: c_int = 0; let width: c_int = 0; @@ -625,14 +625,14 @@ impl Texture { } } - pub fn set_color_mod(&self, red: u8, green: u8, blue: u8) -> Result<(), ~str> { + pub fn set_color_mod(&self, red: u8, green: u8, blue: u8) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_SetTextureColorMod(self.raw, red, green, blue) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn get_color_mod(&self) -> Result<(u8, u8, u8), ~str> { + pub fn get_color_mod(&self) -> Result<(u8, u8, u8), StrBuf> { let r = 0; let g = 0; let b = 0; @@ -645,14 +645,14 @@ impl Texture { } } - pub fn set_alpha_mod(&self, alpha: u8) -> Result<(), ~str> { + pub fn set_alpha_mod(&self, alpha: u8) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_SetTextureAlphaMod(self.raw, alpha) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn get_alpha_mod(&self) -> Result { + pub fn get_alpha_mod(&self) -> Result { let alpha = 0; let result = unsafe { ll::SDL_GetTextureAlphaMod(self.raw, &alpha) == 0 }; @@ -663,14 +663,14 @@ impl Texture { } } - pub fn set_blend_mode(&self, blend: BlendMode) -> Result<(), ~str> { + pub fn set_blend_mode(&self, blend: BlendMode) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_SetTextureBlendMode(self.raw, FromPrimitive::from_i64(blend as i64).unwrap()) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn get_blend_mode(&self) -> Result { + pub fn get_blend_mode(&self) -> Result { let blend: i64 = 0; let result = unsafe { ll::SDL_GetTextureBlendMode(self.raw, &FromPrimitive::from_i64(blend as i64).unwrap()) == 0 }; if result { @@ -680,7 +680,7 @@ impl Texture { } } - pub fn update(&self, rect: Option, pixel_data: &[u8], pitch: int) -> Result<(), ~str> { + pub fn update(&self, rect: Option, pixel_data: &[u8], pitch: int) -> Result<(), StrBuf> { let ret = unsafe { let actual_rect = match rect { Some(rect) => mem::transmute(&rect), @@ -694,7 +694,7 @@ impl Texture { else { Err(get_error()) } } - pub fn lock(&self, rect: Option) -> Result, ~str> { + pub fn lock(&self, rect: Option) -> Result, StrBuf> { let q = try!(self.query()); unsafe { let actual_rect = match rect { @@ -718,7 +718,7 @@ impl Texture { unsafe { ll::SDL_UnlockTexture(self.raw) } } - pub fn gl_bind_texture(&self) -> Result<(f64, f64), ~str> { + pub fn gl_bind_texture(&self) -> Result<(f64, f64), StrBuf> { let texw: c_float = 0.0; let texh: c_float = 0.0; @@ -750,7 +750,7 @@ impl Texture { } -pub fn get_num_render_drivers() -> Result { +pub fn get_num_render_drivers() -> Result { let result = unsafe { ll::SDL_GetNumRenderDrivers() }; if result > 0 { Ok(result as int) @@ -759,7 +759,7 @@ pub fn get_num_render_drivers() -> Result { } } -pub fn get_render_driver_info(index: int) -> Result { +pub fn get_render_driver_info(index: int) -> Result { let out = ll::SDL_RendererInfo { name: ptr::null(), flags: 0, diff --git a/src/sdl2/rwops.rs b/src/sdl2/rwops.rs index cf63a00b..412e1529 100644 --- a/src/sdl2/rwops.rs +++ b/src/sdl2/rwops.rs @@ -49,7 +49,7 @@ pub struct RWops { /// A structure that provides an abstract interface to stream I/O. impl RWops { - pub fn from_file(path: &Path, mode: &str) -> Result { + pub fn from_file(path: &Path, mode: &str) -> Result { let raw = unsafe { ll::SDL_RWFromFile(path.to_c_str().unwrap(), mode.to_c_str().unwrap()) }; @@ -57,7 +57,7 @@ impl RWops { else { Ok(RWops{raw: raw, close_on_drop: true}) } } - pub fn from_bytes(buf: &[u8]) -> Result { + pub fn from_bytes(buf: &[u8]) -> Result { let raw = unsafe { ll::SDL_RWFromConstMem(buf.as_ptr() as *c_void, buf.len() as c_int) }; diff --git a/src/sdl2/sdl.rs b/src/sdl2/sdl.rs index 201ef1a1..c03b55d7 100644 --- a/src/sdl2/sdl.rs +++ b/src/sdl2/sdl.rs @@ -111,7 +111,7 @@ pub fn was_inited(flags: InitFlag) -> InitFlag { } } -pub fn get_error() -> ~str { +pub fn get_error() -> StrBuf { unsafe { let cstr = ll::SDL_GetError(); diff --git a/src/sdl2/surface.rs b/src/sdl2/surface.rs index 70d03e14..245de891 100644 --- a/src/sdl2/surface.rs +++ b/src/sdl2/surface.rs @@ -101,7 +101,7 @@ impl Drop for Surface { impl Surface { pub fn new(surface_flags: SurfaceFlag, width: int, height: int, bpp: int, - rmask: u32, gmask: u32, bmask: u32, amask: u32) -> Result { + rmask: u32, gmask: u32, bmask: u32, amask: u32) -> Result { unsafe { let raw = ll::SDL_CreateRGBSurface(surface_flags.bits(), width as c_int, height as c_int, bpp as c_int, rmask, gmask, bmask, amask); @@ -162,7 +162,7 @@ impl Surface { unsafe { ll::SDL_UnlockSurface(self.raw); } } - pub fn from_bmp(path: &Path) -> Result { + pub fn from_bmp(path: &Path) -> Result { let raw = unsafe { ll::SDL_LoadBMP_RW(try!(rwops::RWops::from_file(path, "rb")).raw, 0) }; @@ -171,7 +171,7 @@ impl Surface { else { Ok(Surface{raw: raw, owned: true}) } } - pub fn save_bmp(&self, path: &Path) -> Result<(), ~str> { + pub fn save_bmp(&self, path: &Path) -> Result<(), StrBuf> { let ret = unsafe { ll::SDL_SaveBMP_RW(self.raw, try!(rwops::RWops::from_file(path, "rb")).raw, 0) }; @@ -197,7 +197,7 @@ impl Surface { } } - pub fn set_color_key(&self, enable: bool, color: pixels::Color) -> Result<(), ~str> { + pub fn set_color_key(&self, enable: bool, color: pixels::Color) -> Result<(), StrBuf> { let key = color.to_u32(&self.get_pixel_format()); let result = unsafe { ll::SDL_SetColorKey(self.raw, ::std::bool::to_bit(enable), key) @@ -209,7 +209,7 @@ impl Surface { } } - pub fn get_color_key(&self) -> Result { + pub fn get_color_key(&self) -> Result { let key: u32 = 0; let result = unsafe { ll::SDL_GetColorKey(self.raw, &key) @@ -233,7 +233,7 @@ impl Surface { } } - pub fn get_color_mod(&self) -> Result { + pub fn get_color_mod(&self) -> Result { let r: u8 = 0; let g: u8 = 0; let b: u8 = 0; diff --git a/src/sdl2/version.rs b/src/sdl2/version.rs index ae570447..e5d82191 100644 --- a/src/sdl2/version.rs +++ b/src/sdl2/version.rs @@ -58,7 +58,7 @@ pub fn get_version() -> Version { } /// Get the code revision of SDL that is linked against your program. -pub fn get_revision() -> ~str { +pub fn get_revision() -> StrBuf { unsafe { let ret = ll::SDL_GetRevision(); CString::new(ret, false).as_str().unwrap().into_owned() diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index d7a5a943..f864e2aa 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -330,7 +330,7 @@ impl Drop for Window { } impl Window { - pub fn new(title: &str, x: WindowPos, y: WindowPos, width: int, height: int, window_flags: WindowFlags) -> Result { + pub fn new(title: &str, x: WindowPos, y: WindowPos, width: int, height: int, window_flags: WindowFlags) -> Result { unsafe { let raw = title.with_c_str(|buff| { ll::SDL_CreateWindow( @@ -351,7 +351,7 @@ impl Window { } } - pub fn from_id(id: u32) -> Result { + pub fn from_id(id: u32) -> Result { let raw = unsafe { ll::SDL_GetWindowFromID(id) }; if raw == ptr::null() { Err(get_error()) @@ -360,7 +360,7 @@ impl Window { } } - pub fn get_display_index(&self) -> Result { + pub fn get_display_index(&self) -> Result { let result = unsafe { ll::SDL_GetWindowDisplayIndex(self.raw) }; if result < 0 { return Err(get_error()) @@ -381,7 +381,7 @@ impl Window { } } - pub fn get_display_mode(&self, display_mode: &DisplayMode) -> Result { + pub fn get_display_mode(&self, display_mode: &DisplayMode) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { @@ -419,7 +419,7 @@ impl Window { }) } - pub fn get_title(&self) -> ~str { + pub fn get_title(&self) -> StrBuf { unsafe { let cstr = ll::SDL_GetWindowTitle(self.raw); str::raw::from_c_str(mem::transmute_copy(&cstr)) @@ -509,7 +509,7 @@ impl Window { unsafe { ll::SDL_SetWindowFullscreen(self.raw, fullscreen_type as uint32_t) == 0 } } - pub fn get_surface(&self) -> Result { + pub fn get_surface(&self) -> Result { let raw = unsafe { ll::SDL_GetWindowSurface(self.raw) }; if raw == ptr::null() { @@ -561,7 +561,7 @@ impl Window { } } - pub fn get_gamma_ramp(&self) -> Result<(Vec, Vec, Vec), ~str> { + pub fn get_gamma_ramp(&self) -> Result<(Vec, Vec, Vec), StrBuf> { let red: Vec = Vec::with_capacity(256); let green: Vec = Vec::with_capacity(256); let blue: Vec = Vec::with_capacity(256); @@ -573,7 +573,7 @@ impl Window { } } - pub fn gl_create_context(&self) -> Result { + pub fn gl_create_context(&self) -> Result { let result = unsafe { ll::SDL_GL_CreateContext(self.raw) }; if result == ptr::null() { Err(get_error()) @@ -591,7 +591,7 @@ impl Window { } } -pub fn get_num_video_drivers() -> Result { +pub fn get_num_video_drivers() -> Result { let result = unsafe { ll::SDL_GetNumVideoDrivers() }; if result < 0 { Err(get_error()) @@ -600,7 +600,7 @@ pub fn get_num_video_drivers() -> Result { } } -pub fn get_video_driver(id: int) -> ~str { +pub fn get_video_driver(id: int) -> StrBuf { unsafe { let cstr = ll::SDL_GetVideoDriver(id as c_int); str::raw::from_c_str(mem::transmute_copy(&cstr)) @@ -617,14 +617,14 @@ pub fn video_quit() { unsafe { ll::SDL_VideoQuit() } } -pub fn get_current_video_driver() -> ~str { +pub fn get_current_video_driver() -> StrBuf { unsafe { let cstr = ll::SDL_GetCurrentVideoDriver(); str::raw::from_c_str(mem::transmute_copy(&cstr)) } } -pub fn get_num_video_displays() -> Result { +pub fn get_num_video_displays() -> Result { let result = unsafe { ll::SDL_GetNumVideoDisplays() }; if result < 0 { Err(get_error()) @@ -633,14 +633,14 @@ pub fn get_num_video_displays() -> Result { } } -pub fn get_display_name(display_index: int) -> ~str { +pub fn get_display_name(display_index: int) -> StrBuf { unsafe { let cstr = ll::SDL_GetDisplayName(display_index as c_int); str::raw::from_c_str(mem::transmute_copy(&cstr)) } } -pub fn get_display_bounds(display_index: int) -> Result { +pub fn get_display_bounds(display_index: int) -> Result { let out: Rect = Rect::new(0, 0, 0, 0); let result = unsafe { ll::SDL_GetDisplayBounds(display_index as c_int, &out) == 0 }; @@ -651,7 +651,7 @@ pub fn get_display_bounds(display_index: int) -> Result { } } -pub fn get_num_display_modes(display_index: int) -> Result { +pub fn get_num_display_modes(display_index: int) -> Result { let result = unsafe { ll::SDL_GetNumDisplayModes(display_index as c_int) }; if result < 0 { Err(get_error()) @@ -660,7 +660,7 @@ pub fn get_num_display_modes(display_index: int) -> Result { } } -pub fn get_display_mode(display_index: int, mode_index: int) -> Result { +pub fn get_display_mode(display_index: int, mode_index: int) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { ll::SDL_GetDisplayMode(display_index as c_int, mode_index as c_int, &dm) == 0}; @@ -671,7 +671,7 @@ pub fn get_display_mode(display_index: int, mode_index: int) -> Result Result { +pub fn get_desktop_display_mode(display_index: int) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { ll::SDL_GetDesktopDisplayMode(display_index as c_int, &dm) == 0}; @@ -682,7 +682,7 @@ pub fn get_desktop_display_mode(display_index: int) -> Result } } -pub fn get_current_display_mode(display_index: int) -> Result { +pub fn get_current_display_mode(display_index: int) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { ll::SDL_GetCurrentDisplayMode(display_index as c_int, &dm) == 0}; @@ -693,7 +693,7 @@ pub fn get_current_display_mode(display_index: int) -> Result } } -pub fn get_closest_display_mode(display_index: int, mode: &DisplayMode) -> Result { +pub fn get_closest_display_mode(display_index: int, mode: &DisplayMode) -> Result { let input = mode.to_ll(); let out = empty_sdl_display_mode(); @@ -718,7 +718,7 @@ pub fn disable_screen_saver() { unsafe { ll::SDL_DisableScreenSaver() } } -pub fn gl_load_library(path: &str) -> Result<(), ~str> { +pub fn gl_load_library(path: &str) -> Result<(), StrBuf> { unsafe { path.with_c_str(|path| { if ll::SDL_GL_LoadLibrary(path) == 0 { @@ -752,7 +752,7 @@ pub fn gl_set_attribute(attr: GLAttr, value: int) -> bool { unsafe { ll::SDL_GL_SetAttribute(FromPrimitive::from_u64(attr as u64).unwrap(), value as c_int) == 0 } } -pub fn gl_get_attribute(attr: GLAttr) -> Result { +pub fn gl_get_attribute(attr: GLAttr) -> Result { let out: c_int = 0; let result = unsafe { ll::SDL_GL_GetAttribute(FromPrimitive::from_u64(attr as u64).unwrap(), &out) } == 0; @@ -763,7 +763,7 @@ pub fn gl_get_attribute(attr: GLAttr) -> Result { } } -pub fn gl_get_current_window() -> Result { +pub fn gl_get_current_window() -> Result { let raw = unsafe { ll::SDL_GL_GetCurrentWindow() }; if raw == ptr::null() { Err(get_error()) @@ -772,7 +772,7 @@ pub fn gl_get_current_window() -> Result { } } -pub fn gl_get_current_context() -> Result { +pub fn gl_get_current_context() -> Result { let raw = unsafe { ll::SDL_GL_GetCurrentContext() }; if raw == ptr::null() { Err(get_error())