diff options
| author | mat <git@matdoes.dev> | 2025-09-20 20:35:16 -1200 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-09-20 20:35:16 -1200 |
| commit | 585b51e91a5335eae37bc5af7c0111bb2092b156 (patch) | |
| tree | c1559014df9db20dd625d9fe972d4e9f88317008 /azalea-buf/src/write.rs | |
| parent | db793448ff8e656ad80859835edc3b89cb547dd2 (diff) | |
| download | azalea-drasl-585b51e91a5335eae37bc5af7c0111bb2092b156.tar.xz | |
more accurate mining and impl PartialEq for packets
Diffstat (limited to 'azalea-buf/src/write.rs')
| -rw-r--r-- | azalea-buf/src/write.rs | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/azalea-buf/src/write.rs b/azalea-buf/src/write.rs index a925647d..7b9ad496 100644 --- a/azalea-buf/src/write.rs +++ b/azalea-buf/src/write.rs @@ -5,6 +5,7 @@ use std::{ }; use byteorder::{BigEndian, WriteBytesExt}; +use indexmap::IndexMap; use super::{MAX_STRING_LENGTH, UnsizedByteArray}; @@ -80,30 +81,36 @@ impl<T: AzaleaWrite> AzaleaWrite for [T] { } } -impl<K: AzaleaWrite, V: AzaleaWrite> AzaleaWrite for HashMap<K, V> { - fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { - u32::azalea_write_var(&(self.len() as u32), buf)?; - for (key, value) in self { - key.azalea_write(buf)?; - value.azalea_write(buf)?; - } - - Ok(()) - } -} +macro_rules! impl_for_map_type { + ($ty: ident) => { + impl<K: AzaleaWrite, V: AzaleaWrite> AzaleaWrite for $ty<K, V> { + fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { + u32::azalea_write_var(&(self.len() as u32), buf)?; + for (key, value) in self { + key.azalea_write(buf)?; + value.azalea_write(buf)?; + } -impl<K: AzaleaWrite, V: AzaleaWriteVar> AzaleaWriteVar for HashMap<K, V> { - fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> { - u32::azalea_write_var(&(self.len() as u32), buf)?; - for (key, value) in self { - key.azalea_write(buf)?; - value.azalea_write_var(buf)?; + Ok(()) + } } - - Ok(()) - } + impl<K: AzaleaWrite, V: AzaleaWriteVar> AzaleaWriteVar for $ty<K, V> { + fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> { + u32::azalea_write_var(&(self.len() as u32), buf)?; + for (key, value) in self { + key.azalea_write(buf)?; + value.azalea_write_var(buf)?; + } + + Ok(()) + } + } + }; } +impl_for_map_type!(HashMap); +impl_for_map_type!(IndexMap); + impl AzaleaWrite for Vec<u8> { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { (self.len() as u32).azalea_write_var(buf)?; |
