forked from databendlabs/openraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: Replace
MessageSummary
with Display
This commit eliminates redundant `MessageSummary` implementations, as they were identical to the existing `Display` trait implementations. The following types are affected by this change: - Raft protocol types: - `VoteRequest` - `VoteResponse` - `AppendEntriesRequest` - `InstallSnapshotRequest` - Application API types: - `ClientWriteResponse` - `SnapshotMeta` - Base types: - `LogId` - `Vote` - `EntryPayload` - `Entry` - Membership types: - `Membership` - `EffectiveMembership` - `StoredMembership` - `MembershipState` - Metrics types: `RaftMetrics` `RaftDataMetrics` `RaftServerMetrics` With this update, if possible, any usage of `MessageSummary` should be replaced with `Display`. `MessageSummary` provides addtional display abilities and can be used for displaying `Option<T>` or `&[T]`: - If `T` implements `Display`, then `T` implements `MessageSummary` too. - `Option<T: MessageSummary>` implements `MessageSummary`. - and `&[T]` where `T: MessageSummary` implements `MessageSummary` #### Examples ```rust,ignore use openraft::MessageSummary; use openraft::testing::log_id; let lid = log_id(1, 2, 3); assert_eq!("1-2-3", lid.to_string(), "LogId is Display"); assert_eq!("1-2-3", lid.summary(), "Thus LogId is also MessageSummary"); assert_eq!("1-2-3", (&lid).summary(), "and its reference"); assert_eq!("Some(1-2-3)", Some(lid).summary(), "Option<LogId> can be displayed too"); assert_eq!("Some(1-2-3)", Some(&lid).summary(), "Option<&LogId> can be displayed too"); let slc = vec![lid, lid]; assert_eq!("1-2-3,1-2-3", slc.as_slice().summary(), "&[LogId] can be displayed too"); let slc = vec![&lid, &lid]; assert_eq!("1-2-3,1-2-3", slc.as_slice().summary(), "&[&LogId] can be displayed too"); ``` Upgrade tip: For instances of type `T`, replace any calls to `T::summary()` with the standard `T::to_string()` method or the more general `format!("{}", t)` pattern. For convenience, when working with `Option<T>` or `&[T]`, the `summary()` method can still be utilized to generate string representations of these types.
- Loading branch information
1 parent
cfd0c6b
commit 8b7ba0d
Showing
34 changed files
with
234 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.