1 2 3 4 5 6 7 8 9 10 11 12 13 14
//! Contains the operator [`limit`].
use crate::array::Array;
/// Returns the [`Array`] limited by `num_elements`.
///
/// Limit performs a zero-copy slice of the array, and is a convenience method on slice
/// where:
/// * it performs a bounds-check on the array
/// * it slices from offset 0
pub fn limit(array: &dyn Array, num_elements: usize) -> Box<dyn Array> {
let lim = num_elements.min(array.len());
array.slice(0, lim)
}