aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-12-11 03:25:36 +0000
committermat <git@matdoes.dev>2024-12-11 03:25:36 +0000
commit097a620de1a0139ca9a745ddc146c37e1d4695da (patch)
tree293a0187f7528afa48aa5ffa7e89acd10841c5ba /azalea-core/src
parent2feef494718009dbcb5c62ef1e58c84c36e8bcbf (diff)
downloadazalea-drasl-097a620de1a0139ca9a745ddc146c37e1d4695da.tar.xz
fix for latest nightly by changing the FixedBitSet generic to take bytes instead of bits
Diffstat (limited to 'azalea-core/src')
-rwxr-xr-xazalea-core/src/bitset.rs40
1 files changed, 16 insertions, 24 deletions
diff --git a/azalea-core/src/bitset.rs b/azalea-core/src/bitset.rs
index e7c79467..de9d00f3 100755
--- a/azalea-core/src/bitset.rs
+++ b/azalea-core/src/bitset.rs
@@ -126,26 +126,24 @@ impl From<Vec<u8>> for BitSet {
/// A list of bits with a known fixed size.
///
+/// The `N` is the number of bytes reserved for the bitset. You're encouraged to
+/// use it like `FixedBitSet<{ 20_usize.div_ceil(8) }>` if you need 20 bits.
+///
+/// TODO: this should be changed back to bits once this is resolved:
+/// https://github.com/rust-lang/rust/issues/133199#issuecomment-2531645526
+///
/// Note that this is primarily meant for fast serialization and deserialization
/// for Minecraft, if you don't need that you should use the `fixedbitset` crate
/// since it's approximately 20% faster (since it stores the data as usizes
-/// instead of u8s)
+/// instead of u8s).
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct FixedBitSet<const N: usize>
-where
- [(); N.div_ceil(8)]: Sized,
-{
- data: [u8; N.div_ceil(8)],
+pub struct FixedBitSet<const N: usize> {
+ data: [u8; N],
}
-impl<const N: usize> FixedBitSet<N>
-where
- [u8; N.div_ceil(8)]: Sized,
-{
+impl<const N: usize> FixedBitSet<N> {
pub fn new() -> Self {
- FixedBitSet {
- data: [0; N.div_ceil(8)],
- }
+ FixedBitSet { data: [0; N] }
}
#[inline]
@@ -159,24 +157,18 @@ where
}
}
-impl<const N: usize> AzaleaRead for FixedBitSet<N>
-where
- [u8; N.div_ceil(8)]: Sized,
-{
+impl<const N: usize> AzaleaRead for FixedBitSet<N> {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
- let mut data = [0; N.div_ceil(8)];
- for item in data.iter_mut().take(N.div_ceil(8)) {
+ let mut data = [0; N];
+ for item in data.iter_mut().take(N) {
*item = u8::azalea_read(buf)?;
}
Ok(FixedBitSet { data })
}
}
-impl<const N: usize> AzaleaWrite for FixedBitSet<N>
-where
- [u8; N.div_ceil(8)]: Sized,
-{
+impl<const N: usize> AzaleaWrite for FixedBitSet<N> {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- for i in 0..N.div_ceil(8) {
+ for i in 0..N {
self.data[i].azalea_write(buf)?;
}
Ok(())