Function raft::util::limit_size [−][src]
pub fn limit_size<T: PbMessage + Clone>(entries: &mut Vec<T>, max: Option<u64>)
Truncates the list of entries down to a specific byte-length of all entries together.
Examples
use raft::{util::limit_size, prelude::*}; let template = { let mut entry = Entry::default(); entry.data = "*".repeat(100).into_bytes().into(); entry }; // Make a bunch of entries that are ~100 bytes long let mut entries = vec![ template.clone(), template.clone(), template.clone(), template.clone(), template.clone(), ]; assert_eq!(entries.len(), 5); limit_size(&mut entries, Some(220)); assert_eq!(entries.len(), 2); // `entries` will always have at least 1 Message limit_size(&mut entries, Some(0)); assert_eq!(entries.len(), 1);