native_neural_network 0.1.6

Lib no_std Rust for native neural network (.rnn)
Documentation
use crate::rnn_format::RnnHandle;

pub fn blob_bounds_valid(handle: &RnnHandle<'_, '_>, index: usize) -> bool {
    let b = match handle.blobs.get(index) {
        Some(v) => v,
        None => return false,
    };
    let offset = match usize::try_from(b.offset) {
        Ok(v) => v,
        Err(_) => return false,
    };
    let len = match usize::try_from(b.length) {
        Ok(v) => v,
        Err(_) => return false,
    };
    match offset.checked_add(len) {
        Some(end) => end <= handle.bytes.len(),
        None => false,
    }
}

pub fn all_blob_bounds_valid(handle: &RnnHandle<'_, '_>) -> bool {
    for i in 0..handle.blobs.len() {
        if !blob_bounds_valid(handle, i) {
            return false;
        }
    }
    true
}