From 575f17948fd83c7b28b219c01329c492913f8917 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Sat, 10 May 2025 15:22:06 +0200 Subject: [PATCH] Inline format arguments Looks much nicer and more readable --- pumpkin-config/src/resource_pack.rs | 3 +- pumpkin-data/build/block.rs | 6 +-- pumpkin-data/build/damage_type.rs | 4 +- pumpkin-data/build/fluid.rs | 10 ++--- .../src/player/player_inventory.rs | 4 +- pumpkin-nbt/src/deserializer.rs | 3 +- pumpkin-nbt/src/nbt_compress.rs | 4 +- pumpkin-nbt/src/serializer.rs | 3 +- pumpkin-protocol/src/packet_decoder.rs | 5 +-- pumpkin-protocol/src/packet_encoder.rs | 9 ++-- pumpkin-protocol/src/ser/serializer.rs | 34 ++++++--------- pumpkin-util/src/noise/perlin.rs | 2 +- pumpkin-util/src/permission.rs | 3 +- pumpkin-util/src/registry.rs | 2 +- pumpkin-world/src/chunk/format/anvil.rs | 41 ++++++++----------- pumpkin-world/src/chunk/format/linear.rs | 2 +- .../src/chunk/io/chunk_file_manager.rs | 14 +++---- pumpkin-world/src/chunk/mod.rs | 2 +- pumpkin-world/src/data/player_data.rs | 22 ++++------ pumpkin-world/src/generation/biome.rs | 3 +- .../noise_router/proto_noise_router.rs | 2 +- pumpkin-world/src/level.rs | 18 ++++---- pumpkin/build.rs | 2 +- pumpkin/src/lib.rs | 23 ++++------- 24 files changed, 92 insertions(+), 129 deletions(-) diff --git a/pumpkin-config/src/resource_pack.rs b/pumpkin-config/src/resource_pack.rs index 2b5f2eb8a..156fc97a4 100644 --- a/pumpkin-config/src/resource_pack.rs +++ b/pumpkin-config/src/resource_pack.rs @@ -29,8 +29,7 @@ impl ResourcePackConfig { let hash_len = self.sha1.len(); assert!( hash_len == 40, - "Resource pack SHA1 hash is the wrong length (should be 40, is {})", - hash_len + "Resource pack SHA1 hash is the wrong length (should be 40, is {hash_len})" ) } } diff --git a/pumpkin-data/build/block.rs b/pumpkin-data/build/block.rs index ae8f62480..bf048d579 100644 --- a/pumpkin-data/build/block.rs +++ b/pumpkin-data/build/block.rs @@ -11,7 +11,7 @@ fn const_block_name_from_block_name(block: &str) -> String { } fn property_group_name_from_derived_name(name: &str) -> String { - format!("{}_properties", name).to_upper_camel_case() + format!("{name}_properties").to_upper_camel_case() } enum PropertyType { @@ -1015,7 +1015,7 @@ impl GeneratedProperty { fn to_property(&self) -> Property { let enum_name = match &self.property_type { GeneratedPropertyType::Boolean => "boolean".to_string(), - GeneratedPropertyType::Int { min, max } => format!("integer_{}_to_{}", min, max), + GeneratedPropertyType::Int { min, max } => format!("integer_{min}_to_{max}"), GeneratedPropertyType::Enum { .. } => self.enum_name.clone(), }; @@ -1026,7 +1026,7 @@ impl GeneratedProperty { GeneratedPropertyType::Int { min, max } => { let mut values = Vec::new(); for i in *min..=*max { - values.push(format!("L{}", i)); + values.push(format!("L{i}")); } values } diff --git a/pumpkin-data/build/damage_type.rs b/pumpkin-data/build/damage_type.rs index 1b304fa80..936ccb7be 100644 --- a/pumpkin-data/build/damage_type.rs +++ b/pumpkin-data/build/damage_type.rs @@ -68,7 +68,7 @@ pub(crate) fn build() -> TokenStream { let data = &entry.components; let death_message_type = match &data.death_message_type { Some(msg) => { - let msg_ident = Ident::new(&format!("{:?}", msg), proc_macro2::Span::call_site()); + let msg_ident = Ident::new(&format!("{msg:?}"), proc_macro2::Span::call_site()); quote! { Some(DeathMessageType::#msg_ident) } } None => quote! { None }, @@ -76,7 +76,7 @@ pub(crate) fn build() -> TokenStream { let effects = match &data.effects { Some(msg) => { - let msg_ident = Ident::new(&format!("{:?}", msg), proc_macro2::Span::call_site()); + let msg_ident = Ident::new(&format!("{msg:?}"), proc_macro2::Span::call_site()); quote! { Some(DamageEffects::#msg_ident) } } None => quote! { None }, diff --git a/pumpkin-data/build/fluid.rs b/pumpkin-data/build/fluid.rs index 5545afdd6..bd3efa269 100644 --- a/pumpkin-data/build/fluid.rs +++ b/pumpkin-data/build/fluid.rs @@ -10,7 +10,7 @@ fn const_fluid_name_from_fluid_name(fluid: &str) -> String { } fn property_group_name_from_derived_name(name: &str) -> String { - format!("{}_fluid_properties", name).to_upper_camel_case() + format!("{name}_fluid_properties").to_upper_camel_case() } struct PropertyVariantMapping { @@ -55,7 +55,7 @@ impl ToTokens for PropertyStruct { let ident_values = self.values.iter().map(|value| { let value_str = if value.chars().all(|c| c.is_numeric()) { - format!("L{}", value) + format!("L{value}") } else { value.clone() }; @@ -67,7 +67,7 @@ impl ToTokens for PropertyStruct { let from_values = self.values.iter().map(|value| { let value_str = if value.chars().all(|c| c.is_numeric()) { - format!("L{}", value) + format!("L{value}") } else { value.clone() }; @@ -78,7 +78,7 @@ impl ToTokens for PropertyStruct { }); let to_values = self.values.iter().map(|value| { let value_str = if value.chars().all(|c| c.is_numeric()) { - format!("L{}", value) + format!("L{value}") } else { value.clone() }; @@ -345,7 +345,7 @@ pub(crate) fn build() -> TokenStream { let fluids: Vec = match serde_json::from_str(include_str!("../../assets/fluids.json")) { Ok(fluids) => fluids, - Err(e) => panic!("Failed to parse fluids.json: {}", e), + Err(e) => panic!("Failed to parse fluids.json: {e}"), }; let mut constants = TokenStream::new(); diff --git a/pumpkin-inventory/src/player/player_inventory.rs b/pumpkin-inventory/src/player/player_inventory.rs index c4a1336a7..ec3f7f8c9 100644 --- a/pumpkin-inventory/src/player/player_inventory.rs +++ b/pumpkin-inventory/src/player/player_inventory.rs @@ -384,7 +384,7 @@ impl Inventory for PlayerInventory { Some(slot) => { self.entity_equipment.lock().await.put(slot, stack).await; } - None => log::warn!("Failed to get Equipment Slot at {0}", slot), + None => log::warn!("Failed to get Equipment Slot at {slot}"), } } } @@ -398,7 +398,7 @@ impl PlayerInventory { self.selected_slot .store(slot, std::sync::atomic::Ordering::Relaxed); } else { - panic!("Invalid hotbar slot: {}", slot); + panic!("Invalid hotbar slot: {slot}"); } } diff --git a/pumpkin-nbt/src/deserializer.rs b/pumpkin-nbt/src/deserializer.rs index 0e2007e62..7859ef3ec 100644 --- a/pumpkin-nbt/src/deserializer.rs +++ b/pumpkin-nbt/src/deserializer.rs @@ -274,8 +274,7 @@ impl<'de, R: Read> de::Deserializer<'de> for &mut Deserializer { } } else { Err(Error::UnsupportedType(format!( - "Non-byte bool (found type {})", - tag_id + "Non-byte bool (found type {tag_id})" ))) } } else { diff --git a/pumpkin-nbt/src/nbt_compress.rs b/pumpkin-nbt/src/nbt_compress.rs index 72b1071fd..909e99808 100644 --- a/pumpkin-nbt/src/nbt_compress.rs +++ b/pumpkin-nbt/src/nbt_compress.rs @@ -203,7 +203,7 @@ mod tests { // Add 1000 integer entries for i in 0..1000 { - compound.put_int(&format!("value_{}", i), i); + compound.put_int(&format!("value_{i}"), i); } let mut buffer = Vec::new(); @@ -281,7 +281,7 @@ mod tests { let mut buffer = Vec::new(); write_gzip_compound_tag(&compound, &mut buffer).expect("Failed to compress compound"); - println!("Uncompressed size (est): {} bytes", uncompressed); + println!("Uncompressed size (est): {uncompressed} bytes"); println!("Compressed size: {} bytes", buffer.len()); println!( "Compression ratio: {:.2}x", diff --git a/pumpkin-nbt/src/serializer.rs b/pumpkin-nbt/src/serializer.rs index b4dc46a91..b571a1f16 100644 --- a/pumpkin-nbt/src/serializer.rs +++ b/pumpkin-nbt/src/serializer.rs @@ -154,8 +154,7 @@ impl Serializer { } else { if tag != COMPOUND_ID { return Err(Error::SerdeError(format!( - "Invalid state: root is not a `Compound`! ({})", - tag + "Invalid state: root is not a `Compound`! ({tag})" ))); } self.handled_root = true; diff --git a/pumpkin-protocol/src/packet_decoder.rs b/pumpkin-protocol/src/packet_decoder.rs index d78cbd8f9..af391340a 100644 --- a/pumpkin-protocol/src/packet_decoder.rs +++ b/pumpkin-protocol/src/packet_decoder.rs @@ -421,10 +421,7 @@ mod tests { // Build the packet with compression enabled let packet = build_packet(packet_id, &payload, true, None, None); - println!( - "Built packet (with compression, maximum length): {:?}", - packet - ); + println!("Built packet (with compression, maximum length): {packet:?}"); // Initialize the decoder with compression enabled let mut decoder = NetworkDecoder::new(packet.as_slice()); diff --git a/pumpkin-protocol/src/packet_encoder.rs b/pumpkin-protocol/src/packet_encoder.rs index d42c7bca7..6308b6143 100644 --- a/pumpkin-protocol/src/packet_encoder.rs +++ b/pumpkin-protocol/src/packet_encoder.rs @@ -146,8 +146,7 @@ impl NetworkEncoder { } let data_len_var_int: VarInt = data_len.try_into().map_err(|_| { PacketEncodeError::Message(format!( - "Packet data length is too large to fit in VarInt! ({})", - data_len + "Packet data length is too large to fit in VarInt! ({data_len})" )) })?; @@ -180,8 +179,7 @@ impl NetworkEncoder { .try_into() .map_err(|_| { PacketEncodeError::Message(format!( - "Full packet length is too large to fit in VarInt! ({})", - data_len + "Full packet length is too large to fit in VarInt! ({data_len})" )) })?; @@ -213,8 +211,7 @@ impl NetworkEncoder { .try_into() .map_err(|_| { PacketEncodeError::Message(format!( - "Full packet length is too large to fit in VarInt! ({})", - data_len + "Full packet length is too large to fit in VarInt! ({data_len})" )) })?; diff --git a/pumpkin-protocol/src/ser/serializer.rs b/pumpkin-protocol/src/ser/serializer.rs index 9d9aa3373..ebd974963 100644 --- a/pumpkin-protocol/src/ser/serializer.rs +++ b/pumpkin-protocol/src/ser/serializer.rs @@ -98,8 +98,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { T: ?Sized + Serialize, { Err(WritingError::Serde(format!( - "Expected a sequence but found a newtype struct {}!", - name + "Expected a sequence but found a newtype struct {name}!" ))) } @@ -114,8 +113,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { T: ?Sized + Serialize, { Err(WritingError::Serde(format!( - "Expected a sequence but found a newtype variant {}!", - name + "Expected a sequence but found a newtype variant {name}!" ))) } @@ -141,8 +139,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { _len: usize, ) -> Result { Err(WritingError::Serde(format!( - "Expected a sequence but found a struct {}!", - name + "Expected a sequence but found a struct {name}!" ))) } @@ -154,8 +151,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { _len: usize, ) -> Result { Err(WritingError::Serde(format!( - "Expected a sequence but found a struct variant {}!", - name + "Expected a sequence but found a struct variant {name}!" ))) } @@ -171,8 +167,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { _len: usize, ) -> Result { Err(WritingError::Serde(format!( - "Expected a sequence but found a tuple struct {}!", - name + "Expected a sequence but found a tuple struct {name}!" ))) } @@ -184,8 +179,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { _len: usize, ) -> Result { Err(WritingError::Serde(format!( - "Expected a sequence but found a tuple variant {}!", - name + "Expected a sequence but found a tuple variant {name}!" ))) } @@ -197,8 +191,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { fn serialize_unit_struct(self, name: &'static str) -> Result { Err(WritingError::Serde(format!( - "Expected a sequence but found a unit struct {}!", - name + "Expected a sequence but found a unit struct {name}!" ))) } @@ -209,8 +202,7 @@ impl ser::Serializer for NonPrefixedSeqSerializer<'_, W> { _variant: &'static str, ) -> Result { Err(WritingError::Serde(format!( - "Expected a sequence but found a unit variant {}!", - name + "Expected a sequence but found a unit variant {name}!" ))) } } @@ -282,7 +274,7 @@ impl ser::Serializer for &mut Serializer { let mut nbt_serializer = pumpkin_nbt::serializer::Serializer::new(&mut self.write, None); value.serialize(&mut nbt_serializer).map_err(|err| { - WritingError::Serde(format!("Failed to serialize TextComponent NBT: {}", err)) + WritingError::Serde(format!("Failed to serialize TextComponent NBT: {err}")) }) } else if name == NO_PREFIX_MARKER { value.serialize(NonPrefixedSeqSerializer { wrapped: self }) @@ -302,7 +294,7 @@ impl ser::Serializer for &mut Serializer { { self.write .write_var_int(&variant_index.try_into().map_err(|_| { - WritingError::Message(format!("{} isn't representable as a VarInt", variant_index)) + WritingError::Message(format!("{variant_index} isn't representable as a VarInt")) })?)?; value.serialize(self) } @@ -317,7 +309,7 @@ impl ser::Serializer for &mut Serializer { }; self.write.write_var_int(&len.try_into().map_err(|_| { - WritingError::Message(format!("{} isn't representable as a VarInt", len)) + WritingError::Message(format!("{len} isn't representable as a VarInt")) })?)?; Ok(self) @@ -368,7 +360,7 @@ impl ser::Serializer for &mut Serializer { // Serialize ENUM index as varint self.write .write_var_int(&variant_index.try_into().map_err(|_| { - WritingError::Message(format!("{} isn't representable as a VarInt", variant_index)) + WritingError::Message(format!("{variant_index} isn't representable as a VarInt")) })?)?; Ok(self) } @@ -402,7 +394,7 @@ impl ser::Serializer for &mut Serializer { // For ENUMs, only write enum index as varint self.write .write_var_int(&variant_index.try_into().map_err(|_| { - WritingError::Message(format!("{} isn't representable as a VarInt", variant_index)) + WritingError::Message(format!("{variant_index} isn't representable as a VarInt")) })?) } fn is_human_readable(&self) -> bool { diff --git a/pumpkin-util/src/noise/perlin.rs b/pumpkin-util/src/noise/perlin.rs index 67ad9aecf..d49f5c99b 100644 --- a/pumpkin-util/src/noise/perlin.rs +++ b/pumpkin-util/src/noise/perlin.rs @@ -228,7 +228,7 @@ impl OctavePerlinNoiseSampler { if amplitudes[k] != 0f64 { let l = first_octave + k as i32; samplers[k] = Some(PerlinNoiseSampler::new( - &mut splitter.split_string(&format!("octave_{}", l)), + &mut splitter.split_string(&format!("octave_{l}")), )); } } diff --git a/pumpkin-util/src/permission.rs b/pumpkin-util/src/permission.rs index 8ecfa589e..cb589bc4d 100644 --- a/pumpkin-util/src/permission.rs +++ b/pumpkin-util/src/permission.rs @@ -52,8 +52,7 @@ impl<'de> Deserialize<'de> for PermissionLvl { 3 => Ok(PermissionLvl::Three), 4 => Ok(PermissionLvl::Four), _ => Err(serde::de::Error::custom(format!( - "Invalid value for OpLevel: {}", - value + "Invalid value for OpLevel: {value}" ))), } } diff --git a/pumpkin-util/src/registry.rs b/pumpkin-util/src/registry.rs index d39286aec..6a0d882e9 100644 --- a/pumpkin-util/src/registry.rs +++ b/pumpkin-util/src/registry.rs @@ -13,7 +13,7 @@ impl TagType { pub fn serialize(&self) -> String { match self { TagType::Item(name) => name.clone(), - TagType::Tag(tag) => format!("#{}", tag), + TagType::Tag(tag) => format!("#{tag}"), } } } diff --git a/pumpkin-world/src/chunk/format/anvil.rs b/pumpkin-world/src/chunk/format/anvil.rs index 27dc972e2..a7289c5ad 100644 --- a/pumpkin-world/src/chunk/format/anvil.rs +++ b/pumpkin-world/src/chunk/format/anvil.rs @@ -354,7 +354,7 @@ impl AnvilChunkFile { } async fn write_indices(&self, path: &Path, indices: &[usize]) -> Result<(), std::io::Error> { - log::trace!("Writing in place: {:?}", path); + log::trace!("Writing in place: {path:?}"); let file = tokio::fs::OpenOptions::new() .read(false) @@ -454,7 +454,7 @@ impl AnvilChunkFile { /// Write entire file, disregarding saved offsets async fn write_all(&self, path: &Path) -> Result<(), std::io::Error> { let temp_path = path.with_extension("tmp"); - log::trace!("Writing tmp file to disk: {:?}", temp_path); + log::trace!("Writing tmp file to disk: {temp_path:?}"); let file = tokio::fs::OpenOptions::new() .read(false) @@ -500,7 +500,7 @@ impl AnvilChunkFile { // that the data is not corrupted before the rename is completed tokio::fs::rename(temp_path, path).await?; - log::trace!("Wrote file to Disk: {:?}", path); + log::trace!("Wrote file to Disk: {path:?}"); Ok(()) } } @@ -527,17 +527,14 @@ impl ChunkSerializer for AnvilChunkFile { fn get_chunk_key(chunk: &Vector2) -> String { let (region_x, region_z) = Self::get_region_coords(chunk); - format!("./r.{}.{}.mca", region_x, region_z) + format!("./r.{region_x}.{region_z}.mca") } async fn write(&self, path: PathBuf) -> Result<(), std::io::Error> { let mut write_action = self.write_action.lock().await; match &*write_action { WriteAction::Pass => { - log::debug!( - "Skipping write for {:?} as there were no dirty chunks", - path - ); + log::debug!("Skipping write for {path:?} as there were no dirty chunks"); Ok(()) } WriteAction::All => self.write_all(&path).await, @@ -757,11 +754,7 @@ impl ChunkSerializer for AnvilChunkFile { let offset = new_sectors as i64 - swapped_sectors as i64; log::trace!( - "Swapping {} with {}, shifting all chunks {} and after by {}", - index, - swapped_index, - swapped_index, - offset + "Swapping {index} with {swapped_index}, shifting all chunks {swapped_index} and after by {offset}" ); for shift_index in indices_to_shift { @@ -946,7 +939,7 @@ mod tests { LoadedData::Loaded(chunk) => chunk, LoadedData::Missing(_) => panic!("Missing chunk"), LoadedData::Error((position, error)) => { - panic!("Error reading chunk at {:?} | Error: {:?}", position, error) + panic!("Error reading chunk at {position:?} | Error: {error:?}") } }) .collect::>(); @@ -1034,7 +1027,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); @@ -1047,7 +1040,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); break; @@ -1092,7 +1085,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); @@ -1105,7 +1098,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); @@ -1165,7 +1158,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); @@ -1178,7 +1171,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); @@ -1226,7 +1219,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); @@ -1239,7 +1232,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); break; @@ -1307,7 +1300,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); @@ -1320,7 +1313,7 @@ mod tests { .enumerate() .for_each(|(i, (o, r))| { if o != r { - panic!("Data miss-match expected {}, got {} ({})", o, r, i); + panic!("Data miss-match expected {o}, got {r} ({i})"); } }); break; diff --git a/pumpkin-world/src/chunk/format/linear.rs b/pumpkin-world/src/chunk/format/linear.rs index 7b91467ad..4b1f8a635 100644 --- a/pumpkin-world/src/chunk/format/linear.rs +++ b/pumpkin-world/src/chunk/format/linear.rs @@ -169,7 +169,7 @@ impl ChunkSerializer for LinearFile { fn get_chunk_key(chunk: &Vector2) -> String { let (region_x, region_z) = AnvilChunkFile::get_region_coords(chunk); - format!("./r.{}.{}.linear", region_x, region_z) + format!("./r.{region_x}.{region_z}.linear") } async fn write(&self, path: PathBuf) -> Result<(), std::io::Error> { diff --git a/pumpkin-world/src/chunk/io/chunk_file_manager.rs b/pumpkin-world/src/chunk/io/chunk_file_manager.rs index b4e3872c5..124cc4768 100644 --- a/pumpkin-world/src/chunk/io/chunk_file_manager.rs +++ b/pumpkin-world/src/chunk/io/chunk_file_manager.rs @@ -277,7 +277,7 @@ where .into_iter() .map(async |(file_name, chunk_locks)| { let path = Self::map_key(folder, &file_name); - log::trace!("Updating data for file {:?}", path); + log::trace!("Updating data for file {path:?}"); let chunk_serializer = match self.get_serializer(&path).await { Ok(file) => Ok(file), @@ -285,11 +285,11 @@ where unreachable!("Must be managed by the cache") } Err(ChunkReadingError::IoError(err)) => { - error!("Error reading the data before write: {}", err); + error!("Error reading the data before write: {err}"); Err(ChunkWritingError::IoError(err)) } Err(err) => { - error!("Error reading the data before write: {:?}", err); + error!("Error reading the data before write: {err:?}"); Err(ChunkWritingError::IoError(std::io::ErrorKind::Other)) } }?; @@ -310,7 +310,7 @@ where serializer.update_chunk(&*chunk).await?; } } - log::trace!("Updated data for file {:?}", path); + log::trace!("Updated data for file {path:?}"); let is_watched = self .watchers @@ -324,7 +324,7 @@ where // to avoid other threads to write/modify the data, but allow other threads to read it let serializer = serializer.downgrade(); - log::debug!("Writing file for {:?}", path); + log::debug!("Writing file for {path:?}"); serializer .write(path.clone()) .await @@ -353,9 +353,9 @@ where if can_remove { locks.remove(&path); - log::trace!("Removed lockfile cache {:?}", path); + log::trace!("Removed lockfile cache {path:?}"); } else { - log::trace!("Wanted to remove lockfile cache {:?} but someone still holds a reference to it!", path); + log::trace!("Wanted to remove lockfile cache {path:?} but someone still holds a reference to it!"); } } } diff --git a/pumpkin-world/src/chunk/mod.rs b/pumpkin-world/src/chunk/mod.rs index 5fbbb072d..94a6ce97f 100644 --- a/pumpkin-world/src/chunk/mod.rs +++ b/pumpkin-world/src/chunk/mod.rs @@ -95,7 +95,7 @@ impl From for TickPriority { 1 => TickPriority::Low, 2 => TickPriority::VeryLow, 3 => TickPriority::ExtremelyLow, - _ => panic!("Invalid tick priority: {}", value), + _ => panic!("Invalid tick priority: {value}"), } } } diff --git a/pumpkin-world/src/data/player_data.rs b/pumpkin-world/src/data/player_data.rs index 3cac3e2d6..2eae326f2 100644 --- a/pumpkin-world/src/data/player_data.rs +++ b/pumpkin-world/src/data/player_data.rs @@ -30,11 +30,7 @@ impl PlayerDataStorage { let path = data_path.into(); if !path.exists() { if let Err(e) = create_dir_all(&path) { - log::error!( - "Failed to create player data directory at {:?}: {}", - path, - e - ); + log::error!("Failed to create player data directory at {path:?}: {e}"); } } @@ -84,25 +80,25 @@ impl PlayerDataStorage { // If not in cache, load from disk let path = self.get_player_data_path(uuid); if !path.exists() { - log::debug!("No player data file found for {}", uuid); + log::debug!("No player data file found for {uuid}"); return Ok((false, NbtCompound::new())); } let file = match File::open(&path) { Ok(file) => file, Err(e) => { - log::error!("Failed to open player data file for {}: {}", uuid, e); + log::error!("Failed to open player data file for {uuid}: {e}"); return Err(PlayerDataError::Io(e)); } }; match pumpkin_nbt::nbt_compress::read_gzip_compound_tag(file) { Ok(nbt) => { - log::debug!("Loaded player data for {} from disk", uuid); + log::debug!("Loaded player data for {uuid} from disk"); Ok((true, nbt)) } Err(e) => { - log::error!("Failed to read player data for {}: {}", uuid, e); + log::error!("Failed to read player data for {uuid}: {e}"); Err(PlayerDataError::Nbt(e.to_string())) } } @@ -132,7 +128,7 @@ impl PlayerDataStorage { // Ensure parent directory exists if let Some(parent) = path.parent() { if let Err(e) = create_dir_all(parent) { - log::error!("Failed to create player data directory for {}: {}", uuid, e); + log::error!("Failed to create player data directory for {uuid}: {e}"); return Err(PlayerDataError::Io(e)); } } @@ -141,15 +137,15 @@ impl PlayerDataStorage { match File::create(&path) { Ok(file) => { if let Err(e) = pumpkin_nbt::nbt_compress::write_gzip_compound_tag(&data, file) { - log::error!("Failed to write compressed player data for {}: {}", uuid, e); + log::error!("Failed to write compressed player data for {uuid}: {e}"); Err(PlayerDataError::Nbt(e.to_string())) } else { - log::debug!("Saved player data for {} to disk", uuid); + log::debug!("Saved player data for {uuid} to disk"); Ok(()) } } Err(e) => { - log::error!("Failed to create player data file for {}: {}", uuid, e); + log::error!("Failed to create player data file for {uuid}: {e}"); Err(PlayerDataError::Io(e)) } } diff --git a/pumpkin-world/src/generation/biome.rs b/pumpkin-world/src/generation/biome.rs index ebfc42c07..542d0095a 100644 --- a/pumpkin-world/src/generation/biome.rs +++ b/pumpkin-world/src/generation/biome.rs @@ -194,8 +194,7 @@ mod test { let expected = Vector3::new(result_x, result_y, result_z); assert_eq!( result, expected, - "Expected: {:?}, was: {:?} ({})", - expected, result, i + "Expected: {expected:?}, was: {result:?} ({i})" ); } } diff --git a/pumpkin-world/src/generation/noise_router/proto_noise_router.rs b/pumpkin-world/src/generation/noise_router/proto_noise_router.rs index 08d940b09..df8a95948 100644 --- a/pumpkin-world/src/generation/noise_router/proto_noise_router.rs +++ b/pumpkin-world/src/generation/noise_router/proto_noise_router.rs @@ -70,7 +70,7 @@ impl<'a> DoublePerlinNoiseBuilder<'a> { pub fn get_noise_sampler_for_id(&mut self, id: &str) -> DoublePerlinNoiseSampler { let parameters = DoublePerlinNoiseParameters::id_to_parameters(id) - .unwrap_or_else(|| panic!("Unknown noise id: {}", id)); + .unwrap_or_else(|| panic!("Unknown noise id: {id}")); // Note that the parameters' id is different than `id` let mut random = self diff --git a/pumpkin-world/src/level.rs b/pumpkin-world/src/level.rs index 51629e9ae..1dd687360 100644 --- a/pumpkin-world/src/level.rs +++ b/pumpkin-world/src/level.rs @@ -100,11 +100,11 @@ impl Level { WorldInfoError::InfoNotFound => (), WorldInfoError::UnsupportedVersion(version) => { log::error!("Failed to load world info!, {version}"); - log::error!("{}", error); + log::error!("{error}"); panic!("Unsupported world data! See the logs for more info."); } e => { - panic!("World Error {}", e); + panic!("World Error {e}"); } } } else { @@ -189,7 +189,7 @@ impl Level { // Lets not stop the overall save for this if let Err(err) = result { - log::error!("Failed to save level.dat: {}", err); + log::error!("Failed to save level.dat: {err}"); } } @@ -212,7 +212,7 @@ impl Level { /// before pub async fn mark_chunks_as_newly_watched(&self, chunks: &[Vector2]) { for chunk in chunks { - log::trace!("{:?} marked as newly watched", chunk); + log::trace!("{chunk:?} marked as newly watched"); match self.chunk_watchers.entry(*chunk) { Entry::Occupied(mut occupied) => { let value = occupied.get_mut(); @@ -220,7 +220,7 @@ impl Level { *value = new_value; //log::debug!("Watch value for {:?}: {}", chunk, value); } else { - log::error!("Watching overflow on chunk {:?}", chunk); + log::error!("Watching overflow on chunk {chunk:?}"); } } Entry::Vacant(vacant) => { @@ -245,7 +245,7 @@ impl Level { let mut chunks_to_clean = Vec::new(); for chunk in chunks { - log::trace!("{:?} marked as no longer watched", chunk); + log::trace!("{chunk:?} marked as no longer watched"); match self.chunk_watchers.entry(*chunk) { Entry::Occupied(mut occupied) => { let value = occupied.get_mut(); @@ -391,7 +391,7 @@ impl Level { .save_chunks(&level_folder, chunks_to_write) .await { - log::error!("Failed writing Chunk to disk {}", error); + log::error!("Failed writing Chunk to disk {error}"); } } @@ -501,9 +501,7 @@ impl Level { // this is an error, and we should log it error => { log::error!( - "Failed to load chunk at {:?}: {} (regenerating)", - pos, - error + "Failed to load chunk at {pos:?}: {error} (regenerating)" ); } }; diff --git a/pumpkin/build.rs b/pumpkin/build.rs index 7caffd0c8..c71a81e6e 100644 --- a/pumpkin/build.rs +++ b/pumpkin/build.rs @@ -15,5 +15,5 @@ fn main() { "unknown" => env::var("GIT_VERSION").unwrap_or("unknown".to_string()), _ => version.to_string(), }; - println!("cargo:rustc-env=GIT_VERSION={}", git_version); + println!("cargo:rustc-env=GIT_VERSION={git_version}"); } diff --git a/pumpkin/src/lib.rs b/pumpkin/src/lib.rs index b9a7f0379..b9408539a 100644 --- a/pumpkin/src/lib.rs +++ b/pumpkin/src/lib.rs @@ -142,8 +142,7 @@ pub static LOGGER_IMPL: LazyLock> = La } Err(e) => { log::warn!( - "Failed to initialize console input ({}); falling back to simple logger", - e + "Failed to initialize console input ({e}); falling back to simple logger" ); let logger = simplelog::SimpleLogger::new(level, config.build()); Some((ReadlineLogWrapper::new(logger, None), level)) @@ -261,7 +260,7 @@ impl PumpkinServer { let mut loader_lock = PLUGIN_MANAGER.lock().await; loader_lock.set_server(self.server.clone()); if let Err(err) = loader_lock.load_plugins().await { - log::error!("{}", err); + log::error!("{err}"); }; } @@ -297,11 +296,7 @@ impl PumpkinServer { } else { format!("{client_addr}") }; - log::debug!( - "Accepted connection from: {} (id {})", - formatted_address, - id - ); + log::debug!("Accepted connection from: {formatted_address} (id {id})"); let mut client = Client::new(connection, client_addr, id); client.init(); @@ -325,7 +320,7 @@ impl PumpkinServer { player.close().await; //TODO: Move these somewhere less likely to be forgotten - log::debug!("Cleaning up player for id {}", id); + log::debug!("Cleaning up player for id {id}"); // Save player data on disconnect if let Err(e) = server @@ -333,7 +328,7 @@ impl PumpkinServer { .handle_player_leave(&player) .await { - log::error!("Failed to save player data on disconnect: {}", e); + log::error!("Failed to save player data on disconnect: {e}"); } // Remove the player from its world @@ -345,9 +340,9 @@ impl PumpkinServer { // Also handle case of client connects but does not become a player (like a server // ping) client.close(); - log::debug!("Awaiting tasks for client {}", id); + log::debug!("Awaiting tasks for client {id}"); client.await_tasks().await; - log::debug!("Finished awaiting tasks for client {}", id); + log::debug!("Finished awaiting tasks for client {id}"); } }); } @@ -360,7 +355,7 @@ impl PumpkinServer { .save_all_players(&self.server) .await { - log::error!("Error saving all players during shutdown: {}", e); + log::error!("Error saving all players during shutdown: {e}"); } let kick_message = TextComponent::text("Server stopped"); @@ -463,7 +458,7 @@ fn setup_console(rl: Readline, server: Arc) { } err => { log::error!("Console command loop failed!"); - log::error!("{:?}", err); + log::error!("{err:?}"); break; } }