Closed Rantanen closed 5 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*
.
CString
/&CStr
So in total we now have:
BString
/&BStr
String
/&str
CString
/&CStr
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).
Current plan
https://github.com/Rantanen/intercom-site/blob/master/content/docs/types/strings.md
Legacy thoughts
Currently
String
is converted toBStr
.It might be more sensible to reduce the automation in this sense. Perhaps use the following mappings:
BStr
-BSTR
OsString
-WCHAR*
on Windows,char*
on Linux.String
-char*
everywhere. Essentially beingstd::string
compatible.Eager implement for
AsRef
/From
/etc. onBStr
would be needed for this to be sensible.On Windows
BStr
would be allocated withSysAllocString
while everything else would use theCoTaskMemAlloc
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.