aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-02-22 23:01:54 +0000
committermat <git@matdoes.dev>2025-02-22 23:01:54 +0000
commit34f53baf85fb5c7163ec5d71a8ab9d45d3f271b6 (patch)
tree7920fec1203e8e96463a142f5f6da6164e76e684 /azalea-chat/src
parentbdd2fc91e11e2896d8e1c7046df247e1075bd40d (diff)
downloadazalea-drasl-34f53baf85fb5c7163ec5d71a8ab9d45d3f271b6.tar.xz
update to rust edition 2024
Diffstat (limited to 'azalea-chat/src')
-rwxr-xr-xazalea-chat/src/base_component.rs2
-rwxr-xr-xazalea-chat/src/component.rs19
-rwxr-xr-xazalea-chat/src/style.rs15
-rwxr-xr-xazalea-chat/src/text_component.rs4
-rwxr-xr-xazalea-chat/src/translatable_component.rs4
5 files changed, 26 insertions, 18 deletions
diff --git a/azalea-chat/src/base_component.rs b/azalea-chat/src/base_component.rs
index b01f2eb3..cbc5ae8b 100755
--- a/azalea-chat/src/base_component.rs
+++ b/azalea-chat/src/base_component.rs
@@ -1,6 +1,6 @@
use serde::Serialize;
-use crate::{style::Style, FormattedText};
+use crate::{FormattedText, style::Style};
#[derive(Clone, Debug, PartialEq, Serialize, Eq, Hash)]
pub struct BaseComponent {
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 4f772e36..e96ead43 100755
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -2,7 +2,7 @@ use std::{fmt::Display, sync::LazyLock};
#[cfg(feature = "azalea-buf")]
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
-use serde::{de, Deserialize, Deserializer, Serialize};
+use serde::{Deserialize, Deserializer, Serialize, de};
#[cfg(feature = "simdnbt")]
use simdnbt::{Deserialize as _, FromNbtTag as _, Serialize as _};
use tracing::{debug, trace, warn};
@@ -371,7 +371,9 @@ impl FormattedText {
} else if let Some(s) = primitive.string() {
with_array.push(StringOrComponent::String(s.to_string()));
} else {
- warn!("couldn't parse {item:?} as FormattedText because it has a disallowed primitive");
+ warn!(
+ "couldn't parse {item:?} as FormattedText because it has a disallowed primitive"
+ );
with_array.push(StringOrComponent::String("?".to_string()));
}
} else if let Some(c) = FormattedText::from_nbt_compound(item) {
@@ -392,7 +394,9 @@ impl FormattedText {
}
}
} else {
- warn!("couldn't parse {with:?} as FormattedText because it's not a list of compounds");
+ warn!(
+ "couldn't parse {with:?} as FormattedText because it's not a list of compounds"
+ );
return None;
}
component =
@@ -456,12 +460,11 @@ impl From<&simdnbt::Mutf8Str> for FormattedText {
impl AzaleaRead for FormattedText {
fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, BufReadError> {
let nbt = simdnbt::borrow::read_optional_tag(buf)?;
- if let Some(nbt) = nbt {
- FormattedText::from_nbt_tag(nbt.as_tag()).ok_or(BufReadError::Custom(
+ match nbt {
+ Some(nbt) => FormattedText::from_nbt_tag(nbt.as_tag()).ok_or(BufReadError::Custom(
"couldn't convert nbt to chat message".to_owned(),
- ))
- } else {
- Ok(FormattedText::default())
+ )),
+ _ => Ok(FormattedText::default()),
}
}
}
diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs
index 57fe76a0..26fa2633 100755
--- a/azalea-chat/src/style.rs
+++ b/azalea-chat/src/style.rs
@@ -2,7 +2,7 @@ use std::{collections::HashMap, fmt, sync::LazyLock};
#[cfg(feature = "azalea-buf")]
use azalea_buf::AzBuf;
-use serde::{ser::SerializeStruct, Serialize, Serializer};
+use serde::{Serialize, Serializer, ser::SerializeStruct};
use serde_json::Value;
#[cfg(feature = "simdnbt")]
use simdnbt::owned::{NbtCompound, NbtTag};
@@ -334,10 +334,15 @@ fn simdnbt_serialize_field(
default: impl simdnbt::ToNbtTag,
reset: bool,
) {
- if let Some(value) = value {
- compound.insert(name, value);
- } else if reset {
- compound.insert(name, default);
+ match value {
+ Some(value) => {
+ compound.insert(name, value);
+ }
+ _ => {
+ if reset {
+ compound.insert(name, default);
+ }
+ }
}
}
diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs
index d3418ad8..db1b4edf 100755
--- a/azalea-chat/src/text_component.rs
+++ b/azalea-chat/src/text_component.rs
@@ -1,8 +1,8 @@
use std::fmt::Display;
-use serde::{ser::SerializeMap, Serialize, Serializer, __private::ser::FlatMapSerializer};
+use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
-use crate::{base_component::BaseComponent, style::ChatFormatting, FormattedText};
+use crate::{FormattedText, base_component::BaseComponent, style::ChatFormatting};
/// A component that contains text that's the same in all locales.
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs
index ecd238a5..452de738 100755
--- a/azalea-chat/src/translatable_component.rs
+++ b/azalea-chat/src/translatable_component.rs
@@ -1,11 +1,11 @@
use std::fmt::{self, Display, Formatter};
-use serde::{ser::SerializeMap, Serialize, Serializer, __private::ser::FlatMapSerializer};
+use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
#[cfg(feature = "simdnbt")]
use simdnbt::Serialize as _;
use crate::{
- base_component::BaseComponent, style::Style, text_component::TextComponent, FormattedText,
+ FormattedText, base_component::BaseComponent, style::Style, text_component::TextComponent,
};
#[derive(Clone, Debug, PartialEq, Serialize, Eq, Hash)]