aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-05-30 19:36:59 -0800
committermat <git@matdoes.dev>2025-05-30 19:36:59 -0800
commitae4b1e85e669bc882d158509ef1eda46c6b2a72e (patch)
treeadf81cc01b0ce1575e95b99ad109fd92db1738f6 /azalea-chat/src
parenta64c6505049082175224802c5be51ac8f0cf4677 (diff)
downloadazalea-drasl-ae4b1e85e669bc882d158509ef1eda46c6b2a72e.tar.xz
fix clippy issues and improve formatting everywhere
Diffstat (limited to 'azalea-chat/src')
-rw-r--r--azalea-chat/src/component.rs38
-rw-r--r--azalea-chat/src/numbers.rs4
-rw-r--r--azalea-chat/src/style.rs18
-rw-r--r--azalea-chat/src/text_component.rs14
-rw-r--r--azalea-chat/src/translatable_component.rs6
5 files changed, 41 insertions, 39 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 8eaaf178..c04aac4e 100644
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -1,4 +1,8 @@
-use std::{fmt::Display, sync::LazyLock};
+use std::{
+ fmt::{self, Display},
+ io::{self, Cursor, Write},
+ sync::LazyLock,
+};
#[cfg(feature = "azalea-buf")]
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
@@ -269,13 +273,12 @@ impl<'de> Deserialize<'de> for FormattedText {
// string to with_array otherwise add the component
// to the array
let c = FormattedText::deserialize(item).map_err(de::Error::custom)?;
- if let FormattedText::Text(text_component) = c {
- if text_component.base.siblings.is_empty()
- && text_component.base.style.is_empty()
- {
- with_array.push(StringOrComponent::String(text_component.text));
- continue;
- }
+ if let FormattedText::Text(text_component) = c
+ && text_component.base.siblings.is_empty()
+ && text_component.base.style.is_empty()
+ {
+ with_array.push(StringOrComponent::String(text_component.text));
+ continue;
}
with_array.push(StringOrComponent::FormattedText(
FormattedText::deserialize(item).map_err(de::Error::custom)?,
@@ -465,13 +468,12 @@ impl FormattedText {
with_array.push(StringOrComponent::String("?".to_string()));
}
} else if let Some(c) = FormattedText::from_nbt_compound(item) {
- if let FormattedText::Text(text_component) = c {
- if text_component.base.siblings.is_empty()
- && text_component.base.style.is_empty()
- {
- with_array.push(StringOrComponent::String(text_component.text));
- continue;
- }
+ if let FormattedText::Text(text_component) = c
+ && text_component.base.siblings.is_empty()
+ && text_component.base.style.is_empty()
+ {
+ with_array.push(StringOrComponent::String(text_component.text));
+ continue;
}
with_array.push(StringOrComponent::FormattedText(
FormattedText::from_nbt_compound(item)?,
@@ -547,7 +549,7 @@ impl From<&simdnbt::Mutf8Str> for FormattedText {
#[cfg(feature = "azalea-buf")]
#[cfg(feature = "simdnbt")]
impl AzaleaRead for FormattedText {
- fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, BufReadError> {
+ fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let nbt = simdnbt::borrow::read_optional_tag(buf)?;
match nbt {
Some(nbt) => FormattedText::from_nbt_tag(nbt.as_tag()).ok_or(BufReadError::Custom(
@@ -561,7 +563,7 @@ impl AzaleaRead for FormattedText {
#[cfg(feature = "azalea-buf")]
#[cfg(feature = "simdnbt")]
impl AzaleaWrite for FormattedText {
- fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
+ fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
let mut out = Vec::new();
simdnbt::owned::BaseNbt::write_unnamed(&(self.clone().to_compound().into()), &mut out);
buf.write_all(&out)
@@ -583,7 +585,7 @@ impl From<&str> for FormattedText {
}
impl Display for FormattedText {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FormattedText::Text(c) => c.fmt(f),
FormattedText::Translatable(c) => c.fmt(f),
diff --git a/azalea-chat/src/numbers.rs b/azalea-chat/src/numbers.rs
index 161f1177..d9499e26 100644
--- a/azalea-chat/src/numbers.rs
+++ b/azalea-chat/src/numbers.rs
@@ -1,7 +1,7 @@
//! Contains a few ways to style numbers. At the time of writing, Minecraft only
//! uses this for rendering scoreboard objectives.
-use std::io::{Cursor, Write};
+use std::io::{self, Cursor, Write};
#[cfg(feature = "azalea-buf")]
use azalea_buf::{AzaleaRead, AzaleaWrite};
@@ -35,7 +35,7 @@ impl AzaleaRead for NumberFormat {
#[cfg(feature = "azalea-buf")]
impl AzaleaWrite for NumberFormat {
- fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
match self {
NumberFormat::Blank => NumberFormatKind::Blank.azalea_write(buf)?,
NumberFormat::Styled { style } => {
diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs
index 3d068cb9..18176a3d 100644
--- a/azalea-chat/src/style.rs
+++ b/azalea-chat/src/style.rs
@@ -595,29 +595,29 @@ impl Style {
pub fn get_html_style(&self) -> String {
let mut style = String::new();
if let Some(color) = &self.color {
- style.push_str(&format!("color: {};", color.format_value()));
+ style.push_str(&format!("color:{};", color.format_value()));
}
if let Some(bold) = self.bold {
style.push_str(&format!(
- "font-weight: {};",
+ "font-weight:{};",
if bold { "bold" } else { "normal" }
));
}
if let Some(italic) = self.italic {
style.push_str(&format!(
- "font-style: {};",
+ "font-style:{};",
if italic { "italic" } else { "normal" }
));
}
if let Some(underlined) = self.underlined {
style.push_str(&format!(
- "text-decoration: {};",
+ "text-decoration:{};",
if underlined { "underline" } else { "none" }
));
}
if let Some(strikethrough) = self.strikethrough {
style.push_str(&format!(
- "text-decoration: {};",
+ "text-decoration:{};",
if strikethrough {
"line-through"
} else {
@@ -625,10 +625,10 @@ impl Style {
}
));
}
- if let Some(obfuscated) = self.obfuscated {
- if obfuscated {
- style.push_str("filter: blur(2px);");
- }
+ if let Some(obfuscated) = self.obfuscated
+ && obfuscated
+ {
+ style.push_str("filter:blur(2px);");
}
style
diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs
index 62547d0d..228dad3b 100644
--- a/azalea-chat/src/text_component.rs
+++ b/azalea-chat/src/text_component.rs
@@ -1,4 +1,4 @@
-use std::fmt::Display;
+use std::fmt::{self, Display};
use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
@@ -142,7 +142,7 @@ impl TextComponent {
}
impl Display for TextComponent {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// this contains the final string will all the ansi escape codes
for component in FormattedText::Text(self.clone()).into_iter() {
let component_text = match &component {
@@ -191,9 +191,9 @@ mod tests {
format!(
"{GREEN}Hypixel Network {END_SPAN}{RED}[1.8-1.18]<br>{END_SPAN}{BOLD_AQUA}HAPPY HOLIDAYS{END_SPAN}",
END_SPAN = "</span>",
- GREEN = "<span style=\"color: #55FF55;\">",
- RED = "<span style=\"color: #FF5555;\">",
- BOLD_AQUA = "<span style=\"color: #55FFFF;font-weight: bold;\">",
+ GREEN = "<span style=\"color:#55FF55;\">",
+ RED = "<span style=\"color:#FF5555;\">",
+ BOLD_AQUA = "<span style=\"color:#55FFFF;font-weight: bold;\">",
)
);
}
@@ -207,8 +207,8 @@ mod tests {
format!(
"{GREEN}&lt;b&gt;&amp;<br>{END_SPAN}{AQUA}&lt;/b&gt;{END_SPAN}",
END_SPAN = "</span>",
- GREEN = "<span style=\"color: #55FF55;\">",
- AQUA = "<span style=\"color: #55FFFF;\">",
+ GREEN = "<span style=\"color:#55FF55;\">",
+ AQUA = "<span style=\"color:#55FFFF;\">",
)
);
}
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs
index 452de738..431c08b2 100644
--- a/azalea-chat/src/translatable_component.rs
+++ b/azalea-chat/src/translatable_component.rs
@@ -1,4 +1,4 @@
-use std::fmt::{self, Display, Formatter};
+use std::fmt::{self, Display};
use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
#[cfg(feature = "simdnbt")]
@@ -189,7 +189,7 @@ impl TranslatableComponent {
}
impl Display for TranslatableComponent {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// this contains the final string will all the ansi escape codes
for component in FormattedText::Translatable(self.clone()).into_iter() {
let component_text = match &component {
@@ -208,7 +208,7 @@ impl Display for TranslatableComponent {
}
impl Display for StringOrComponent {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
StringOrComponent::String(s) => write!(f, "{s}"),
StringOrComponent::FormattedText(c) => write!(f, "{c}"),