Passing an array from C to Rust via FFI with #[!no_std]

890 Views Asked by At

All the answers to this question about passing an array from C to Rust use std::slice::from_raw_parts to convert the raw C pointer and some length information into a Rust. In an embedded context (MOS 6502 in my case), there might not be a std library available. So in a #![no_std] context, what is the nicest way of passing an array from C to Rust for (potentially mutable) processing?

1

There are 1 best solutions below

1
On BEST ANSWER

While std::slice::from_raw_parts is not available in a no_std environment, core::slice::from_raw_parts is available, so you can simply use that.

In general, anything that is in std and not somehow platform dependent (so, not I/O, heap allocation and the like) should also be available in no_std environments through the core crate.