From ee2575794e91b9457a74a95daf1dcc707058cd58 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 12 Oct 2025 23:01:54 +0300 Subject: upgrade deps and clean up lots of doc comments --- azalea-chat/src/component.rs | 13 ++-- azalea-chat/src/style.rs | 2 +- azalea-chat/src/translatable_component.rs | 98 ++++--------------------------- 3 files changed, 19 insertions(+), 94 deletions(-) (limited to 'azalea-chat/src') diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index 87886e96..30b0ed9d 100644 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -76,19 +76,22 @@ impl FormattedText { /// Render all components into a single `String`, using your custom /// closures to drive styling, text transformation, and final cleanup. /// - /// # Type params + /// # Type parameters + /// /// - `F`: `(running, component, default) -> (prefix, suffix)` for /// per-component styling /// - `S`: `&str -> String` for text tweaks (escaping, mapping, etc.) /// - `C`: `&final_running_style -> String` for any trailing cleanup /// - /// # Args - /// - `style_formatter`: how to open/close each component’s style - /// - `text_formatter`: how to turn raw text into output text + /// # Arguments + /// + /// - `style_formatter`: how to open/close each component's style + /// - `text_formatter`: how to turn raw text into output text /// - `cleanup_formatter`: emit after all components (e.g. reset codes) - /// - `default_style`: where to reset when a component’s `reset` is true + /// - `default_style`: where to reset when a component's `reset` is true /// /// # Example + /// /// ```rust /// use azalea_chat::{FormattedText, DEFAULT_STYLE}; /// use serde::de::Deserialize; diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs index c43b7791..514944f1 100644 --- a/azalea-chat/src/style.rs +++ b/azalea-chat/src/style.rs @@ -497,7 +497,7 @@ impl Style { } /// Returns a new style that is a merge of self and other. - /// For any field that `other` does not specify (is None), self’s value is + /// For any field that `other` does not specify (is None), self's value is /// used. pub fn merged_with(&self, other: &Style) -> Style { Style { diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs index 13afe6b7..ae1d80bc 100644 --- a/azalea-chat/src/translatable_component.rs +++ b/azalea-chat/src/translatable_component.rs @@ -2,7 +2,10 @@ use std::fmt::{self, Display}; use serde::{Deserialize, Serialize}; #[cfg(feature = "simdnbt")] -use simdnbt::ToNbtTag; +use simdnbt::{ + ToNbtTag, + owned::{NbtList, NbtTag}, +}; use crate::{FormattedText, base_component::BaseComponent, text_component::TextComponent}; @@ -49,93 +52,12 @@ pub struct TranslatableComponent { } #[cfg(feature = "simdnbt")] -fn serialize_args_as_nbt(args: Vec) -> simdnbt::owned::NbtList { - let tags: Vec = args.into_iter().map(|arg| arg.to_nbt_tag()).collect(); - - if let Some(first_element) = tags.first() { - let tags = tags.clone(); - let homogenous_list = match first_element { - simdnbt::owned::NbtTag::Byte(_) => tags - .into_iter() - .map(|tag| tag.into_byte()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Short(_) => tags - .into_iter() - .map(|tag| tag.into_short()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Int(_) => tags - .into_iter() - .map(|tag| tag.into_int()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Long(_) => tags - .into_iter() - .map(|tag| tag.into_long()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Float(_) => tags - .into_iter() - .map(|tag| tag.into_float()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Double(_) => tags - .into_iter() - .map(|tag| tag.into_double()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::ByteArray(_) => tags - .into_iter() - .map(|tag| tag.into_byte_array()) - .collect::>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::String(_) => tags - .into_iter() - .map(|tag| tag.into_string()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::List(_) => tags - .into_iter() - .map(|tag| tag.into_list()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Compound(_) => tags - .into_iter() - .map(|tag| tag.into_compound()) - .collect::>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::IntArray(_) => tags - .into_iter() - .map(|tag| tag.into_int_array()) - .collect::>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::LongArray(_) => tags - .into_iter() - .map(|tag| tag.into_long_array()) - .collect::>>>() - .map(simdnbt::owned::NbtList::from), - }; - - if let Some(homogenous_list) = homogenous_list { - return homogenous_list; - } - } - - let mut compounds = Vec::with_capacity(tags.len()); - for tag in tags { - let compound = if let simdnbt::owned::NbtTag::Compound(compound) = tag { - compound - } else { - let mut compound = simdnbt::owned::NbtCompound::new(); - compound.insert("", tag); - compound - }; - - compounds.push(compound); - } - - compounds.into() +fn serialize_args_as_nbt(args: Vec) -> NbtList { + let tags = args + .into_iter() + .map(|arg| arg.to_nbt_tag()) + .collect::>(); + NbtList::from(tags) } #[cfg(feature = "simdnbt")] -- cgit v1.2.3