From b099ebfaa0dbfa2f218c81f66f4ee8d642259fef Mon Sep 17 00:00:00 2001 From: SelfMadeSystem Date: Sun, 8 Oct 2023 11:27:46 -0400 Subject: [PATCH] Use standard `div_cell` (#547) # Objective - Replace `num_integer::div_ceil` with the standard `div_ceil`. - Closes #544 # Solution [Rust 1.73.0 stabilized div_ceil for unsigned integers.](https://blog.rust-lang.org/2023/10/05/Rust-1.73.0.html#stabilized-apis) - Replaces `num_integer::div_ceil` with the standard `div_ceil`. - Removes `num-integer` crate as a dependency because it is no longer used. --- Cargo.toml | 1 - crates/valence_anvil/Cargo.toml | 3 +-- crates/valence_anvil/src/parsing.rs | 5 ++--- crates/valence_server/Cargo.toml | 1 - crates/valence_server/src/layer/chunk/paletted_container.rs | 5 ++--- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f221a2dd4..c4d5e25bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -140,7 +140,6 @@ lru = "0.11.0" noise = "0.8.2" num = "0.4.0" num-bigint = "0.4.3" -num-integer = "0.1.45" owo-colors = "3.5.0" parking_lot = "0.12.1" paste = "1.0.11" diff --git a/crates/valence_anvil/Cargo.toml b/crates/valence_anvil/Cargo.toml index c5bd484dd..4aedac8ea 100644 --- a/crates/valence_anvil/Cargo.toml +++ b/crates/valence_anvil/Cargo.toml @@ -11,7 +11,7 @@ license.workspace = true [features] bevy_plugin = ["dep:bevy_app", "dep:bevy_ecs", "dep:flume", "parsing"] -parsing = ["dep:num-integer", "dep:valence_server"] +parsing = ["dep:valence_server"] [dependencies] bevy_app = { workspace = true, optional = true } @@ -22,7 +22,6 @@ byteorder.workspace = true flate2.workspace = true flume = { workspace = true, optional = true } lru.workspace = true -num-integer = { workspace = true, optional = true } thiserror.workspace = true valence_nbt = { workspace = true, features = ["binary"] } valence_server = { workspace = true, optional = true } diff --git a/crates/valence_anvil/src/parsing.rs b/crates/valence_anvil/src/parsing.rs index 898aa4436..68f85b76a 100644 --- a/crates/valence_anvil/src/parsing.rs +++ b/crates/valence_anvil/src/parsing.rs @@ -2,7 +2,6 @@ use std::borrow::Cow; use std::collections::BTreeMap; use std::path::PathBuf; -use num_integer::div_ceil; use thiserror::Error; use valence_server::block::{PropName, PropValue}; use valence_server::layer::chunk::{Chunk, UnloadedChunk}; @@ -214,7 +213,7 @@ fn parse_chunk( let bits_per_idx = bit_width(converted_block_palette.len() - 1).max(4); let idxs_per_long = 64 / bits_per_idx; - let long_count = div_ceil(BLOCKS_PER_SECTION, idxs_per_long); + let long_count = BLOCKS_PER_SECTION.div_ceil(idxs_per_long); let mask = 2_u64.pow(bits_per_idx as u32) - 1; if long_count != data.len() { @@ -281,7 +280,7 @@ fn parse_chunk( let bits_per_idx = bit_width(converted_biome_palette.len() - 1); let idxs_per_long = 64 / bits_per_idx; - let long_count = div_ceil(BIOMES_PER_SECTION, idxs_per_long); + let long_count = BIOMES_PER_SECTION.div_ceil(idxs_per_long); let mask = 2_u64.pow(bits_per_idx as u32) - 1; if long_count != data.len() { diff --git a/crates/valence_server/Cargo.toml b/crates/valence_server/Cargo.toml index bafa51c57..f4cb5be08 100644 --- a/crates/valence_server/Cargo.toml +++ b/crates/valence_server/Cargo.toml @@ -29,5 +29,4 @@ valence_protocol.workspace = true valence_generated.workspace = true rustc-hash.workspace = true parking_lot.workspace = true -num-integer.workspace = true arrayvec.workspace = true diff --git a/crates/valence_server/src/layer/chunk/paletted_container.rs b/crates/valence_server/src/layer/chunk/paletted_container.rs index 302151d83..cc470c42c 100644 --- a/crates/valence_server/src/layer/chunk/paletted_container.rs +++ b/crates/valence_server/src/layer/chunk/paletted_container.rs @@ -2,7 +2,6 @@ use std::array; use std::io::Write; use arrayvec::ArrayVec; -use num_integer::div_ceil; use valence_protocol::{Encode, VarInt}; use super::chunk::bit_width; @@ -28,7 +27,7 @@ impl PalettedContainer { pub(super) fn new() -> Self { - assert_eq!(div_ceil(LEN, 2), HALF_LEN); + assert_eq!(LEN.div_ceil(2), HALF_LEN); assert_ne!(LEN, 0); Self::Single(T::default()) @@ -261,7 +260,7 @@ impl Indirect usize { let vals_per_u64 = 64 / bits_per_val; - div_ceil(vals_count, vals_per_u64) + vals_count.div_ceil(vals_per_u64) } #[inline]