Skip to content

Commit

Permalink
Adopt range_contains
Browse files Browse the repository at this point in the history
The feature is now stable, as of latest rustc nightly
rustc 1.35.0-nightly (2c8bbf50d 2019-03-16)
  • Loading branch information
est31 committed Mar 17, 2019
1 parent 989d7fe commit d6121e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
10 changes: 3 additions & 7 deletions mehlon-server/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,13 @@ impl<S :NetworkServerSocket> Server<S> {
let msg = conn.try_recv();
match msg {
Ok(Some(ClientToServerMsg::LogIn(nick))) => {
// TODO use range_contains once it becomes
// available
// https://github.com/rust-lang/rust/issues/32311

// Check that the nick uses valid characters
let nick_has_valid_chars = nick
.bytes()
.all(|b|
(b >= b'0' && b <= b'9') ||
(b >= b'a' && b <= b'z') ||
(b >= b'A' && b <= b'Z') ||
(b'0' ..= b'9').contains(&b) ||
(b'a' ..= b'z').contains(&b) ||
(b'A' ..= b'Z').contains(&b) ||
(b == b'-' || b == b'_'));

let id = {
Expand Down
16 changes: 6 additions & 10 deletions mehlon-server/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,9 @@ impl MapgenMap {
for z in pos_min.z - ex ..= pos_max.z + ex {
let pos = Vector3::new(x, y, z) * CHUNKSIZE;
if let Some(c) = self.chunks.get(&pos) {
// TODO use range_contains once it's available
// https://github.com/rust-lang/rust/issues/32311
if x >= pos_min.x && x < pos_max.x &&
y >= pos_min.y && y < pos_max.y &&
z >= pos_min.z && z < pos_max.z {
if (pos_min.x .. pos_max.x).contains(&x) &&
(pos_min.y .. pos_max.y).contains(&y) &&
(pos_min.z .. pos_max.z).contains(&z) {
if c.generation_phase != GenerationPhase::Done {
sth_to_generate = true;
}
Expand All @@ -390,11 +388,9 @@ impl MapgenMap {
f(pos, &chn.data);
self.chunks.insert(pos, chn);
} else {
// TODO use range_contains once it's available
// https://github.com/rust-lang/rust/issues/32311
if x >= pos_min.x && x < pos_max.x &&
y >= pos_min.y && y < pos_max.y &&
z >= pos_min.z && z < pos_max.z {
if (pos_min.x .. pos_max.x).contains(&x) &&
(pos_min.y .. pos_max.y).contains(&y) &&
(pos_min.z .. pos_max.z).contains(&z) {
sth_to_generate = true;
}
}
Expand Down

0 comments on commit d6121e4

Please sign in to comment.