Function byte::check_len

source ·
pub fn check_len(bytes: &[u8], len: usize) -> Result<usize>
Expand description

A helper function that checks whether the given length exceeded the length of the slice; returns Err(Error::Incomplete) otherwise.

§Example

use byte::*;

let bytes = [0u8; 4];
assert_eq!(check_len(&bytes, 4), Ok(4));
assert_eq!(check_len(&bytes, 5), Err(Error::Incomplete));