Pointer constness for FFI

⚓ Rust    📅 2025-11-13    👤 surdeus    👁️ 5      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Pointer constness for FFI

Suppose I have an opaque C type MyType and a C function get_name(MyType* p), and I'm going to invoke the function from Rust. Logically the function doesn't change the internal state of p, but the implementation may require a mutable pointer.
In this case, what should be signature of the corresponding function in Rust? More specifically, should I use p: *const MyType or p: *mut MyType?

2 posts - 2 participants

Read full topic

🏷️ Rust_feed