Skip to content

Commit c700f6e

Browse files
committed
Fix labrpc building for Rust Nightly
Missing `dyn` for trait object (bare trait object) is a warning by default now as rust-lang/rust#61203 is merged, which breaks labrpc. Also fixed a few other warnings and unclear documents. Signed-off-by: Liqueur Librazy <[email protected]>
1 parent d4f84df commit c700f6e

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

dss/labrpc/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static ID_ALLOC: AtomicUsize = AtomicUsize::new(0);
4646

4747
pub type RpcFuture<T> = Box<dyn Future<Item = T, Error = Error> + Send + 'static>;
4848

49-
pub type Handler = Fn(&[u8]) -> RpcFuture<Vec<u8>>;
49+
pub type Handler = dyn Fn(&[u8]) -> RpcFuture<Vec<u8>>;
5050

5151
pub trait HandlerFactory: Sync + Send + 'static {
5252
fn handler(&self, name: &'static str) -> Box<Handler>;
@@ -55,7 +55,7 @@ pub trait HandlerFactory: Sync + Send + 'static {
5555
pub struct ServerBuilder {
5656
name: String,
5757
// Service name -> service methods
58-
services: HashMap<&'static str, Box<HandlerFactory>>,
58+
services: HashMap<&'static str, Box<dyn HandlerFactory>>,
5959
}
6060

6161
impl ServerBuilder {
@@ -69,7 +69,7 @@ impl ServerBuilder {
6969
pub fn add_service(
7070
&mut self,
7171
service_name: &'static str,
72-
fact: Box<HandlerFactory>,
72+
fact: Box<dyn HandlerFactory>,
7373
) -> Result<()> {
7474
match self.services.entry(service_name) {
7575
hashbrown::hash_map::Entry::Occupied(_) => Err(Error::Other(format!(
@@ -99,7 +99,7 @@ struct ServerCore {
9999
name: String,
100100
id: usize,
101101

102-
services: HashMap<&'static str, Box<HandlerFactory>>,
102+
services: HashMap<&'static str, Box<dyn HandlerFactory>>,
103103
count: AtomicUsize,
104104
}
105105

dss/src/kvraft/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn check_clnt_appends(clnt: usize, v: String, count: usize) {
9595
assert_eq!(off1, off, "duplicate element {:?} in Append result", wanted);
9696

9797
if let Some(lastoff) = lastoff {
98-
assert!( off > lastoff "wrong order for element {:?} in Append result", wanted);
98+
assert!( off > lastoff, "wrong order for element {:?} in Append result", wanted);
9999
}
100100
lastoff = Some(off);
101101
} else {
@@ -120,7 +120,7 @@ fn check_concurrent_appends(v: String, counts: &[usize]) {
120120
assert_eq!(off1, off, "duplicate element {:?} in Append result", wanted);
121121

122122
if let Some(lastoff) = lastoff {
123-
assert!( off > lastoff "wrong order for element {:?} in Append result", wanted);
123+
assert!( off > lastoff, "wrong order for element {:?} in Append result", wanted);
124124
}
125125
lastoff = Some(off);
126126
} else {

dss/src/raft/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,16 @@ impl Node {
199199

200200
/// the service using Raft (e.g. a k/v server) wants to start
201201
/// agreement on the next command to be appended to Raft's log. if this
202-
/// server isn't the leader, returns false. otherwise start the
203-
/// agreement and return immediately. there is no guarantee that this
202+
/// server isn't the leader, returns [`Error::NotLeader`]. otherwise start
203+
/// the agreement and return immediately. there is no guarantee that this
204204
/// command will ever be committed to the Raft log, since the leader
205205
/// may fail or lose an election. even if the Raft instance has been killed,
206206
/// this function should return gracefully.
207207
///
208-
/// the first return value is the index that the command will appear at
209-
/// if it's ever committed. the second return value is the current
210-
/// term. the third return value is true if this server believes it is
211-
/// the leader.
212-
/// This method must return quickly.
208+
/// the first value of the tuple is the index that the command will appear
209+
/// at if it's ever committed. the second is the current term.
210+
///
211+
/// This method must return without blocking on the raft.
213212
pub fn start<M>(&self, command: &M) -> Result<(u64, u64)>
214213
where
215214
M: labcodec::Message,

0 commit comments

Comments
 (0)