Is it possible to just use default partially?


Source is here
There are many redundant assignments. Like 0, None, and Default::default.
Can i make this code cleaner by using default value partially? Thanks.


To use the default for all unspecified fields, you can write .. Default::default(). So your code can be rewritten like this:

    let mut r = Raft {
        raft_log: raft_log,
        max_inflight: c.max_inflight_msgs,
        max_msg_size: c.max_size_per_msg,
        prs: HashMap::with_capacity(peers.len()),
        state: StateRole::Follower,
        check_quorum: c.check_quorum,
        heartbeat_timeout: c.heartbeat_tick,
        election_timeout: c.election_tick,
        allow_step: true,
        tag: c.tag.to_owned(),
        .. Default::default()