#![allow(dead_code, deprecated, unused_variables, unused_mut)] use std::slice; /// Sum the elements of an FFI slice. /// /// # Safety /// /// If ptr is not NULL, it must be correctly aligned and /// point to `len` initialized items of type `f32`. unsafe extern "C" fn sum_slice(ptr: *const f32, len: usize) -> f32 { let data = if ptr.is_null() { &[] } else { unsafe { slice::from_raw_parts(ptr, len) } }; data.into_iter().sum() } fn main() { let ptr = std::ptr::null(); let len = 0; assert_eq!(unsafe { sum_slice(ptr, len) }, 0.0); }