Skip to content

Commit

Permalink
Add Clone derive for primitive structs (#10730)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kobayurii authored and khorolets committed Apr 4, 2024
1 parent 980dd74 commit 8c2085b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions chain/indexer-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexerShard>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct IndexerChunkView {
pub author: types::AccountId,
pub header: views::ChunkHeaderView,
Expand All @@ -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<IndexerChunkView>,
Expand Down
8 changes: 4 additions & 4 deletions core/primitives/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ impl From<ChunkHeaderView> for ShardChunkHeader {
}
}

#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct BlockView {
pub author: AccountId,
pub header: BlockHeaderView,
Expand Down Expand Up @@ -2201,7 +2201,7 @@ impl From<StateChangeKind> for StateChangeKindView {
pub type StateChangesKindsView = Vec<StateChangeKindView>;

/// 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,
Expand Down Expand Up @@ -2246,7 +2246,7 @@ impl From<StateChangeCause> 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 {
Expand Down Expand Up @@ -2320,7 +2320,7 @@ impl From<StateChangeValue> for StateChangeValueView {
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct StateChangeWithCauseView {
pub cause: StateChangeCauseView,
#[serde(flatten)]
Expand Down

0 comments on commit 8c2085b

Please sign in to comment.