Skip to content

Commit

Permalink
Apply NLL simplifications as it's now stable on the 2015 edition
Browse files Browse the repository at this point in the history
Starting with today's rustc nightly 6d599337f 2019-04-22,
NLL, or more precisely two phase borrows are enabled on
the 2015 edition used by us [1].

Due to this, we can apply simplifications to the codebase
that needed two phase borrows to come to fruition.

[1]: rust-lang/rust#59114
  • Loading branch information
est31 committed Apr 23, 2019
1 parent e7c7f39 commit 7f7aabd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
38 changes: 17 additions & 21 deletions mehlon-server/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,27 +400,23 @@ impl<S :NetworkServerSocket> Server<S> {
}
fn handle_players_waiting_for_kv(&mut self) {
let mut players_to_add = Vec::new();
// TODO with NLL, these {} become unneccessary
// See: https://github.com/rust-lang/rust/issues/57804
{
let pwfk = &mut self.players_waiting_for_kv;
self.map.run_for_kv_results(&mut |id, _payload, key, value| {
if key != "position" {
return;
}
if let Some((conn, nick)) = pwfk.remove(&id) {
let pos = if let Some(buf) = value {
PlayerPosition::deserialize(&buf)
.ok()
.unwrap_or_else(PlayerPosition::default)
} else {
// No value could be found
PlayerPosition::default()
};
players_to_add.push((conn, id, nick, pos));
}
});
}
let pwfk = &mut self.players_waiting_for_kv;
self.map.run_for_kv_results(&mut |id, _payload, key, value| {
if key != "position" {
return;
}
if let Some((conn, nick)) = pwfk.remove(&id) {
let pos = if let Some(buf) = value {
PlayerPosition::deserialize(&buf)
.ok()
.unwrap_or_else(PlayerPosition::default)
} else {
// No value could be found
PlayerPosition::default()
};
players_to_add.push((conn, id, nick, pos));
}
});
for (conn, id, nick, pos) in players_to_add {
self.add_player(conn, id, nick, pos);
}
Expand Down
14 changes: 7 additions & 7 deletions mehlon-server/map_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,13 @@ pub type DynStorageBackend = Box<dyn StorageBackend + Send>;

fn sqlite_backend_from_config(config :&mut Config, auth_needed :bool)
-> Option<(DynStorageBackend, Option<SqliteLocalAuth>)> {
// TODO: once we have NLL, remove the "cloned" below
// See: https://github.com/rust-lang/rust/issues/57804
let p = config.map_storage_path.as_ref().cloned()?;
let p = config.map_storage_path.as_ref()?;

let p_config = Path::new(&p);
let p_auth = p_config.with_file_name(p_config.file_stem()
.and_then(|v| v.to_str()).unwrap_or("").to_owned()
+ "-auth.sqlite");

let sqlite_backend = match SqliteStorageBackend::open_or_create(&p) {
Ok(mut b) => {
manage_mapgen_meta_toml(&mut b, config).unwrap();
Expand All @@ -450,10 +454,6 @@ fn sqlite_backend_from_config(config :&mut Config, auth_needed :bool)
},
};
let storage_backend = Box::new(sqlite_backend);
let p_config = Path::new(&p);
let p_auth = p_config.with_file_name(p_config.file_stem()
.and_then(|v| v.to_str()).unwrap_or("").to_owned()
+ "-auth.sqlite");
let local_auth = if auth_needed {
Some(SqliteLocalAuth::open_or_create(p_auth).unwrap())
} else {
Expand Down
6 changes: 1 addition & 5 deletions mehlon-server/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,7 @@ impl MapgenMap {
sth_to_generate = true;
}
}
// TODO: once we have NLL, remove the continue, and
// remove the /* */ around the else below.
// See: https://github.com/rust-lang/rust/issues/57804
continue;
} /* else */ {
} else {
if let Some(data) = self.storage.load_chunk(pos).unwrap() {
let chn = MapChunk {
data,
Expand Down

0 comments on commit 7f7aabd

Please sign in to comment.