From 22f759aa4f459e9e40328644f2036624a3e169a0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Apr 2025 21:51:10 +0200 Subject: [PATCH] Rustc now allows many derives for packed structs --- src/allocator.rs | 29 +---------------------------- src/block.rs | 7 +------ src/dir.rs | 9 +-------- src/record.rs | 7 +------ 4 files changed, 4 insertions(+), 48 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index f4e306bc88..286695c2bf 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -172,6 +172,7 @@ impl Allocator { } #[repr(C, packed)] +#[derive(Clone, Copy, Default, Debug)] pub struct AllocEntry { /// The index of the first block this [`AllocEntry`] refers to index: Le, @@ -210,34 +211,6 @@ impl AllocEntry { } } -impl Clone for AllocEntry { - fn clone(&self) -> Self { - *self - } -} - -impl Copy for AllocEntry {} - -impl Default for AllocEntry { - fn default() -> Self { - Self { - index: 0.into(), - count: 0.into(), - } - } -} - -impl fmt::Debug for AllocEntry { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let index = self.index(); - let count = self.count(); - f.debug_struct("AllocEntry") - .field("index", &index) - .field("count", &count) - .finish() - } -} - /// A node in the allocation chain. #[repr(C, packed)] pub struct AllocList { diff --git a/src/block.rs b/src/block.rs index b66a66d2f1..5e677ec7ec 100644 --- a/src/block.rs +++ b/src/block.rs @@ -286,6 +286,7 @@ impl fmt::Debug for BlockPtr { } #[repr(C, packed)] +#[derive(Clone)] pub struct BlockRaw([u8; BLOCK_SIZE as usize]); unsafe impl BlockTrait for BlockRaw { @@ -298,12 +299,6 @@ unsafe impl BlockTrait for BlockRaw { } } -impl Clone for BlockRaw { - fn clone(&self) -> Self { - Self(self.0) - } -} - impl ops::Deref for BlockRaw { type Target = [u8]; fn deref(&self) -> &[u8] { diff --git a/src/dir.rs b/src/dir.rs index 63846516b2..f9a23c1c7d 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -4,6 +4,7 @@ use core::{mem, ops, slice, str}; use crate::{BlockLevel, BlockTrait, Node, TreePtr, DIR_ENTRY_MAX_LENGTH, RECORD_LEVEL}; #[repr(C, packed)] +#[derive(Clone, Copy)] pub struct DirEntry { node_ptr: TreePtr, name: [u8; DIR_ENTRY_MAX_LENGTH], @@ -38,14 +39,6 @@ impl DirEntry { } } -impl Clone for DirEntry { - fn clone(&self) -> Self { - *self - } -} - -impl Copy for DirEntry {} - impl Default for DirEntry { fn default() -> Self { Self { diff --git a/src/record.rs b/src/record.rs index 6a9556b89d..e7815a42c0 100644 --- a/src/record.rs +++ b/src/record.rs @@ -4,6 +4,7 @@ use core::ops; use crate::{BlockLevel, BlockTrait, RECORD_LEVEL}; //TODO: this is a box to prevent stack overflows +#[derive(Clone)] pub struct RecordRaw(Box<[u8]>); unsafe impl BlockTrait for RecordRaw { @@ -16,12 +17,6 @@ unsafe impl BlockTrait for RecordRaw { } } -impl Clone for RecordRaw { - fn clone(&self) -> Self { - Self(self.0.clone()) - } -} - impl ops::Deref for RecordRaw { type Target = [u8]; fn deref(&self) -> &[u8] {