Skip to content

Commit dc18dc6

Browse files
committed
Improve: remove Copy bound from NodeId
The `NodeId` type is currently defined as: ```rust type NodeId: .. + Copy + .. + 'static; ``` This commit removes the `Copy` bound from `NodeId`. This modification will allow the use of non-`Copy` types as `NodeId`, providing greater flexibility for applications that prefer variable-length strings or other non-`Copy` types for node identification. This change maintain compatibility by updating derived `Copy` implementations with manual implementations: ```rust // Before #[derive(Copy...)] pub struct LogId<NID: NodeId> {} // After impl<NID: Copy> Copy for LogId<NID> {} ```
1 parent acc8502 commit dc18dc6

File tree

43 files changed

+366
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+366
-336
lines changed

examples/memstore/src/log_store.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ impl<C: RaftTypeConfig> LogStoreInner<C> {
6060
}
6161

6262
async fn get_log_state(&mut self) -> Result<LogState<C>, StorageError<C::NodeId>> {
63-
let last = self.log.iter().next_back().map(|(_, ent)| *ent.get_log_id());
63+
let last = self.log.iter().next_back().map(|(_, ent)| ent.get_log_id().clone());
6464

65-
let last_purged = self.last_purged_log_id;
65+
let last_purged = self.last_purged_log_id.clone();
6666

6767
let last = match last {
68-
None => last_purged,
68+
None => last_purged.clone(),
6969
Some(x) => Some(x),
7070
};
7171

@@ -81,16 +81,16 @@ impl<C: RaftTypeConfig> LogStoreInner<C> {
8181
}
8282

8383
async fn read_committed(&mut self) -> Result<Option<LogId<C::NodeId>>, StorageError<C::NodeId>> {
84-
Ok(self.committed)
84+
Ok(self.committed.clone())
8585
}
8686

8787
async fn save_vote(&mut self, vote: &Vote<C::NodeId>) -> Result<(), StorageError<C::NodeId>> {
88-
self.vote = Some(*vote);
88+
self.vote = Some(vote.clone());
8989
Ok(())
9090
}
9191

9292
async fn read_vote(&mut self) -> Result<Option<Vote<C::NodeId>>, StorageError<C::NodeId>> {
93-
Ok(self.vote)
93+
Ok(self.vote.clone())
9494
}
9595

9696
async fn append<I>(&mut self, entries: I, callback: LogFlushed<C>) -> Result<(), StorageError<C::NodeId>>
@@ -116,8 +116,8 @@ impl<C: RaftTypeConfig> LogStoreInner<C> {
116116
async fn purge(&mut self, log_id: LogId<C::NodeId>) -> Result<(), StorageError<C::NodeId>> {
117117
{
118118
let ld = &mut self.last_purged_log_id;
119-
assert!(*ld <= Some(log_id));
120-
*ld = Some(log_id);
119+
assert!(ld.as_ref() <= Some(&log_id));
120+
*ld = Some(log_id.clone());
121121
}
122122

123123
{

0 commit comments

Comments
 (0)