Changing Original Library API when writing Wrappers

David Hurka david.hurka at mailbox.org
Sun Jan 30 22:42:42 GMT 2022


On Sunday, January 30, 2022 2:20:10 PM CET Ayush Singh wrote:
> An example of this situation:
> `QString readGenericName () const`
> method of KDesktopFile
> (https://api.kde.org/frameworks/kconfig/html/classKDesktopFile.html#aaf263b7
> 9cce3125c9e6e52428e05c524). If I am doing a one-to-one wrapping, the Rust
> function definition
> would look something like this:
> `fn read_generic_name(&self) -> QString`
> By default, this function returns `QString()` in case the key is not
> present in the `.desktop` file. According to me, a better definition
> for this function will be:
> `fn read_generic_name(&self) -> Option<QString>`
> The function will return `None` if the key is not present in this case.

I remember that there were plans to use std::optional<> for return types in a 
future version, so KConfig would end up to use the C++ interface you propose 
for Rust. So your suggestion seems appropriate in this special case.

Besides that, I think that this example is fairly low-level. If you adapt 
towards Rust here, you preserve the overall way to use the library, and you 
just have a more elegant way to reach your goal.

Cheers, David




More information about the kde-core-devel mailing list