-
Rust] How bad is to use unsafe code internally in a library?코딩Coding/★★Rust★★최신동향★및관련글 2020. 12. 31. 15:30728x90
How bad is to use unsafe code internally in a library?
I'm trying to write a Rust library to interop with an old C library. The final user will have a 100% safe Rust API. However to make this work, I find myself using *a lot* of unsafe blocks internally, "for a greater good".
Also, sometimes storing a raw pointer seems to be the most sane choice, because it alleviates the burden to the final user, and *I know* the pointer will be valid because of the internal implementation.
So, at this point, this is my dilemma:
* keep using unsafe code internally, providing a more ergonomic API to the final user; or
* use less unsafe code internally, and let the user deal with extra syntax.
I know there's **no** definitive answer to this, but I'd really like to read your own guidelines when facing such implementations.반응형'코딩Coding > ★★Rust★★최신동향★및관련글' 카테고리의 다른 글
Rust) Deno 2020 year in review (0) 2021.01.16 Rust] Is it possible to generate an extern "C" function at runtime? (0) 2021.01.08 Rust is now overall faster than C in benchmarks (0) 2021.01.06 Rust) I did a thing, it's not much, but here's a diceware (0) 2021.01.02 Rust] Windows defender detects Virus in rust crate (0) 2020.12.31 napi@1.0.0 Released, build fast and safe NodeJS native addon in Rust (0) 2020.12.30 Vas-quod – A minimal Linux container runtime written in Rust (0) 2020.12.28 Rust Survey 2020 Results (0) 2020.12.28