Cactus
Cactus

Reputation: 27626

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

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?

Upvotes: 5

Views: 1299

Answers (1)

Elias Holzmann
Elias Holzmann

Reputation: 3649

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.

Upvotes: 6

Related Questions