raft_proto/
lib.rs

1// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
2
3// We use `default` method a lot to be support prost and rust-protobuf at the
4// same time. And reassignment can be optimized by compiler.
5#![allow(clippy::field_reassign_with_default)]
6
7mod confchange;
8mod confstate;
9
10pub use crate::confchange::{
11    new_conf_change_single, parse_conf_change, stringify_conf_change, ConfChangeI,
12};
13pub use crate::confstate::conf_state_eq;
14pub use crate::protos::eraftpb;
15
16#[allow(dead_code)]
17#[allow(unknown_lints)]
18#[allow(clippy::all)]
19#[allow(renamed_and_removed_lints)]
20#[allow(bare_trait_objects)]
21mod protos {
22    include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));
23
24    use self::eraftpb::Snapshot;
25
26    impl Snapshot {
27        /// For a given snapshot, determine if it's empty or not.
28        pub fn is_empty(&self) -> bool {
29            self.get_metadata().index == 0
30        }
31    }
32}
33
34pub mod prelude {
35    pub use crate::eraftpb::{
36        ConfChange, ConfChangeSingle, ConfChangeTransition, ConfChangeType, ConfChangeV2,
37        ConfState, Entry, EntryType, HardState, Message, MessageType, Snapshot, SnapshotMetadata,
38    };
39}
40
41pub mod util {
42    use crate::eraftpb::ConfState;
43
44    impl<Iter1, Iter2> From<(Iter1, Iter2)> for ConfState
45    where
46        Iter1: IntoIterator<Item = u64>,
47        Iter2: IntoIterator<Item = u64>,
48    {
49        fn from((voters, learners): (Iter1, Iter2)) -> Self {
50            let mut conf_state = ConfState::default();
51            conf_state.mut_voters().extend(voters.into_iter());
52            conf_state.mut_learners().extend(learners.into_iter());
53            conf_state
54        }
55    }
56}