Merge pull request #114 from gmorenz/update_rust

Update rust, ~str to StrBuf, std lib changes
This commit is contained in:
Tony Aldridge
2014-05-25 11:05:36 +01:00
14 changed files with 116 additions and 114 deletions
+4 -4
View File
@@ -7,7 +7,7 @@ use std::vec::Vec;
struct ParseBranch {
matches: Vec<u8>,
result: Option<~str>,
result: Option<StrBuf>,
children: Vec<ParseBranch>,
}
@@ -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!("\\},");
}
+9 -8
View File
@@ -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<KeyCode> \\{
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) }
+2 -2
View File
@@ -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),
+9 -8
View File
@@ -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<ScanCode> \\{
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("
+9 -9
View File
@@ -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<u8>), ~str> {
pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec<u8>), StrBuf> {
AudioSpec::load_wav_rw(&try!(RWops::from_file(path, "rb")))
}
pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec<u8>), ~str> {
pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec<u8>), StrBuf> {
assert_eq!(mem::size_of::<AudioSpec>(), mem::size_of::<ll::SDL_AudioSpec>());
let mut spec = unsafe { mem::uninit::<AudioSpec>() };
let audio_buf = ptr::null::<u8>();
@@ -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::<AudioSpec>() };
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<AudioCVT, ~str> {
dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result<AudioCVT, StrBuf> {
unsafe {
let c_cvt_p = libc::malloc(mem::size_of::<ll::SDL_AudioCVT>() 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<u8>) -> Result<CVec<u8>, ~str> {
pub fn convert(&self, src: CVec<u8>) -> Result<CVec<u8>, StrBuf> {
//! Convert audio data to a desired audio format.
unsafe {
+6 -6
View File
@@ -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<Event, ~str> {
pub fn wait_event() -> Result<Event, StrBuf> {
let raw = null_event();
let success = unsafe { ll::SDL_WaitEvent(&raw) == 1 as c_int };
@@ -1071,7 +1071,7 @@ pub fn wait_event() -> Result<Event, ~str> {
}
/// Wait until the specified timeout (in milliseconds) for the next available event.
pub fn wait_event_timeout(timeout: int) -> Result<Event, ~str> {
pub fn wait_event_timeout(timeout: int) -> Result<Event, StrBuf> {
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<uint> {
}
/// 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 };
+2 -2
View File
@@ -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()))
}
+3 -3
View File
@@ -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<Cursor, ~str> {
pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result<Cursor, StrBuf> {
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<Cursor, ~str> {
pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> Result<Cursor, StrBuf> {
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<Cursor, ~str> {
pub fn from_system(cursor: SystemCursor) -> Result<Cursor, StrBuf> {
unsafe {
let raw = ll::SDL_CreateSystemCursor(cursor as u32);
+39 -39
View File
@@ -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<pixels::PixelFormatFlag>,
pub max_texture_width: int,
@@ -219,7 +219,7 @@ impl<S> Drop for Renderer<S> {
}
impl Renderer<Window> {
pub fn from_window(window: Window, index: RenderDriverIndex, renderer_flags: RendererFlags) -> Result<Renderer<Window>, ~str> {
pub fn from_window(window: Window, index: RenderDriverIndex, renderer_flags: RendererFlags) -> Result<Renderer<Window>, StrBuf> {
let index = match index {
DriverAuto => -1,
DriverIndex(x) => x
@@ -236,7 +236,7 @@ impl Renderer<Window> {
}
}
pub fn new_with_window(width: int, height: int, window_flags: video::WindowFlags) -> Result<Renderer<Window>, ~str> {
pub fn new_with_window(width: int, height: int, window_flags: video::WindowFlags) -> Result<Renderer<Window>, 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<Window> {
}
impl Renderer<Surface> {
pub fn from_surface(surface: surface::Surface) -> Result<Renderer<Surface>, ~str> {
pub fn from_surface(surface: surface::Surface) -> Result<Renderer<Surface>, StrBuf> {
let result = unsafe { ll::SDL_CreateSoftwareRenderer(surface.raw) };
if result == ptr::null() {
Ok(Renderer {
@@ -281,7 +281,7 @@ impl<S> Renderer<S> {
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<S> Renderer<S> {
else { Err(get_error()) }
}
pub fn get_draw_color(&self) -> Result<pixels::Color, ~str> {
pub fn get_draw_color(&self) -> Result<pixels::Color, StrBuf> {
let r: u8 = 0;
let g: u8 = 0;
let b: u8 = 0;
@@ -307,7 +307,7 @@ impl<S> Renderer<S> {
}
}
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<S> Renderer<S> {
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<S> Renderer<S> {
}
}
pub fn create_texture(&self, format: pixels::PixelFormatFlag, access: TextureAccess, width: int, height: int) -> Result<Texture, ~str> {
pub fn create_texture(&self, format: pixels::PixelFormatFlag, access: TextureAccess, width: int, height: int) -> Result<Texture, StrBuf> {
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<S> Renderer<S> {
}
}
pub fn create_texture_from_surface(&self, surface: &surface::Surface) -> Result<Texture, ~str> {
pub fn create_texture_from_surface(&self, surface: &surface::Surface) -> Result<Texture, StrBuf> {
let result = unsafe { ll::SDL_CreateTextureFromSurface(self.raw, surface.raw) };
if result == ptr::null() {
Err(get_error())
@@ -352,7 +352,7 @@ impl<S> Renderer<S> {
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<S> Renderer<S> {
}
}
pub fn get_render_target(&self) -> Result<Texture, ~str> {
pub fn get_render_target(&self) -> Result<Texture, StrBuf> {
let raw = unsafe { ll::SDL_GetRenderTarget(self.raw) };
if raw == ptr::null() {
@@ -379,7 +379,7 @@ impl<S> Renderer<S> {
}
}
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<S> Renderer<S> {
(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<S> Renderer<S> {
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<S> Renderer<S> {
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<S> Renderer<S> {
(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<S> Renderer<S> {
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<S> Renderer<S> {
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<S> Renderer<S> {
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<S> Renderer<S> {
else { Err(get_error()) }
}
pub fn copy(&self, texture: &Texture, src: Option<Rect>, dst: Option<Rect>) -> Result<(), ~str> {
pub fn copy(&self, texture: &Texture, src: Option<Rect>, dst: Option<Rect>) -> Result<(), StrBuf> {
let ret = unsafe {
ll::SDL_RenderCopy(
self.raw,
@@ -531,7 +531,7 @@ impl<S> Renderer<S> {
}
//TODO: Check whether RendererFlip is supposed to be combinable
pub fn copy_ex(&self, texture: &Texture, src: Option<Rect>, dst: Option<Rect>, angle: f64, center: Option<Point>, flip: RendererFlip) -> Result<(), ~str> {
pub fn copy_ex(&self, texture: &Texture, src: Option<Rect>, dst: Option<Rect>, angle: f64, center: Option<Point>, flip: RendererFlip) -> Result<(), StrBuf> {
let ret = unsafe {
ll::SDL_RenderCopyEx(
self.raw,
@@ -557,7 +557,7 @@ impl<S> Renderer<S> {
else { Err(get_error()) }
}
pub fn read_pixels(&self, rect: Option<Rect>, format: pixels::PixelFormatFlag) -> Result<CVec<u8>, ~str> {
pub fn read_pixels(&self, rect: Option<Rect>, format: pixels::PixelFormatFlag) -> Result<CVec<u8>, 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<TextureQuery, ~str> {
pub fn query(&self) -> Result<TextureQuery, StrBuf> {
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<u8, ~str> {
pub fn get_alpha_mod(&self) -> Result<u8, StrBuf> {
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<BlendMode, ~str> {
pub fn get_blend_mode(&self) -> Result<BlendMode, StrBuf> {
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<Rect>, pixel_data: &[u8], pitch: int) -> Result<(), ~str> {
pub fn update(&self, rect: Option<Rect>, 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<Rect>) -> Result<CVec<u8>, ~str> {
pub fn lock(&self, rect: Option<Rect>) -> Result<CVec<u8>, 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<int, ~str> {
pub fn get_num_render_drivers() -> Result<int, StrBuf> {
let result = unsafe { ll::SDL_GetNumRenderDrivers() };
if result > 0 {
Ok(result as int)
@@ -759,7 +759,7 @@ pub fn get_num_render_drivers() -> Result<int, ~str> {
}
}
pub fn get_render_driver_info(index: int) -> Result<RendererInfo, ~str> {
pub fn get_render_driver_info(index: int) -> Result<RendererInfo, StrBuf> {
let out = ll::SDL_RendererInfo {
name: ptr::null(),
flags: 0,
+2 -2
View File
@@ -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<RWops, ~str> {
pub fn from_file(path: &Path, mode: &str) -> Result<RWops, StrBuf> {
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<RWops, ~str> {
pub fn from_bytes(buf: &[u8]) -> Result<RWops, StrBuf> {
let raw = unsafe {
ll::SDL_RWFromConstMem(buf.as_ptr() as *c_void, buf.len() as c_int)
};
+1 -1
View File
@@ -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();
+6 -6
View File
@@ -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<Surface, ~str> {
rmask: u32, gmask: u32, bmask: u32, amask: u32) -> Result<Surface, StrBuf> {
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<Surface, ~str> {
pub fn from_bmp(path: &Path) -> Result<Surface, StrBuf> {
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<pixels::Color, ~str> {
pub fn get_color_key(&self) -> Result<pixels::Color, StrBuf> {
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<pixels::Color, ~str> {
pub fn get_color_mod(&self) -> Result<pixels::Color, StrBuf> {
let r: u8 = 0;
let g: u8 = 0;
let b: u8 = 0;
+1 -1
View File
@@ -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()
+23 -23
View File
@@ -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<Window, ~str> {
pub fn new(title: &str, x: WindowPos, y: WindowPos, width: int, height: int, window_flags: WindowFlags) -> Result<Window, StrBuf> {
unsafe {
let raw = title.with_c_str(|buff| {
ll::SDL_CreateWindow(
@@ -351,7 +351,7 @@ impl Window {
}
}
pub fn from_id(id: u32) -> Result<Window, ~str> {
pub fn from_id(id: u32) -> Result<Window, StrBuf> {
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<int, ~str> {
pub fn get_display_index(&self) -> Result<int, StrBuf> {
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<DisplayMode, ~str> {
pub fn get_display_mode(&self, display_mode: &DisplayMode) -> Result<DisplayMode, StrBuf> {
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<Surface, ~str> {
pub fn get_surface(&self) -> Result<Surface, StrBuf> {
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<u16>, Vec<u16>, Vec<u16>), ~str> {
pub fn get_gamma_ramp(&self) -> Result<(Vec<u16>, Vec<u16>, Vec<u16>), StrBuf> {
let red: Vec<u16> = Vec::with_capacity(256);
let green: Vec<u16> = Vec::with_capacity(256);
let blue: Vec<u16> = Vec::with_capacity(256);
@@ -573,7 +573,7 @@ impl Window {
}
}
pub fn gl_create_context(&self) -> Result<GLContext, ~str> {
pub fn gl_create_context(&self) -> Result<GLContext, StrBuf> {
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<int, ~str> {
pub fn get_num_video_drivers() -> Result<int, StrBuf> {
let result = unsafe { ll::SDL_GetNumVideoDrivers() };
if result < 0 {
Err(get_error())
@@ -600,7 +600,7 @@ pub fn get_num_video_drivers() -> Result<int, ~str> {
}
}
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<int, ~str> {
pub fn get_num_video_displays() -> Result<int, StrBuf> {
let result = unsafe { ll::SDL_GetNumVideoDisplays() };
if result < 0 {
Err(get_error())
@@ -633,14 +633,14 @@ pub fn get_num_video_displays() -> Result<int, ~str> {
}
}
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<Rect, ~str> {
pub fn get_display_bounds(display_index: int) -> Result<Rect, StrBuf> {
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<Rect, ~str> {
}
}
pub fn get_num_display_modes(display_index: int) -> Result<int, ~str> {
pub fn get_num_display_modes(display_index: int) -> Result<int, StrBuf> {
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<int, ~str> {
}
}
pub fn get_display_mode(display_index: int, mode_index: int) -> Result<DisplayMode, ~str> {
pub fn get_display_mode(display_index: int, mode_index: int) -> Result<DisplayMode, StrBuf> {
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<DisplayMo
}
}
pub fn get_desktop_display_mode(display_index: int) -> Result<DisplayMode, ~str> {
pub fn get_desktop_display_mode(display_index: int) -> Result<DisplayMode, StrBuf> {
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<DisplayMode, ~str>
}
}
pub fn get_current_display_mode(display_index: int) -> Result<DisplayMode, ~str> {
pub fn get_current_display_mode(display_index: int) -> Result<DisplayMode, StrBuf> {
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<DisplayMode, ~str>
}
}
pub fn get_closest_display_mode(display_index: int, mode: &DisplayMode) -> Result<DisplayMode, ~str> {
pub fn get_closest_display_mode(display_index: int, mode: &DisplayMode) -> Result<DisplayMode, StrBuf> {
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<int, ~str> {
pub fn gl_get_attribute(attr: GLAttr) -> Result<int, StrBuf> {
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<int, ~str> {
}
}
pub fn gl_get_current_window() -> Result<Window, ~str> {
pub fn gl_get_current_window() -> Result<Window, StrBuf> {
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<Window, ~str> {
}
}
pub fn gl_get_current_context() -> Result<GLContext, ~str> {
pub fn gl_get_current_context() -> Result<GLContext, StrBuf> {
let raw = unsafe { ll::SDL_GL_GetCurrentContext() };
if raw == ptr::null() {
Err(get_error())