diff --git a/Cargo.toml b/Cargo.toml index b951af74c..bbd9b8a79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" build = "build.rs" [build-dependencies] -protobuf-build = "0.3" +protobuf-build = "0.4.1" [features] default = [] diff --git a/build.rs b/build.rs index a76e2c4f0..a3aa205ae 100644 --- a/build.rs +++ b/build.rs @@ -52,6 +52,7 @@ fn main() { .map(|m| format!("src/prost/{}.rs", m)) .collect::>(), "src/prost", + GenOpt::All, ); generate_prost_rs(&mod_names); } diff --git a/src/prost/wrapper_eraftpb.rs b/src/prost/wrapper_eraftpb.rs index 562a4a694..e10c4afd0 100644 --- a/src/prost/wrapper_eraftpb.rs +++ b/src/prost/wrapper_eraftpb.rs @@ -1,70 +1,94 @@ +// Generated file, please don't edit manually. + impl Entry { pub fn new_() -> Entry { ::std::default::Default::default() } + #[inline] pub fn clear_entry_type(&mut self) { self.entry_type = 0 } + #[inline] pub fn set_entry_type_(&mut self, v: EntryType) { self.entry_type = unsafe { ::std::mem::transmute::(v) }; } + #[inline] pub fn get_entry_type(&self) -> EntryType { unsafe { ::std::mem::transmute::(self.entry_type) } } + #[inline] pub fn clear_term(&mut self) { self.term = 0 } + #[inline] pub fn set_term(&mut self, v: u64) { self.term = v; } + #[inline] pub fn get_term(&self) -> u64 { self.term } + #[inline] pub fn clear_index(&mut self) { self.index = 0 } + #[inline] pub fn set_index(&mut self, v: u64) { self.index = v; } + #[inline] pub fn get_index(&self) -> u64 { self.index } + #[inline] pub fn clear_data(&mut self) { self.data.clear(); } + #[inline] pub fn set_data(&mut self, v: std::vec::Vec) { self.data = v; } + #[inline] pub fn get_data(&self) -> &[u8] { &self.data } + #[inline] pub fn mut_data(&mut self) -> &mut std::vec::Vec { &mut self.data } + #[inline] pub fn take_data(&mut self) -> std::vec::Vec { ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) } + #[inline] pub fn clear_context(&mut self) { self.context.clear(); } + #[inline] pub fn set_context(&mut self, v: std::vec::Vec) { self.context = v; } + #[inline] pub fn get_context(&self) -> &[u8] { &self.context } + #[inline] pub fn mut_context(&mut self) -> &mut std::vec::Vec { &mut self.context } + #[inline] pub fn take_context(&mut self) -> std::vec::Vec { ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) } + #[inline] pub fn clear_sync_log(&mut self) { self.sync_log = false } + #[inline] pub fn set_sync_log(&mut self, v: bool) { self.sync_log = v; } + #[inline] pub fn get_sync_log(&self) -> bool { self.sync_log } @@ -139,80 +163,101 @@ impl SnapshotMetadata { pub fn new_() -> SnapshotMetadata { ::std::default::Default::default() } + #[inline] pub fn has_conf_state(&self) -> bool { self.conf_state.is_some() } + #[inline] pub fn clear_conf_state(&mut self) { self.conf_state = ::std::option::Option::None } + #[inline] pub fn set_conf_state(&mut self, v: ConfState) { self.conf_state = ::std::option::Option::Some(v); } + #[inline] pub fn get_conf_state(&self) -> &ConfState { match self.conf_state.as_ref() { Some(v) => v, None => ::default_instance(), } } + #[inline] pub fn mut_conf_state(&mut self) -> &mut ConfState { if self.conf_state.is_none() { self.conf_state = ::std::option::Option::Some(ConfState::default()); } self.conf_state.as_mut().unwrap() } + #[inline] pub fn take_conf_state(&mut self) -> ConfState { self.conf_state.take().unwrap_or_else(ConfState::default) } + #[inline] pub fn has_pending_membership_change(&self) -> bool { self.pending_membership_change.is_some() } + #[inline] pub fn clear_pending_membership_change(&mut self) { self.pending_membership_change = ::std::option::Option::None } + #[inline] pub fn set_pending_membership_change(&mut self, v: ConfState) { self.pending_membership_change = ::std::option::Option::Some(v); } + #[inline] pub fn get_pending_membership_change(&self) -> &ConfState { match self.pending_membership_change.as_ref() { Some(v) => v, None => ::default_instance(), } } + #[inline] pub fn mut_pending_membership_change(&mut self) -> &mut ConfState { if self.pending_membership_change.is_none() { self.pending_membership_change = ::std::option::Option::Some(ConfState::default()); } self.pending_membership_change.as_mut().unwrap() } + #[inline] pub fn take_pending_membership_change(&mut self) -> ConfState { self.pending_membership_change .take() .unwrap_or_else(ConfState::default) } + #[inline] pub fn clear_pending_membership_change_index(&mut self) { self.pending_membership_change_index = 0 } + #[inline] pub fn set_pending_membership_change_index(&mut self, v: u64) { self.pending_membership_change_index = v; } + #[inline] pub fn get_pending_membership_change_index(&self) -> u64 { self.pending_membership_change_index } + #[inline] pub fn clear_index(&mut self) { self.index = 0 } + #[inline] pub fn set_index(&mut self, v: u64) { self.index = v; } + #[inline] pub fn get_index(&self) -> u64 { self.index } + #[inline] pub fn clear_term(&mut self) { self.term = 0 } + #[inline] pub fn set_term(&mut self, v: u64) { self.term = v; } + #[inline] pub fn get_term(&self) -> u64 { self.term } @@ -287,42 +332,53 @@ impl Snapshot { pub fn new_() -> Snapshot { ::std::default::Default::default() } + #[inline] pub fn clear_data(&mut self) { self.data.clear(); } + #[inline] pub fn set_data(&mut self, v: std::vec::Vec) { self.data = v; } + #[inline] pub fn get_data(&self) -> &[u8] { &self.data } + #[inline] pub fn mut_data(&mut self) -> &mut std::vec::Vec { &mut self.data } + #[inline] pub fn take_data(&mut self) -> std::vec::Vec { ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) } + #[inline] pub fn has_metadata(&self) -> bool { self.metadata.is_some() } + #[inline] pub fn clear_metadata(&mut self) { self.metadata = ::std::option::Option::None } + #[inline] pub fn set_metadata(&mut self, v: SnapshotMetadata) { self.metadata = ::std::option::Option::Some(v); } + #[inline] pub fn get_metadata(&self) -> &SnapshotMetadata { match self.metadata.as_ref() { Some(v) => v, None => ::default_instance(), } } + #[inline] pub fn mut_metadata(&mut self) -> &mut SnapshotMetadata { if self.metadata.is_none() { self.metadata = ::std::option::Option::Some(SnapshotMetadata::default()); } self.metadata.as_mut().unwrap() } + #[inline] pub fn take_metadata(&mut self) -> SnapshotMetadata { self.metadata .take() @@ -399,138 +455,181 @@ impl Message { pub fn new_() -> Message { ::std::default::Default::default() } + #[inline] pub fn clear_msg_type(&mut self) { self.msg_type = 0 } + #[inline] pub fn set_msg_type_(&mut self, v: MessageType) { self.msg_type = unsafe { ::std::mem::transmute::(v) }; } + #[inline] pub fn get_msg_type(&self) -> MessageType { unsafe { ::std::mem::transmute::(self.msg_type) } } + #[inline] pub fn clear_to(&mut self) { self.to = 0 } + #[inline] pub fn set_to(&mut self, v: u64) { self.to = v; } + #[inline] pub fn get_to(&self) -> u64 { self.to } + #[inline] pub fn clear_from(&mut self) { self.from = 0 } + #[inline] pub fn set_from(&mut self, v: u64) { self.from = v; } + #[inline] pub fn get_from(&self) -> u64 { self.from } + #[inline] pub fn clear_term(&mut self) { self.term = 0 } + #[inline] pub fn set_term(&mut self, v: u64) { self.term = v; } + #[inline] pub fn get_term(&self) -> u64 { self.term } + #[inline] pub fn clear_log_term(&mut self) { self.log_term = 0 } + #[inline] pub fn set_log_term(&mut self, v: u64) { self.log_term = v; } + #[inline] pub fn get_log_term(&self) -> u64 { self.log_term } + #[inline] pub fn clear_index(&mut self) { self.index = 0 } + #[inline] pub fn set_index(&mut self, v: u64) { self.index = v; } + #[inline] pub fn get_index(&self) -> u64 { self.index } + #[inline] pub fn clear_entries(&mut self) { self.entries.clear(); } + #[inline] pub fn set_entries(&mut self, v: ::std::vec::Vec) { self.entries = v; } + #[inline] pub fn get_entries(&self) -> &::std::vec::Vec { &self.entries } + #[inline] pub fn mut_entries(&mut self) -> &mut ::std::vec::Vec { &mut self.entries } + #[inline] pub fn take_entries(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.entries, ::std::vec::Vec::new()) } + #[inline] pub fn clear_commit(&mut self) { self.commit = 0 } + #[inline] pub fn set_commit(&mut self, v: u64) { self.commit = v; } + #[inline] pub fn get_commit(&self) -> u64 { self.commit } + #[inline] pub fn has_snapshot(&self) -> bool { self.snapshot.is_some() } + #[inline] pub fn clear_snapshot(&mut self) { self.snapshot = ::std::option::Option::None } + #[inline] pub fn set_snapshot(&mut self, v: Snapshot) { self.snapshot = ::std::option::Option::Some(v); } + #[inline] pub fn get_snapshot(&self) -> &Snapshot { match self.snapshot.as_ref() { Some(v) => v, None => ::default_instance(), } } + #[inline] pub fn mut_snapshot(&mut self) -> &mut Snapshot { if self.snapshot.is_none() { self.snapshot = ::std::option::Option::Some(Snapshot::default()); } self.snapshot.as_mut().unwrap() } + #[inline] pub fn take_snapshot(&mut self) -> Snapshot { self.snapshot.take().unwrap_or_else(Snapshot::default) } + #[inline] pub fn clear_reject(&mut self) { self.reject = false } + #[inline] pub fn set_reject(&mut self, v: bool) { self.reject = v; } + #[inline] pub fn get_reject(&self) -> bool { self.reject } + #[inline] pub fn clear_reject_hint(&mut self) { self.reject_hint = 0 } + #[inline] pub fn set_reject_hint(&mut self, v: u64) { self.reject_hint = v; } + #[inline] pub fn get_reject_hint(&self) -> u64 { self.reject_hint } + #[inline] pub fn clear_context(&mut self) { self.context.clear(); } + #[inline] pub fn set_context(&mut self, v: std::vec::Vec) { self.context = v; } + #[inline] pub fn get_context(&self) -> &[u8] { &self.context } + #[inline] pub fn mut_context(&mut self) -> &mut std::vec::Vec { &mut self.context } + #[inline] pub fn take_context(&mut self) -> std::vec::Vec { ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) } @@ -605,30 +704,39 @@ impl HardState { pub fn new_() -> HardState { ::std::default::Default::default() } + #[inline] pub fn clear_term(&mut self) { self.term = 0 } + #[inline] pub fn set_term(&mut self, v: u64) { self.term = v; } + #[inline] pub fn get_term(&self) -> u64 { self.term } + #[inline] pub fn clear_vote(&mut self) { self.vote = 0 } + #[inline] pub fn set_vote(&mut self, v: u64) { self.vote = v; } + #[inline] pub fn get_vote(&self) -> u64 { self.vote } + #[inline] pub fn clear_commit(&mut self) { self.commit = 0 } + #[inline] pub fn set_commit(&mut self, v: u64) { self.commit = v; } + #[inline] pub fn get_commit(&self) -> u64 { self.commit } @@ -703,33 +811,43 @@ impl ConfState { pub fn new_() -> ConfState { ::std::default::Default::default() } + #[inline] pub fn clear_nodes(&mut self) { self.nodes.clear(); } + #[inline] pub fn set_nodes(&mut self, v: ::std::vec::Vec) { self.nodes = v; } + #[inline] pub fn get_nodes(&self) -> &::std::vec::Vec { &self.nodes } + #[inline] pub fn mut_nodes(&mut self) -> &mut ::std::vec::Vec { &mut self.nodes } + #[inline] pub fn take_nodes(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.nodes, ::std::vec::Vec::new()) } + #[inline] pub fn clear_learners(&mut self) { self.learners.clear(); } + #[inline] pub fn set_learners(&mut self, v: ::std::vec::Vec) { self.learners = v; } + #[inline] pub fn get_learners(&self) -> &::std::vec::Vec { &self.learners } + #[inline] pub fn mut_learners(&mut self) -> &mut ::std::vec::Vec { &mut self.learners } + #[inline] pub fn take_learners(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.learners, ::std::vec::Vec::new()) } @@ -804,78 +922,101 @@ impl ConfChange { pub fn new_() -> ConfChange { ::std::default::Default::default() } + #[inline] pub fn clear_id(&mut self) { self.id = 0 } + #[inline] pub fn set_id(&mut self, v: u64) { self.id = v; } + #[inline] pub fn get_id(&self) -> u64 { self.id } + #[inline] pub fn clear_change_type(&mut self) { self.change_type = 0 } + #[inline] pub fn set_change_type_(&mut self, v: ConfChangeType) { self.change_type = unsafe { ::std::mem::transmute::(v) }; } + #[inline] pub fn get_change_type(&self) -> ConfChangeType { unsafe { ::std::mem::transmute::(self.change_type) } } + #[inline] pub fn clear_node_id(&mut self) { self.node_id = 0 } + #[inline] pub fn set_node_id(&mut self, v: u64) { self.node_id = v; } + #[inline] pub fn get_node_id(&self) -> u64 { self.node_id } + #[inline] pub fn clear_context(&mut self) { self.context.clear(); } + #[inline] pub fn set_context(&mut self, v: std::vec::Vec) { self.context = v; } + #[inline] pub fn get_context(&self) -> &[u8] { &self.context } + #[inline] pub fn mut_context(&mut self) -> &mut std::vec::Vec { &mut self.context } + #[inline] pub fn take_context(&mut self) -> std::vec::Vec { ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) } + #[inline] pub fn has_configuration(&self) -> bool { self.configuration.is_some() } + #[inline] pub fn clear_configuration(&mut self) { self.configuration = ::std::option::Option::None } + #[inline] pub fn set_configuration(&mut self, v: ConfState) { self.configuration = ::std::option::Option::Some(v); } + #[inline] pub fn get_configuration(&self) -> &ConfState { match self.configuration.as_ref() { Some(v) => v, None => ::default_instance(), } } + #[inline] pub fn mut_configuration(&mut self) -> &mut ConfState { if self.configuration.is_none() { self.configuration = ::std::option::Option::Some(ConfState::default()); } self.configuration.as_mut().unwrap() } + #[inline] pub fn take_configuration(&mut self) -> ConfState { self.configuration.take().unwrap_or_else(ConfState::default) } + #[inline] pub fn clear_start_index(&mut self) { self.start_index = 0 } + #[inline] pub fn set_start_index(&mut self, v: u64) { self.start_index = v; } + #[inline] pub fn get_start_index(&self) -> u64 { self.start_index } diff --git a/src/raft.rs b/src/raft.rs index d9986d43b..6ea3af946 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -429,7 +429,7 @@ impl Raft { pub fn began_membership_change_at(&self) -> Option { self.pending_membership_change .as_ref() - .map(|v| v.get_start_index()) + .map(ConfChange::get_start_index) } /// Set whether batch append msg at runtime.