pub fn new(
        peers: Vec<RaftClient>,
        me: usize,
        persister: Box<dyn Persister>,
        _apply_ch: UnboundedSender<ApplyMsg>,
    ) -> Raft {
        let raft_state = persister.raft_state();

        // Your initialization code here (2A, 2B, 2C).
        let mut rf = Raft {
            peers,
            persister: Mutex::new(persister),
            me,
            state: Arc::new(Mutex::new(State::default())),
        };
        {
            let mut state = rf.state.lock().unwrap();
            // set NoOp as the first index to make all indexes start at 1.
            state.log.push((0, ApplyMsg::NoOp));
        }

        // initialize from state persisted before a crash
        rf.restore(&raft_state);

        rf
    }
/// the service or tester wants to create a Raft server. the ports
/// of all the Raft servers (including this one) are in peers. this
/// server's port is peers[me]. all the servers' peers arrays
/// have the same order. persister is a place for this server to
/// save its persistent state, and also initially holds the most
/// recent saved state, if any. apply_ch is a channel on which the
/// tester or service expects Raft to send ApplyMsg messages.
/// This method must return quickly.
the service or tester wants to create a Raft server. the ports
of all the Raft servers (including this one) are in peers. this
server's port is peers[me]. all the servers' peers arrays
have the same order. persister is a place for this server to
save its persistent state, and also initially holds the most
recent saved state, if any. apply_ch is a channel on which the
tester or service expects Raft to send ApplyMsg messages.
This method must return quickly.
the service or tester wants to create a Raft server . the ports of all the Raft servers ( including this one ) are in peers . this server ' s port is peers [ me ] . all the servers ' peers arrays have the same order . persister is a place for this server to save its persistent state and also initially holds the most recent saved state if any . apply_ch is a channel on which the tester or service expects Raft to send ApplyMsg messages . This method must return quickly .
pub fn new(
        peers: Vec<RaftClient>,
        me: usize,
        persister: Box<dyn Persister>,
        _apply_ch: UnboundedSender<ApplyMsg>,
    ) -> Raft {
        let raft_state = persister.raft_state();
        // Your initialization code here (2A, 2B, 2C).
        let mut rf = Raft {
            peers,
            persister: Mutex::new(persister),
            me,
            state: Arc::new(Mutex::new(State::default())),
        };
        {
            let mut state = rf.state.lock().unwrap();
            // set NoOp as the first index to make all indexes start at 1.
            state.log.push((0, ApplyMsg::NoOp));
        }
        // initialize from state persisted before a crash
        rf.restore(&raft_state);
        rf
    }
pub fn new ( peers : Vec < RaftClient > , me : usize , persister : Box < dyn Persister > , _apply_ch : UnboundedSender < ApplyMsg > , ) -> Raft { let raft_state = persister . raft_state ( ) ; // Your initialization code here (2A, 2B, 2C). let mut rf = Raft { peers , persister : Mutex :: new ( persister ) , me , state : Arc :: new ( Mutex :: new ( State :: default ( ) ) ) , } ; { let mut state = rf . state . lock ( ) . unwrap ( ) ; // set NoOp as the first index to make all indexes start at 1. state . log . push ( ( 0 , ApplyMsg :: NoOp ) ) ; } // initialize from state persisted before a crash rf . restore ( & raft_state ) ; rf }
the service or tester wants to create a Raft server.
the service or tester wants to create a Raft server .
peers
Vec<RaftClient>
me
usize
persister
Box<dyn Persister>
_apply_ch
UnboundedSender<ApplyMsg>