nagisa / rust_libloading

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.
https://docs.rs/libloading
ISC License
1.24k stars 102 forks source link

Add `Library::new_with_flags` #159

Closed tgross35 closed 4 weeks ago

tgross35 commented 1 month ago

Sometimes it would be convenient to keep the safer lifetime-bound API, but adjust the way the library gets loaded (e.g. to use eager binding). Add Library::new_with_flags and a LoadFlags type to provide an easier way to do this.

nagisa commented 4 weeks ago

Converting a os::Library into plain Library with an .into() seems pretty straightforward to me, so the safer API is within arm's reach at all times.

The fact that LoadFlags is a OS dependent typedef seems iffy -- code written in a portable seeming way isn't actually portable. More generally I consider that to be a major footgun with exposing any sort of exposition of OS-specific details outside the os::* modules and unless there is a very very good reason I would rather not break the os::* encapsulation. At least not until https://github.com/rust-lang/rust/issues/41619 is implemented and libstd (and thus the ecosystem) expectations change with regards to what looks "portable".

tgross35 commented 4 weeks ago

I don't know why I didn't consider just .intoing it. That's way easier, thanks!