diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2026-01-13 10:51:45 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-13 10:51:45 -0600 |
| commit | b21ac946cafaacc9ee2478ea48ed9e72554f79ed (patch) | |
| tree | 4d05744b9801e94f5da6563d8fabddfb20d1c7b7 /azalea-brigadier/src | |
| parent | d5fa5e32b37754b3b5c136e58821e48cd3b7c2ff (diff) | |
| download | azalea-drasl-b21ac946cafaacc9ee2478ea48ed9e72554f79ed.tar.xz | |
Merge AzaleaRead and AzaleaWrite (#305)
Diffstat (limited to 'azalea-brigadier/src')
| -rw-r--r-- | azalea-brigadier/src/suggestion/mod.rs | 18 | ||||
| -rw-r--r-- | azalea-brigadier/src/suggestion/suggestions.rs | 24 |
2 files changed, 16 insertions, 26 deletions
diff --git a/azalea-brigadier/src/suggestion/mod.rs b/azalea-brigadier/src/suggestion/mod.rs index 95a451f3..b2107889 100644 --- a/azalea-brigadier/src/suggestion/mod.rs +++ b/azalea-brigadier/src/suggestion/mod.rs @@ -2,18 +2,12 @@ mod suggestion_provider; mod suggestions; mod suggestions_builder; -#[cfg(feature = "azalea-buf")] -use std::io::{self, Write}; use std::{ cmp::Ordering, fmt::{self, Display}, hash::Hash, }; -#[cfg(feature = "azalea-buf")] -use azalea_buf::AzaleaWrite; -#[cfg(feature = "azalea-buf")] -use azalea_chat::FormattedText; pub use suggestion_provider::SuggestionProvider; pub use suggestions::Suggestions; pub use suggestions_builder::SuggestionsBuilder; @@ -138,15 +132,3 @@ impl PartialOrd for SuggestionValue { Some(self.cmp(other)) } } - -#[cfg(feature = "azalea-buf")] -impl AzaleaWrite for Suggestion { - fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { - self.value.to_string().azalea_write(buf)?; - self.tooltip - .clone() - .map(FormattedText::from) - .azalea_write(buf)?; - Ok(()) - } -} diff --git a/azalea-brigadier/src/suggestion/suggestions.rs b/azalea-brigadier/src/suggestion/suggestions.rs index c0090a35..64156154 100644 --- a/azalea-brigadier/src/suggestion/suggestions.rs +++ b/azalea-brigadier/src/suggestion/suggestions.rs @@ -3,7 +3,7 @@ use std::io::{self, Cursor, Write}; use std::{collections::HashSet, hash::Hash}; #[cfg(feature = "azalea-buf")] -use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_buf::{AzBuf, AzBufVar, BufReadError}; #[cfg(feature = "azalea-buf")] use azalea_chat::FormattedText; @@ -77,7 +77,7 @@ impl Suggestions { } #[cfg(feature = "azalea-buf")] -impl AzaleaRead for Suggestions { +impl AzBuf for Suggestions { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { #[derive(AzBuf)] struct StandaloneSuggestion { @@ -90,7 +90,7 @@ impl AzaleaRead for Suggestions { let range = StringRange::between(start, start + length); // the range of a Suggestion depends on the Suggestions containing it, - // so we can't just `impl AzaleaRead for Suggestion` + // so we can't just `impl AzBuf for Suggestion` let mut suggestions = Vec::<StandaloneSuggestion>::azalea_read(buf)? .into_iter() .map(|s| Suggestion { @@ -103,14 +103,22 @@ impl AzaleaRead for Suggestions { Ok(Suggestions { range, suggestions }) } -} - -#[cfg(feature = "azalea-buf")] -impl AzaleaWrite for Suggestions { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { (self.range.start() as u32).azalea_write_var(buf)?; (self.range.length() as u32).azalea_write_var(buf)?; - self.suggestions.azalea_write(buf)?; + // self.suggestions.azalea_write(buf)?; + + self.suggestions + .iter() + .map(|s| { + ( + s.value.to_string(), + s.tooltip.clone().map(FormattedText::from), + ) + }) + .collect::<Box<_>>() + .azalea_write(buf)?; + Ok(()) } } |
