Skip to content

Commit ef7c518

Browse files
committed
Merge pull request #114 from gmorenz/update_rust
Update rust, ~str to StrBuf, std lib changes
2 parents 0cac07f + fc093c3 commit ef7c518

File tree

14 files changed

+116
-114
lines changed

14 files changed

+116
-114
lines changed

src/codegen/branchify.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::vec::Vec;
77

88
struct ParseBranch {
99
matches: Vec<u8>,
10-
result: Option<~str>,
10+
result: Option<StrBuf>,
1111
children: Vec<ParseBranch>,
1212
}
1313

@@ -112,14 +112,14 @@ pub fn generate_branchified_method(
112112
let next_prefix = format!("{}{}", prefix, c as char);
113113
wf!("Some(b) if b == '{}' as u8 => match {} \\{", c as char, read_call);
114114
for b in branch.children.iter() {
115-
r(writer, b, next_prefix, indent + 1, read_call, end, max_len, valid, unknown);
115+
r(writer, b, next_prefix.as_slice(), indent + 1, read_call, end, max_len, valid, unknown);
116116
}
117117
match branch.result {
118118
Some(ref result) => wf!(" Some(b) if b == SP => return Some({}),", *result),
119119
None => wf!(" Some(b) if b == SP => return Some({}),",
120-
unknown.replace("{}", format!("~\"{}\"", next_prefix))),
120+
unknown.replace("{}", format!("~\"{}\"", next_prefix.as_slice()).as_slice())),
121121
}
122-
wf!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix);
122+
wf!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix.as_slice());
123123
wf!(" _ => return None,");
124124
wf!("\\},");
125125
}

src/codegen/keycode.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::io::{IoResult,Writer};
2+
use std::path::BytesContainer;
23
use super::get_writer;
34

45
struct Key {
@@ -44,12 +45,12 @@ fn Key(code: uint, ident: &'static str) -> Key {
4445
}
4546

4647
impl Key {
47-
fn ident(&self) -> ~str {
48+
fn ident(&self) -> StrBuf {
4849
self.ident.to_owned()
4950
}
5051

51-
fn padded_ident(&self) -> ~str {
52-
self.ident() + " ".repeat(unsafe { longest_ident } - self.ident().len())
52+
fn padded_ident(&self) -> StrBuf {
53+
self.ident().append(" ".repeat(unsafe { longest_ident } - self.ident().len()).as_slice())
5354
}
5455

5556
}
@@ -313,7 +314,7 @@ use std::num::ToPrimitive;
313314
pub enum KeyCode {
314315
".as_bytes()));
315316
for &entry in entries.iter() {
316-
try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).into_bytes()));
317+
try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).container_as_bytes()));
317318
}
318319

