//! This module contains a collection of various tools to use to manipulate
//! and control messages and data associated with raft.
// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
use u64;
use crate;
use Message as PbMessage;
/// A number to represent that there is no limit.
pub const NO_LIMIT: u64 = u64MAX;
/// 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();
/// 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);
/// ```
/// Check whether the entry is continuous to the message.
/// i.e msg's next entry index should be equal to the first entries's index