Skip to content

Commit

Permalink
language changes: updated dependencies, lifetime bounds, deprecated m…
Browse files Browse the repository at this point in the history
…ethods.
  • Loading branch information
lifthrasiir committed Aug 30, 2014
1 parent cf99b81 commit 61f4758
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion libs/cson-rust
Submodule cson-rust updated 1 files
+2 −2 src/reader.rs
2 changes: 1 addition & 1 deletion libs/rust-encoding
2 changes: 1 addition & 1 deletion libs/rust-sdl
2 changes: 1 addition & 1 deletion src/engine/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> Transaction<'a> {

/// Consumes the transaction while commiting it.
fn commit(mut self) {
let db = self.db.take_unwrap();
let db = self.db.take().unwrap();
match db.prepare("COMMIT;", &None).map(|mut c| step_cursor(db, &mut c)) {
Ok(..) => {},
Err(err) => fail_from_sqlite(db, err),
Expand Down
12 changes: 6 additions & 6 deletions src/format/bms/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ pub fn decode_stream(f: &mut Reader, encoding: EncodingRef) -> String {
//
// Rust: cannot change this to return `EncodingRef`, it seems to "infect" other uses of
// `UTF_8.decode(...)` etc. to fail to resolve.
pub fn guess_decode_stream(f: &mut Reader) -> (String, &'static Encoding, f64) {
pub fn guess_decode_stream(f: &mut Reader) -> (String, EncodingRef, f64) {
let s: Vec<u8> = f.read_to_end().ok().unwrap_or_else(|| Vec::new());

// check for BOM (Sonorous proposal #1)
if s.len() >= 3 && [0xef, 0xbb, 0xbf].equiv(&s.slice_to(3)) {
return (UTF_8.decode(s.as_slice(), DecodeReplace).unwrap(),
UTF_8 as &'static Encoding, 1.0);
UTF_8 as EncodingRef, 1.0);
}

// check for UTF-8 first line (Sonorous proposal #2)
Expand All @@ -75,13 +75,13 @@ pub fn guess_decode_stream(f: &mut Reader) -> (String, &'static Encoding, f64) {
let firstline = first1k.slice_to(first1keol);
if firstline.iter().any(|&c| c >= 0x80) && UTF_8.decode(firstline, DecodeStrict).is_ok() {
return (UTF_8.decode(s.as_slice(), DecodeReplace).unwrap(),
UTF_8 as &'static Encoding, 1.0);
UTF_8 as EncodingRef, 1.0);
}

// ASCII: do we have to decode at all?
if s.iter().all(|&c| c < 0x80) {
return (ASCII.decode(s.as_slice(), DecodeReplace).unwrap(),
ASCII as &'static Encoding, 1.0);
ASCII as EncodingRef, 1.0);
}

// Windows-949/31J: guess
Expand All @@ -91,9 +91,9 @@ pub fn guess_decode_stream(f: &mut Reader) -> (String, &'static Encoding, f64) {
let jaconfidence = Classifier::new(CharClassJa, LOG_PROBS_JA).raw_confidence(ja.as_slice());
let (s, encoding, confidence) =
if koconfidence < jaconfidence {
(ko, WINDOWS_949 as &'static Encoding, koconfidence)
(ko, WINDOWS_949 as EncodingRef, koconfidence)
} else {
(ja, WINDOWS_31J as &'static Encoding, jaconfidence)
(ja, WINDOWS_31J as EncodingRef, jaconfidence)
};
(s, encoding, convert_raw_confidence(confidence))
}
Expand Down
4 changes: 2 additions & 2 deletions src/format/bms/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ impl<'r> Iterator<Parsed<'r>> for ParsingIterator<'r> {
}

/// The preprocessing parser, which feeds parsed items from the main parser into the preprocessor.
pub struct PreprocessingParser<'r,R> {
pub struct PreprocessingParser<'r, R:'r> {
/// The internal parser.
parser: Parser<'r>,
/// The random number generator.
Expand All @@ -845,7 +845,7 @@ pub struct PreprocessingParser<'r,R> {
* One difference is that the preprocessor may return additional commands at the end of file,
* so we keep the `done` flag to avoid calling the parsing iterator when it already returned None.
*/
pub struct PreprocessingParsingIterator<'r,R> {
pub struct PreprocessingParsingIterator<'r, R:'r> {
/// The preprocessor that returns a pair of the line number (if any) and fully owned command.
pp: Preprocessor<'r,(Option<uint>,BmsCommand<'static>),R>,
/// The base parsing iterator.
Expand Down
2 changes: 1 addition & 1 deletion src/format/bms/preproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct Block {
}

/// A generic BMS preprocessor. `T` is normally a BMS command, but there is no restriction.
pub struct Preprocessor<'r,T,R> {
pub struct Preprocessor<'r, T, R:'r> {
/// The current block informations.
blocks: Vec<Block>,
/// Random number generator.
Expand Down
2 changes: 1 addition & 1 deletion src/format/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<S:fmt::Show,I:fmt::Show> fmt::Show for ObjData<S,I> {
}
}

struct fmt_or_default<'r,T>(&'r Option<T>, &'r str);
struct fmt_or_default<'r, T:'r>(&'r Option<T>, &'r str);
impl<'r,T:fmt::Show> fmt::Show for fmt_or_default<'r,T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Expand Down
4 changes: 2 additions & 2 deletions src/format/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<S,I> Iterator<Pointer<S,I>> for UntilIterator<S,I> {
}

/// An iterator object for `Pointer::mut_upto`.
pub struct MutUptoIterator<'r,SoundRef,ImageRef> {
pub struct MutUptoIterator<'r, SoundRef:'r, ImageRef:'r> {
ptr: &'r mut Pointer<SoundRef,ImageRef>,
finished: bool,
lastloc: Option<ObjLoc<f64>>,
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<'r,S,I> Drop for MutUptoIterator<'r,S,I> {
}

/// An iterator object for `Pointer::mut_until`.
pub struct MutUntilIterator<'r,SoundRef,ImageRef> {
pub struct MutUntilIterator<'r, SoundRef:'r, ImageRef:'r> {
ptr: &'r mut Pointer<SoundRef,ImageRef>,
finished: bool,
lastloc: Option<ObjLoc<f64>>,
Expand Down
9 changes: 5 additions & 4 deletions src/gfx/bmfont.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Font {

if v & (1|8) == (1|8) || v & (2|4) == (2|4) { // completely filled
if cur.is_some() {
let mut polygon = cur.take_unwrap();
let mut polygon = cur.take().unwrap();
polygon.x12 += 2;
polygon.xm2 += 2;
polygon.x22 += 2;
Expand All @@ -186,7 +186,7 @@ impl Font {
let dxm2 = 1;
let dx22 = if v & 2 != 0 {2} else {0};
if cur.is_some() {
let mut polygon = cur.take_unwrap();
let mut polygon = cur.take().unwrap();
polygon.x12 += dx12;
polygon.xm2 += dxm2;
polygon.x22 += dx22;
Expand All @@ -201,9 +201,10 @@ impl Font {
v &= !(2|8);
}

// now we have cleared the left side, any remaining polygon should be flushed.
// now we have cleared the left side,
// any remaining polygon should be flushed.
if cur.is_some() {
polygons.push(cur.take_unwrap());
polygons.push(cur.take().unwrap());
}

if v & (1|4) != 0 { // has right-side edge, add a new polygon
Expand Down
8 changes: 4 additions & 4 deletions src/gfx/skin/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl<T:Hook> Hook for Option<T> {

/// A delegated hook with the order.
pub struct Delegate<'a> {
base: &'a Hook,
delegated: &'a Hook,
base: &'a Hook+'a,
delegated: &'a Hook+'a,
}

impl<'a> Hook for Delegate<'a> {
Expand All @@ -133,7 +133,7 @@ impl<'a> Hook for Delegate<'a> {

/// A delegated hook with a single scalar hook added.
pub struct AddText<'a> {
base: &'a Hook,
base: &'a Hook+'a,
id: &'a str,
value: &'a str,
}
Expand Down Expand Up @@ -182,7 +182,7 @@ macro_rules! define_hooks(
fn block_hook(&self, id: &str, parent: &::gfx::skin::hook::Hook,
mut body: |&::gfx::skin::hook::Hook, &str| -> bool) -> bool {
#[allow(unused_imports)] use gfx::skin::scalar::{AsScalar, IntoScalar};
type HookRef<'a> = &'a ::gfx::skin::hook::Hook;
type HookRef<'a> = &'a ::gfx::skin::hook::Hook+'a;
type Body<'a> = |&::gfx::skin::hook::Hook, &str|: 'a -> bool;

match id {
Expand Down
8 changes: 4 additions & 4 deletions src/gfx/skin/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

//! A (sort of) parser for Scene description language.

use std::{num, result, mem};
use std::{num, mem};
use std::collections::{TreeMap, HashMap};
use cson;
use serialize::json::{Json, ToJson, Null, Boolean, I64, U64, F64, String, List, Object};
Expand Down Expand Up @@ -45,7 +45,7 @@ impl<T:FromJson> FromJson for Box<T> {
impl<T:FromJson> FromJson for Vec<T> {
fn from_json(json: Json) -> Result<Vec<T>,String> {
match json {
List(l) => result::collect(l.move_iter().map(from_json::<T>)),
List(l) => l.move_iter().map(from_json::<T>).collect(),
_ => Err(format!("expected a list")),
}
}
Expand Down Expand Up @@ -571,12 +571,12 @@ impl<T:FromJson> FromJson for Block<T> {

// {"$$": "even?", "alt1": ..., "alt2": ..., "$default": ..., "$else": ...}
(None, default, else_, false) => {
let map = result::collect(map.move_iter().map(|(k,v)|
let map: Result<HashMap<String,T>, String> = map.move_iter().map(|(k,v)|
match from_json::<T>(v) {
Ok(v) => Ok((k.into_string(), v)),
Err(err) => Err(err),
}
));
).collect();
Ok(MultiBlock { gen: gen, map: try!(map), default: default, else_: else_ })
},

Expand Down
14 changes: 7 additions & 7 deletions src/ui/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl LoadingContext {

/// Loads the sound and creates a `Chunk` for it.
pub fn load_sound(&mut self, i: uint) {
let path = self.bms.meta.sndpath.as_slice()[i].get_ref().clone();
let path = self.bms.meta.sndpath.as_slice()[i].as_ref().unwrap().clone();
self.lastpath = Some(path.clone());
let fullpath = self.search.resolve_relative_path_for_sound(path.as_slice(), &self.basedir);

Expand All @@ -142,7 +142,7 @@ impl LoadingContext {

/// Loads the image or movie and creates an OpenGL texture for it.
pub fn load_image(&mut self, i: uint) {
let path = self.bms.meta.imgpath.as_slice()[i].get_ref().clone();
let path = self.bms.meta.imgpath.as_slice()[i].as_ref().unwrap().clone();
self.lastpath = Some(path.clone());
let fullpath = self.search.resolve_relative_path_for_image(path.as_slice(), &self.basedir);

Expand Down Expand Up @@ -240,11 +240,11 @@ impl Scene for LoadingScene {

fn deactivate(&mut self) {}

fn consume(self) -> Box<Scene> {
fn consume(self) -> Box<Scene+'static> {
let LoadingScene { context, screen, .. } = self;
let (player, imgres) = context.to_player();
match PlayingScene::new(player, screen, imgres) {
Ok(scene) => scene as Box<Scene>,
Ok(scene) => scene as Box<Scene+'static>,
Err(err) => die!("{}", err),
}
}
Expand Down Expand Up @@ -342,12 +342,12 @@ Level {level} | BPM {bpm:.2}{hasbpmchange} | \
}
}

fn consume(self) -> Box<Scene> {
fn consume(self) -> Box<Scene+'static> {
let TextualLoadingScene { context, screen } = self;
let (player, imgres) = context.to_player();
match screen {
Some(screen) => ViewingScene::new(screen, imgres, player) as Box<Scene>,
None => TextualViewingScene::new(player) as Box<Scene>,
Some(screen) => ViewingScene::new(screen, imgres, player) as Box<Scene+'static>,
None => TextualViewingScene::new(player) as Box<Scene+'static>,
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/ui/playing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,13 @@ impl Scene for PlayingScene {
if grade == MISS {
// switches to the normal BGA after 600ms
let minlimit = when + 600;
self.poorlimit.mutate_or_set(minlimit, |t| cmp::max(t, minlimit));
self.poorlimit =
Some(self.poorlimit.map_or(minlimit, |t| cmp::max(t, minlimit)));
}
// grade disappears after 700ms
let minlimit = when + 700;
self.gradelimit.mutate_or_set(minlimit, |t| cmp::max(t, minlimit));
self.gradelimit =
Some(self.gradelimit.map_or(minlimit, |t| cmp::max(t, minlimit)));
}
if self.poorlimit < Some(self.player.now) { self.poorlimit = None; }
if self.gradelimit < Some(self.player.now) { self.gradelimit = None; }
Expand Down Expand Up @@ -547,9 +549,9 @@ impl Scene for PlayingScene {

fn deactivate(&mut self) {}

fn consume(self) -> Box<Scene> {
fn consume(self) -> Box<Scene+'static> {
let PlayingScene { screen, player, .. } = self;
PlayResultScene::new(screen, player) as Box<Scene>
PlayResultScene::new(screen, player) as Box<Scene+'static>
}
}

2 changes: 1 addition & 1 deletion src/ui/playresult.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Scene for PlayResultScene {

fn deactivate(&mut self) {}

fn consume(self) -> Box<Scene> { fail!("unreachable"); }
fn consume(self) -> Box<Scene+'static> { fail!("unreachable"); }
}

define_hooks! {
Expand Down
8 changes: 4 additions & 4 deletions src/ui/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum SceneCommand {
Continue,
/// Pushes a new `Scene` to the scene stack, making it the active scene. The current scene is
/// stopped (after calling `deactivate`) until the new scene returns `PopScene` command.
PushScene(Box<Scene>),
PushScene(Box<Scene+'static>),
/// Replaces the current scene with a new `Scene` that will be returned by `consume` method.
/// The command itself does not have a `Scene` argument since new scene may have to be
/// constructured out of the existing scene. Therefore the scene should be prepared for
Expand Down Expand Up @@ -78,11 +78,11 @@ pub trait Scene {

/// Called when the scene is to be replaced by a new `Scene` due to the `ReplaceScene` command.
/// When called due to the `tick` call, this is called after `deactivate` call.
fn consume(self) -> Box<Scene>;
fn consume(self) -> Box<Scene+'static>;
}

/// Runs given scene and other additionally spawned scenes.
pub fn run_scene(scene: Box<Scene>) {
pub fn run_scene(scene: Box<Scene+'static>) {
let mut current = scene;
let mut stack = Vec::new();
loop {
Expand All @@ -101,7 +101,7 @@ pub fn run_scene(scene: Box<Scene>) {
_ => { break; }
}
let now = get_ticks();
if now < ticklimit { sleep(Duration::milliseconds((ticklimit - now) as i32)); }
if now < ticklimit { sleep(Duration::milliseconds((ticklimit - now) as i64)); }
}
current.deactivate();
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/selecting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl SelectingScene {

/// Creates a new `LoadingScene` from the currently selected entry. It will load the BMS file
/// or use the preloaded data if possible.
pub fn create_loading_scene(&mut self) -> Option<Box<Scene>> {
pub fn create_loading_scene(&mut self) -> Option<Box<Scene+'static>> {
use std::mem::replace;

let preloaded = replace(&mut self.preloaded, PreloadAfter(0));
Expand Down Expand Up @@ -471,7 +471,7 @@ impl SelectingScene {
Err(err) => die!("{}", err)
};
Some(LoadingScene::new(self.screen.clone(), bms, infos,
keyspec, keymap, self.opts.clone()) as Box<Scene>)
keyspec, keymap, self.opts.clone()) as Box<Scene+'static>)
}
}

Expand Down Expand Up @@ -640,7 +640,7 @@ impl Scene for SelectingScene {
*self.keepgoing.write() = false;
}

fn consume(self) -> Box<Scene> { fail!("unreachable"); }
fn consume(self) -> Box<Scene+'static> { fail!("unreachable"); }
}

define_hooks! {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/viewing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Scene for TextualViewingScene {
update_line("");
}

fn consume(self) -> Box<Scene> { fail!("unreachable"); }
fn consume(self) -> Box<Scene+'static> { fail!("unreachable"); }
}

/// BGA-only viewing scene context. Used for the exclusive mode with BGA enabled.
Expand Down Expand Up @@ -260,6 +260,6 @@ impl Scene for ViewingScene {

fn deactivate(&mut self) { self.parent.deactivate() }

fn consume(self) -> Box<Scene> { fail!("unreachable"); }
fn consume(self) -> Box<Scene+'static> { fail!("unreachable"); }
}

2 changes: 1 addition & 1 deletion src/util/maybe_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::collections::Collection;
use std::default::Default;

/// A vector that can hold either `&'r [T]` or `Vec<T>`.
pub enum MaybeOwnedVec<'r,T> {
pub enum MaybeOwnedVec<'r, T:'r> {
OwnedVec(Vec<T>),
VecSlice(&'r [T]),
}
Expand Down

0 comments on commit 61f4758

Please sign in to comment.