pub(in crate::db::executor) fn apply_offset_limit_window<T>(
rows: &mut Vec<T>,
offset: u32,
limit: Option<u32>,
) {
let offset = usize::min(rows.len(), usize::try_from(offset).unwrap_or(usize::MAX));
if offset > 0 {
rows.drain(..offset);
}
if let Some(limit) = limit {
let limit = usize::min(rows.len(), usize::try_from(limit).unwrap_or(usize::MAX));
rows.truncate(limit);
}
}
#[must_use]
pub(in crate::db::executor) fn saturating_u32_len(row_len: usize) -> u32 {
u32::try_from(row_len).unwrap_or(u32::MAX)
}
#[must_use]
#[expect(clippy::cast_possible_truncation)]
pub(in crate::db::executor) const fn saturating_row_len(row_len: usize) -> u64 {
if row_len > u64::MAX as usize {
u64::MAX
} else {
row_len as u64
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn saturating_row_len_returns_exact_value_within_u64_range() {
assert_eq!(saturating_row_len(42), 42);
}
#[test]
fn saturating_row_len_saturates_at_u64_max() {
assert_eq!(saturating_row_len(usize::MAX), u64::MAX);
}
}