Originally posted by Volta
View Post
I know:
- std::ffi:OsString
- std::ffi:CString
- std::String
See also std::ffi documentation
They have their corresponding view types (c.f. std::string_view in C++). That's probably how you reached six types.
Biggest difference to C and C++ when it comes to strings is that they aren't YOLO types, i.e. when you construct one of these types (without unsafe keyword) the standard library checks that they are valid. And their API guarantees that they stay valid.
The first ffi type, OsString is operating system defined. It is used for interfacing with the file system (without having to pay the conversion to std::string), and CString is a null terminated string with undefined encoding. The corresponding view can be used wherever you need a char pointer in C.
Leave a comment: