enki-gpu 0.1.0

Pure Rust heterogeneous GPU compute platform with JIT compilation
Documentation
use std::ops::{Bound, RangeBounds};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ResolvedRange {
    pub start: usize,
    pub count: usize,
    pub end: usize,
}

impl ResolvedRange {
    #[track_caller]
    pub(crate) fn resolve<R: RangeBounds<usize>>(
        range: R,
        total_len: usize,
        caller: &'static std::panic::Location<'static>,
    ) -> Self {
        let start = match range.start_bound() {
            Bound::Included(&s) => s,
            Bound::Excluded(&s) => s
                .checked_add(1)
                .expect("[Slice Range] Start bound integer overflow"),
            Bound::Unbounded => 0,
        };

        let end = match range.end_bound() {
            Bound::Included(&e) => e
                .checked_add(1)
                .expect("[Slice Range] End bound integer overflow"),
            Bound::Excluded(&e) => e,
            Bound::Unbounded => total_len,
        };

        if start > end || end > total_len {
            let diag = anu::diagnostics::rt::slice_out_of_bounds(caller);
            let formatted = anu::diagnostics::emit_diagnostic(&diag);
            eprint!("{formatted}");

            let bin_name = std::env::current_exe()
                .ok()
                .and_then(|p| p.file_name().map(|n| n.to_string_lossy().to_string()))
                .unwrap_or_else(|| "enki_app".to_string());

            eprintln!(
                "\x1b[1;91merror\x1b[0m: aborting execution of `{bin_name}` due to 1 previous error\n"
            );
            std::process::exit(101);
        }

        let count = end - start;

        Self { start, count, end }
    }
}