Skip to content

Commit

Permalink
Refactor: remove Copy bound from NodeId
Browse files Browse the repository at this point in the history
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> {}
```
  • Loading branch information
drmingdrmer committed Oct 15, 2024
1 parent 73c53c5 commit ab9fb81
Show file tree
Hide file tree
Showing 43 changed files with 366 additions and 336 deletions.
16 changes: 8 additions & 8 deletions examples/memstore/src/log_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ impl<C: RaftTypeConfig> LogStoreInner<C> {
}

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

let last_purged = self.last_purged_log_id;
let last_purged = self.last_purged_log_id.clone();

let last = match last {
None => last_purged,
None => last_purged.clone(),
Some(x) => Some(x),
};

Expand All @@ -81,16 +81,16 @@ impl<C: RaftTypeConfig> LogStoreInner<C> {
}

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

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

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

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

{
Expand Down
Loading

0 comments on commit ab9fb81

Please sign in to comment.