/// Will return an idx within 0 and len - 1 (or 0 if len is 0)
/// - `len` - the length of the aray
pub fn clamp_idx_in_len(idx: usize, len: usize) -> usize {
	idx.min(len.saturating_sub(1))
}

/// Will return an idx within 0 and len - 1 (or 0 if len is 0)
/// - `len` - the length of the aray
pub fn offset_and_clamp_option_idx_in_len(idx: &Option<i32>, offset: i32, len: usize) -> Option<i32> {
	match (len, &idx) {
		(0, _) => None,
		(len, Some(idx_val)) => Some((*idx_val + offset).max(0).min(len as i32 - 1)),
		(_, None) => Some(0),
	}
}
