6 ms·
What do you feel is rough around FFI? Safer, zero-cost bindings to C libraries - what's not to like? :)
by rhelmer 11y ago
What do you feel is rough around FFI? Safer, zero-cost bindings to C libraries - what's not to like? :)
- vvanders 11y agoCString::from_ptr is unstable - https://doc.rust-lang.org/stable/std/ffi/struct.CString.html https://doc.rust-lang.org/stable/std/ffi/struct.CString.html clib is marked as unstable - https://doc.rust-lang.org/stable/libc/types/os/arch/c95/type.c_char.html https://doc.rust-lang.org/stable/libc/types/os/arch/c95/type... Most of the intrinsic types are usable but anything involving strings seems to hit unstable/experimental branch pretty quickly. I'm sure it'll improve I was just a bit surprised to not see it mentioned in the docs.
- steveklabnik 11y agoYou should use libc from crates.io, which is stable. Not the compiler-internal one you linked to.
- vvanders 11y agoAh, the docs around FFI say that libc is a part of the standard library so it wasn't clear that I'd have to pull that from crates.io.
- steveklabnik 11y agoHmm, can you point me to where they say that so I can fix it? Seems bad. (Also, the error message when you don't have a `#![feature(libc)]` should say "hey, please use the external crate thanks")
- vvanders 11y agohttps://doc.rust-lang.org/book/ffi.html https://doc.rust-lang.org/book/ffi.html at the end of "Interoperability with foreign code" Yeah, that error message sent me down the wrong path :).
- steveklabnik 11y agoAhh excellent, thank you! https://github.com/rust-lang/rust/issues/28053 https://github.com/rust-lang/rust/issues/28053
- vvanders 11y agoNice! Let me add another plus for Rust is the community around it.
- tatterdemalion 11y agoYeah its unfortunate that the some FFI APIs are still marked unstable, but Rust is still a language with memory safety, no garbage collector, and opt-in to a C-compatible ABI. That's a pretty big deal in my opinion!
- CyberDildonics 11y agoYou just repeated exactly what the OP was saying.