Rantanen / intercom

Object based cross-language FFI for Rust
MIT License
63 stars 7 forks source link

Support other string types #27

Closed Rantanen closed 5 years ago

Rantanen commented 6 years ago

Current plan

https://github.com/Rantanen/intercom-site/blob/master/content/docs/types/strings.md


Legacy thoughts

Currently String is converted to BStr.

It might be more sensible to reduce the automation in this sense. Perhaps use the following mappings:

Eager implement for AsRef/From/etc. on BStr would be needed for this to be sensible.

On Windows BStr would be allocated with SysAllocString while everything else would use the CoTaskMemAlloc APIs. Not sure what the equivalent on Linux would be, if any. The fallback for both systems would be to use the #6 APIs once we get those.

Rantanen commented 6 years ago

OsString should be BSTR on Windows. This is compatible with APIs expecting WCHAR* as long as they don't take ownership of the memory.

With this change OsString is the preferred string to use when trying to achieve best compatibility with the platform expectations.

The WCHAR* type should be represented with &[u16] or Vec<u16> in the future, as this is the type that std::os::windows::ffi uses for WCHAR*.

Rantanen commented 5 years ago

85 landed a while back, which added CString/&CStr

So in total we now have:

The UString/&UStr variant is missing. We can implement that as the C++ wrapper gets support for that. For now the "native C string" is Rust's built-in CString (just a raw zero terminated char* string).