nagisa / rust_libloading

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

Consider adding libloading::Library::this() #96

Closed MatrixDev closed 2 years ago

MatrixDev commented 2 years ago

Currently Library struct has only one method for creation - Library::new(). It would be really nice to add Library::this() as well. It is already implemented for unix and windows anyways.

So instead of writing this:

#[cfg(unix)]
fn open_self(..) -> Result<Library> {
    Ok(Library::from(libloading::os::unix::Library::this()))
}
#[cfg(windows)]
fn open_self(..) -> Result<Library> {
    Ok(Library::from(libloading::os::windows::Library::this()?))
}

let library = open_self();

Users can just simply write:

let library = Library::this();

Yes, libloading::os::unix::Library::this() cannot fail. But it doesn't really matter when you're writing cross-platform code, as you need to handle errors from everywhere anyways. This can be considered as a very useful helper.

nagisa commented 2 years ago

The behaviour between the two environments is sufficiently distinct in what symbols are made available that a common cross-platform wrapper isn't really feasible.

The documentation for the methods calls it out too.

MatrixDev commented 2 years ago

Thanks for a quick reply. You can close this issue if there are really no common symbols that can be accessed.

nagisa commented 2 years ago

Thank you for taking time to request a change regardless.