Skip to content

Commit

Permalink
Refactor: auto impl AppData and AppDataResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Feb 23, 2023
1 parent 2933a73 commit 03c32b0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
6 changes: 0 additions & 6 deletions memstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use openraft::storage::HardState;
use openraft::storage::LogState;
use openraft::storage::Snapshot;
use openraft::AnyError;
use openraft::AppData;
use openraft::AppDataResponse;
use openraft::EffectiveMembership;
use openraft::ErrorSubject;
use openraft::ErrorVerb;
Expand Down Expand Up @@ -50,14 +48,10 @@ pub struct ClientRequest {
pub status: String,
}

impl AppData for ClientRequest {}

/// The application data response type which the `MemStore` works with.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ClientResponse(Option<String>);

impl AppDataResponse for ClientResponse {}

/// The application snapshot type which the `MemStore` works with.
#[derive(Debug)]
pub struct MemStoreSnapshot {
Expand Down
4 changes: 4 additions & 0 deletions openraft/src/types/v070/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub type NodeId = u64;
/// to do a preliminary deserialization.
pub trait AppData: Clone + Send + Sync + Serialize + DeserializeOwned + 'static {}

impl<T> AppData for T where T: Clone + Send + Sync + Serialize + DeserializeOwned + 'static {}

/// A trait defining application specific response data.
///
/// The intention of this trait is that applications which are using this crate will be able to
Expand All @@ -28,3 +30,5 @@ pub trait AppData: Clone + Send + Sync + Serialize + DeserializeOwned + 'static
/// enforcing of data constraints, and anything of that nature — are expressly out of the realm of
/// the Raft consensus protocol.
pub trait AppDataResponse: Clone + Send + Sync + Serialize + DeserializeOwned + 'static {}

impl<T> AppDataResponse for T where T: Clone + Send + Sync + serde::Serialize + serde::de::DeserializeOwned + 'static {}
6 changes: 0 additions & 6 deletions rocksstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use openraft::async_trait::async_trait;
use openraft::storage::LogState;
use openraft::storage::Snapshot;
use openraft::AnyError;
use openraft::AppData;
use openraft::AppDataResponse;
use openraft::EffectiveMembership;
use openraft::Entry;
use openraft::EntryPayload;
Expand Down Expand Up @@ -52,8 +50,6 @@ pub enum RocksRequest {
Set { key: String, value: String },
}

impl AppData for RocksRequest {}

/**
* Here you will defined what type of answer you expect from reading the data of a node.
* In this example it will return a optional value from a given key in
Expand All @@ -67,8 +63,6 @@ pub struct RocksResponse {
pub value: Option<String>,
}

impl AppDataResponse for RocksResponse {}

#[derive(Serialize, Deserialize, Debug)]
pub struct RocksSnapshot {
pub meta: SnapshotMeta,
Expand Down

0 comments on commit 03c32b0

Please sign in to comment.