Skip to content

Commit a23ba0d

Browse files
committed
Merge pull request #116 from dpx-infinity/master
Switch to SdlResult
2 parents 1d0d67f + fd596ed commit a23ba0d

File tree

8 files changed

+92
-83
lines changed

8 files changed

+92
-83
lines changed

src/sdl2/audio.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::raw::Slice;
99

1010
use get_error;
1111
use rwops::RWops;
12+
use SdlResult;
1213

1314

1415
#[allow(non_camel_case_types)]
@@ -221,11 +222,11 @@ extern "C" fn c_audio_callback(userdata: *c_void, stream: *uint8_t, len: c_int)
221222

222223

223224
impl<'a> AudioSpec<'a> {
224-
pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec<u8>), String> {
225+
pub fn load_wav(path: &Path) -> SdlResult<(AudioSpec, CVec<u8>)> {
225226
AudioSpec::load_wav_rw(&try!(RWops::from_file(path, "rb")))
226227
}
227228

228-
pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec<u8>), String> {
229+
pub fn load_wav_rw(src: &RWops) -> SdlResult<(AudioSpec, CVec<u8>)> {
229230
assert_eq!(mem::size_of::<AudioSpec>(), mem::size_of::<ll::SDL_AudioSpec>());
230231
let mut spec = unsafe { mem::uninitialized::<AudioSpec>() };
231232
let audio_buf = ptr::null::<u8>();
@@ -261,7 +262,7 @@ impl AudioDevice {
261262
}
262263
}
263264

264-
pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> Result<(AudioDevice, AudioSpec), String> {
265+
pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> SdlResult<(AudioDevice, AudioSpec)> {
265266
//! SDL_OpenAudioDevice
266267
let obtained = unsafe { mem::uninitialized::<AudioSpec>() };
267268
unsafe {
@@ -334,7 +335,7 @@ impl Drop for AudioCVT {
334335

335336
impl AudioCVT {
336337
pub fn new(src_format: AudioFormat, src_channels: u8, src_rate: int,
337-
dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result<AudioCVT, String> {
338+
dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> SdlResult<AudioCVT> {
338339
unsafe {
339340
let c_cvt_p = libc::malloc(mem::size_of::<ll::SDL_AudioCVT>() as size_t) as *mut ll::SDL_AudioCVT;
340341
let ret = ll::SDL_BuildAudioCVT(c_cvt_p,
@@ -348,12 +349,12 @@ impl AudioCVT {
348349
}
349350
}
350351

351-
pub fn convert(&self, src: CVec<u8>) -> Result<CVec<u8>, String> {
352+
pub fn convert(&self, src: CVec<u8>) -> SdlResult<CVec<u8>> {
352353
//! Convert audio data to a desired audio format.
353354
354355
unsafe {
355356
if (*self.raw).needed != 1 {
356-
return Err("no convertion needed!".to_owned())
357+
return Err("no convertion needed!".into_owned())
357358
}
358359
// set len
359360
(*self.raw).len = src.len() as c_int;

src/sdl2/event.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use mouse::{Mouse, MouseState};
2121
use scancode::ScanCode;
2222
use video;
2323
use get_error;
24+
use SdlResult;
2425

2526
#[doc(hidden)]
2627
#[allow(non_camel_case_types)]
@@ -1062,7 +1063,7 @@ pub fn poll_event() -> Event {
10621063
}
10631064

10641065
/// Wait indefinitely for the next available event.
1065-
pub fn wait_event() -> Result<Event, String> {
1066+
pub fn wait_event() -> SdlResult<Event> {
10661067
let raw = null_event();
10671068
let success = unsafe { ll::SDL_WaitEvent(&raw) == 1 as c_int };
10681069

@@ -1071,7 +1072,7 @@ pub fn wait_event() -> Result<Event, String> {
10711072
}
10721073

10731074
/// Wait until the specified timeout (in milliseconds) for the next available event.
1074-
pub fn wait_event_timeout(timeout: int) -> Result<Event, String> {
1075+
pub fn wait_event_timeout(timeout: int) -> SdlResult<Event> {
10751076
let raw = null_event();
10761077
let success = unsafe { ll::SDL_WaitEventTimeout(&raw, timeout as c_int) ==
10771078
1 as c_int };
@@ -1133,15 +1134,15 @@ pub fn register_events(num: int) -> Option<uint> {
11331134
}
11341135

11351136
/// add an event to the event queue
1136-
pub fn push_event(event: Event) -> Result<(), String> {
1137+
pub fn push_event(event: Event) -> SdlResult<()> {
11371138
match event.to_ll() {
11381139
Some(raw_event) => {
11391140
let ok = unsafe { ll::SDL_PushEvent(&raw_event) == 1 };
11401141
if ok { Ok(()) }
11411142
else { Err(get_error()) }
11421143
},
11431144
None => {
1144-
Err("Unsupport event type to push back to queue.".to_owned())
1145+
Err("Unsupport event type to push back to queue.".into_owned())
11451146
}
11461147
}
11471148
}

src/sdl2/mouse.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ptr;
22

33
use get_error;
4+
use SdlResult;
45
use surface;
56
use video;
67

@@ -87,7 +88,7 @@ impl Drop for Cursor {
8788
}
8889

8990
impl Cursor {
90-
pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result<Cursor, String> {
91+
pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> SdlResult<Cursor> {
9192
unsafe {
9293
let raw = ll::SDL_CreateCursor(data.as_ptr(),
9394
mask.as_ptr(),
@@ -103,7 +104,7 @@ impl Cursor {
103104
}
104105

105106
// TODO: figure out how to pass Surface in here correctly
106-
pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> Result<Cursor, String> {
107+
pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> SdlResult<Cursor> {
107108
unsafe {
108109
let raw = ll::SDL_CreateColorCursor(surface.raw(), hot_x as i32,
109110
hot_y as i32);
@@ -116,7 +117,7 @@ impl Cursor {
116117
}
117118
}
118119

119-
pub fn from_system(cursor: SystemCursor) -> Result<Cursor, String> {
120+
pub fn from_system(cursor: SystemCursor) -> SdlResult<Cursor> {
120121
unsafe {
121122
let raw = ll::SDL_CreateSystemCursor(cursor as u32);
122123

0 commit comments

Comments
 (0)