319320
try!(out.write("
@@ -332,7 +333,7 @@ impl KeyCode {
332333
match *self {
333334
".as_bytes()));
334335
for &entry in entries.iter() {
335-
try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).into_bytes()));
336+
try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).container_as_bytes()));
336337
}
337338
try!(out.write("
338339
}
@@ -346,7 +347,7 @@ impl ToPrimitive for KeyCode {
346347
for primitive_type in types.iter() {
347348
try!(out.write(format!("fn to_{}(&self) -> Option<{}> \\{
348349
Some(self.code() as {})
349-
\\}\n", *primitive_type, *primitive_type, *primitive_type).into_bytes()));
350+
\\}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes()));
350351
}
351352

352353
try!(out.write("
@@ -364,9 +365,9 @@ impl FromPrimitive for KeyCode {
364365
try!(out.write(format!("
365366
fn from_{}(n: {}) -> Option<KeyCode> \\{
366367
match n \\{
367-
", *primitive_type, *primitive_type).into_bytes()));
368+
", *primitive_type, *primitive_type).container_as_bytes()));
368369
for &entry in entries.iter() {
369-
try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).into_bytes()));
370+
try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).container_as_bytes()));
370371
}
371372
try!(out.write("
372373
_ => { Some(UnknownKey) }

src/codegen/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ fn main() {
2727
Ok(_) => {},
2828
};
2929

30-
if "keycode.rs" == *args.get(1) {
30+
if "keycode.rs" == args.get(1).as_slice() {
3131
match keycode::generate(&output_dir) {
3232
Ok(_) => {},
3333
Err(e) => fail!("Could not automatically generate sources for keycodes: {:s}", e.desc),
3434
};
35-
} else if "scancode.rs" == *args.get(1) {
35+
} else if "scancode.rs" == args.get(1).as_slice() {
3636
match scancode::generate(&output_dir) {
3737
Ok(_) => {},
3838
Err(e) => fail!("Could not automatically generate sources for scancodes: {:s}", e.desc),

src/codegen/scancode.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::io::{IoResult,Writer};
2+
use std::path::BytesContainer;
23
use super::get_writer;
34

45
struct ScanCode {
@@ -43,12 +44,12 @@ fn ScanCode(code: uint, ident: &'static str) -> ScanCode {
4344
}
4445

4546
impl ScanCode {
46-
fn ident(&self) -> ~str {
47+
fn ident(&self) -> StrBuf {
4748
self.ident.to_owned()
4849
}
4950

50-
fn padded_ident(&self) -> ~str {
51-
self.ident() + " ".repeat(unsafe { longest_ident } - self.ident().len())
51+
fn padded_ident(&self) -> StrBuf {
52+
self.ident().append(" ".repeat(unsafe { longest_ident } - self.ident().len()).as_slice())
5253
}
5354

5455
}
@@ -319,7 +320,7 @@ use std::num::ToPrimitive;
319320
pub enum ScanCode {
320321
".as_bytes()));
321322
for &entry in entries.iter() {
322-
try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).into_bytes()));
323+
try!(out.write(format!(" {} = {},\n", entry.padded_ident(), entry.code).container_as_bytes()));
323324
}
324325

325326
try!(out.write("
@@ -338,7 +339,7 @@ impl ScanCode {
338339
match *self {
339340
".as_bytes()));
340341
for &entry in entries.iter() {
341-
try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).into_bytes()));
342+
try!(out.write(format!(" {} => {},\n", entry.padded_ident(), entry.code).container_as_bytes()));
342343
}
343344

344345
try!(out.write("
@@ -355,7 +356,7 @@ impl ToPrimitive for ScanCode {
355356
for primitive_type in types.iter() {
356357
try!(out.write(format!("fn to_{}(&self) -> Option<{}> \\{
357358
Some(self.code() as {})
358-
\\}\n", *primitive_type, *primitive_type, *primitive_type).into_bytes()));
359+
\\}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes()));
359360
}
360361

361362
try!(out.write("
@@ -374,10 +375,10 @@ impl FromPrimitive for ScanCode {
374375
try!(out.write(format!("
375376
fn from_{}(n: {}) -> Option<ScanCode> \\{
376377
match n \\{
377-
", *primitive_type, *primitive_type).into_bytes()));
378+
", *primitive_type, *primitive_type).container_as_bytes()));
378379

379380
for &entry in entries.iter() {
380-
try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).into_bytes()));
381+
try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).container_as_bytes()));
381382
}
382383

383384
try!(out.write("

src/sdl2/audio.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn get_num_audio_drivers() -> int {
152152
unsafe { ll::SDL_GetNumAudioDrivers() as int }
153153
}
154154

155-
pub fn get_audio_driver(index: int) -> ~str {
155+
pub fn get_audio_driver(index: int) -> StrBuf {
156156
unsafe {
157157
let buf = ll::SDL_GetAudioDriver(index as c_int);
158158
CString::new(buf, false).as_str().unwrap().into_owned()
@@ -163,14 +163,14 @@ pub fn get_num_audio_devices(iscapture: int) -> int {
163163
unsafe { ll::SDL_GetNumAudioDevices(iscapture as c_int) as int }
164164
}
165165

166-
pub fn get_audio_device_name(index: int, iscapture: int) -> ~str {
166+
pub fn get_audio_device_name(index: int, iscapture: int) -> StrBuf {
167167
unsafe {
168168
let buf = ll::SDL_GetAudioDeviceName(index as c_int, iscapture as c_int);
169169
CString::new(buf, false).as_str().unwrap().into_owned()
170170
}
171171
}
172172

173-
pub fn audio_init(name: &str) -> Result<(), ~str> {
173+
pub fn audio_init(name: &str) -> Result<(), StrBuf> {
174174
let ret = name.with_c_str(|buf| {
175175
unsafe { ll::SDL_AudioInit(buf) }
176176
});
@@ -185,7 +185,7 @@ pub fn audio_quit() {
185185
unsafe { ll::SDL_AudioQuit() }
186186
}
187187

188-
pub fn get_current_audio_driver() -> ~str {
188+
pub fn get_current_audio_driver() -> StrBuf {
189189
unsafe {
190190
let buf = ll::SDL_GetCurrentAudioDriver();
191191
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)
221221

222222

223223
impl<'a> AudioSpec<'a> {
224-
pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec<u8>), ~str> {
224+
pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec<u8>), StrBuf> {
225225
AudioSpec::load_wav_rw(&try!(RWops::from_file(path, "rb")))
226226
}
227227

228-
pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec<u8>), ~str> {
228+
pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec<u8>), StrBuf> {
229229
assert_eq!(mem::size_of::<AudioSpec>(), mem::size_of::<ll::SDL_AudioSpec>());
230230
let mut spec = unsafe { mem::uninit::<AudioSpec>() };
231231
let audio_buf = ptr::null::<u8>();
@@ -261,7 +261,7 @@ impl AudioDevice {
261261
}
262262
}
263263

264-
pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> Result<(AudioDevice, AudioSpec), ~str> {
264+
pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> Result<(AudioDevice, AudioSpec), StrBuf> {
265265
//! SDL_OpenAudioDevice
266266
let obtained = unsafe { mem::uninit::<AudioSpec>() };
267267
unsafe {
@@ -331,7 +331,7 @@ impl Drop for AudioCVT {
331331

332332
impl AudioCVT {
333333
pub fn new(src_format: AudioFormat, src_channels: u8, src_rate: int,
334-
dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result<AudioCVT, ~str> {
334+
dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result<AudioCVT, StrBuf> {
335335
unsafe {
336336
let c_cvt_p = libc::malloc(mem::size_of::<ll::SDL_AudioCVT>() as size_t) as *mut ll::SDL_AudioCVT;
337337
let ret = ll::SDL_BuildAudioCVT(c_cvt_p,
@@ -345,7 +345,7 @@ impl AudioCVT {
345345
}
346346
}
347347

348-
pub fn convert(&self, src: CVec<u8>) -> Result<CVec<u8>, ~str> {
348+
pub fn convert(&self, src: CVec<u8>) -> Result<CVec<u8>, StrBuf> {
349349
//! Convert audio data to a desired audio format.
350350
351351
unsafe {

src/sdl2/event.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,9 @@ pub enum Event {
563563
KeyDownEvent(uint, video::Window, KeyCode, ScanCode, Mod),
564564
KeyUpEvent(uint, video::Window, KeyCode, ScanCode, Mod),
565565
/// (timestamp, window, text, start, length)
566-
TextEditingEvent(uint, video::Window, ~str, int, int),
566+
TextEditingEvent(uint, video::Window, StrBuf, int, int),
567567
/// (timestamp, window, text)
568-
TextInputEvent(uint, video::Window, ~str),
568+
TextInputEvent(uint, video::Window, StrBuf),
569569

570570
/// (timestamp, window, which, [MouseState], x, y, xrel, yrel)
571571
MouseMotionEvent(uint, video::Window, uint, MouseState, int, int,
@@ -614,7 +614,7 @@ pub enum Event {
614614
ClipboardUpdateEvent(uint),
615615

616616
/// (timestamp, filename)
617-
DropFileEvent(uint, ~str),
617+
DropFileEvent(uint, StrBuf),
618618

619619
/// (timestamp, Window, type, code)
620620
UserEvent(uint, video::Window, uint, int),
@@ -1062,7 +1062,7 @@ pub fn poll_event() -> Event {
10621062
}
10631063

10641064
/// Wait indefinitely for the next available event.
1065-
pub fn wait_event() -> Result<Event, ~str> {
1065+
pub fn wait_event() -> Result<Event, StrBuf> {
10661066
let raw = null_event();
10671067
let success = unsafe { ll::SDL_WaitEvent(&raw) == 1 as c_int };
10681068

@@ -1071,7 +1071,7 @@ pub fn wait_event() -> Result<Event, ~str> {
10711071
}
10721072

10731073
/// Wait until the specified timeout (in milliseconds) for the next available event.
1074-
pub fn wait_event_timeout(timeout: int) -> Result<Event, ~str> {
1074+
pub fn wait_event_timeout(timeout: int) -> Result<Event, StrBuf> {
10751075
let raw = null_event();
10761076
let success = unsafe { ll::SDL_WaitEventTimeout(&raw, timeout as c_int) ==
10771077
1 as c_int };
@@ -1133,7 +1133,7 @@ pub fn register_events(num: int) -> Option<uint> {
11331133
}
11341134

11351135
/// add an event to the event queue
1136-
pub fn push_event(event: Event) -> Result<(), ~str> {
1136+
pub fn push_event(event: Event) -> Result<(), StrBuf> {
11371137
match event.to_ll() {
11381138
Some(raw_event) => {
11391139
let ok = unsafe { ll::SDL_PushEvent(&raw_event) == 1 };

src/sdl2/keyboard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn get_scancode_from_key(key: KeyCode) -> ScanCode {
114114
}
115115
}
116116

117-
pub fn get_scancode_name(scancode: ScanCode) -> ~str {
117+
pub fn get_scancode_name(scancode: ScanCode) -> StrBuf {
118118
unsafe {
119119
str::raw::from_c_str(ll::SDL_GetScancodeName(scancode.code() as u32))
120120
}
@@ -128,7 +128,7 @@ pub fn get_scancode_from_name(name: &str) -> ScanCode {
128128
}
129129
}
130130

131-
pub fn get_key_name(key: KeyCode) -> ~str {
131+
pub fn get_key_name(key: KeyCode) -> StrBuf {
132132
unsafe {
133133
str::raw::from_c_str(ll::SDL_GetKeyName(key.code()))
134134
}

src/sdl2/mouse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Drop for Cursor {
8787
}
8888

8989
impl Cursor {
90-
pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result<Cursor, ~str> {
90+
pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result<Cursor, StrBuf> {
9191
unsafe {
9292
let raw = ll::SDL_CreateCursor(data.as_ptr(),
9393
mask.as_ptr(),
@@ -103,7 +103,7 @@ impl Cursor {
103103
}
104104

105105
// 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, ~str> {
106+
pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> Result<Cursor, StrBuf> {
107107
unsafe {
108108
let raw = ll::SDL_CreateColorCursor(surface.raw, hot_x as i32,
109109
hot_y as i32);
@@ -116,7 +116,7 @@ impl Cursor {
116116
}
117117
}
118118

119-
pub fn from_system(cursor: SystemCursor) -> Result<Cursor, ~str> {
119+
pub fn from_system(cursor: SystemCursor) -> Result<Cursor, StrBuf> {
120120
unsafe {
121121
let raw = ll::SDL_CreateSystemCursor(cursor as u32);
122122

0 commit comments

Comments
 (0)