From 4429cc8682eb3c00901af5d96233fef04768bf5a Mon Sep 17 00:00:00 2001 From: Yurii Koba Date: Fri, 8 Mar 2024 23:20:38 +0200 Subject: [PATCH] Add Clone derive for primitive structs (#10730) This pull request adds the Clone derive for specified primitive structs, enabling easy creation of deep copies. It improves usability, consistency, and readability while adhering to Rust conventions. **Why This Matters:** - **Enhanced Usability:** With the `Clone` trait implemented, users can easily create copies of these structs without manually implementing the clone functionality, which improves usability and reduces boilerplate code. - **Consistency and Readability:** By ensuring consistency in our codebase and following Rust conventions, we enhance code readability and maintainability. - **Performance:** While cloning can incur performance overhead, it's often necessary in certain contexts, and having it readily available can streamline development processes. --- chain/indexer-primitives/src/lib.rs | 6 +++--- core/primitives/src/views.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/chain/indexer-primitives/src/lib.rs b/chain/indexer-primitives/src/lib.rs index a9fe48107d6..0dd90fe44ae 100644 --- a/chain/indexer-primitives/src/lib.rs +++ b/chain/indexer-primitives/src/lib.rs @@ -2,13 +2,13 @@ pub use near_primitives::hash::CryptoHash; pub use near_primitives::{self, types, views}; /// Resulting struct represents block with chunks -#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct StreamerMessage { pub block: views::BlockView, pub shards: Vec, } -#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct IndexerChunkView { pub author: types::AccountId, pub header: views::ChunkHeaderView, @@ -34,7 +34,7 @@ pub struct IndexerExecutionOutcomeWithReceipt { pub receipt: views::ReceiptView, } -#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct IndexerShard { pub shard_id: types::ShardId, pub chunk: Option, diff --git a/core/primitives/src/views.rs b/core/primitives/src/views.rs index 8b9ccd1ee63..ade64f5a0cd 100644 --- a/core/primitives/src/views.rs +++ b/core/primitives/src/views.rs @@ -1123,7 +1123,7 @@ impl From for ShardChunkHeader { } } -#[derive(serde::Serialize, serde::Deserialize, Debug)] +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] pub struct BlockView { pub author: AccountId, pub header: BlockHeaderView, @@ -2251,7 +2251,7 @@ impl From for StateChangeKindView { pub type StateChangesKindsView = Vec; /// See crate::types::StateChangeCause for details. -#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] #[serde(rename_all = "snake_case", tag = "type")] pub enum StateChangeCauseView { NotWritableToDisk, @@ -2296,7 +2296,7 @@ impl From for StateChangeCauseView { } #[serde_as] -#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] #[serde(rename_all = "snake_case", tag = "type", content = "change")] pub enum StateChangeValueView { AccountUpdate { @@ -2370,7 +2370,7 @@ impl From for StateChangeValueView { } } -#[derive(Debug, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct StateChangeWithCauseView { pub cause: StateChangeCauseView, #[serde(flatten)]