rust_libloading icon indicating copy to clipboard operation
rust_libloading copied to clipboard

Provide a `Library::get` method that accepts `&CStr`

Open EFanZh opened this issue 1 year ago • 1 comments

The document of Library::get says that the symbol “may not contain any null bytes, with the exception of the last byte”, which is exactly what CStr is. So I think it is reasonable to provide a get method that accepts &CStr. Changing the current Library::get method is a breaking change, so a new method might need to to be added.

EFanZh avatar Nov 15 '24 13:11 EFanZh

The bytestring passed in to get is allowed to not contain the trailing null too, but if one is present it must be the last byte. CStr meanwhile requires that the last byte is null. The only reason for the bytestring in this API is because at the time literals (the predominant use-case) could only produce &str or &[u8]. Nowadays there are c literals, so it might actually make sense to change to &CStr.

Breaking changes are not a huge deal, the library is still pre 1.0.

nagisa avatar Nov 15 '24 13:11 nagisa