INNER CODE UNIT · Rust

pixel_count

elringus/sprite-dicing · crates/abi/src/lib.rs:208

fn pixel_count(width: u32, height: u32) -> usize {
    width as usize * height as usize
}

unsafe fn to_slice<'a, T>(ptr: *const T, len: usize) -> Option<&'a [T]> {
    match (ptr.is_null(), len) {
        (_, 0) => Some(&[]),
        (true, _) => None,
        (false, _) => Some(slice::from_raw_parts(ptr, len)),
    }
}

fn to_array<T>(vec: Vec<T>) -> (*const T, usize) {
    match vec.len() {
        0 => (ptr::null(), 0),
        len => (Box::into_raw(vec.into_boxed_slice()) as *const T, len),
    }
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…