-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Docs: ffi #29354
Comments
One of the constant reminders I tell myself when working with FFI is that CStr consumes a C NULL terminated string, and that CString represents one. It would be nice if the documentation for both of these structs indicated their purpose, and contained basic FFI examples for using them. |
OsString docs say
I'm not sure if that's entirely correct and it's slightly confusing. On Windows at least you need another step through OsStrExt that is costly. Also, the reverse conversion is always costly (O(n)) to do safely. |
I am happy to mentor anyone who wants to tackle this issue. |
@steveklabnik I'd be happy to write the docs on these provided some guidance. When are you available for a quick doc lesson? |
@seankerr awesome! We can do it asynchronously on this issue, or synchronously if you ping me on IRC, I'm around most often during 10-6ish EST, but at other times too, and sometimes I'm in meetings. |
@seankerr I've updated the issue with some more details here |
I would also like to volunteer for writing the ffi docs. |
Great, thank you @jck ! Let me know if you need any help. |
Contrary to what some might assume, Potential rule of thumb: if it's meant to go into or come out of As this is a relatively reasonable assumption users might make (particularly prompted by the significant body of existing external documentation about interop between Rust and C that points users to these types), the docs should probably make this point very clear. (For reference: an internals thread about |
In the discussion @DanielKeep mentions there was confusion about whether "C-compatible string" means just So it may be worth to clarify in the docs that |
Currently docs don't explicitly say whether 8-bit encodings other than UTF-8 are allowed in There are methods for converting from and to UTF-8-encoded strings, but does it meant that |
I don't think it's useful to have this discussion in two places. The current CString API is clearly meant for null-terminated byte strings with unspecified encoding, as all the |
Might be good to mention at the module level that FFI stands for "foreign function interface". |
Small example of something to include in |
I'm familiar with this module and would be happy to update the docs. Should I just start submitting PRs? |
@federicomenaquintero Absolutely! Start working on the bits you're willing to take on, and submit PRs whenever you're ready. You don't have to tackle the whole list up top at once. |
I'll continue with these docs next week. Do those two commits look like going in the right direction? |
I'm a bit miffed by two notes in the documentation.
It sounds like at some point CStr was intended to really only wrap a I'm happy to note in the docs where validation is being done in linear time. However, should we keep those specific comments around? Or are there plans to change |
That's a good question. @rust-lang/libs? |
If Now what we want to have is something like: struct CStr(u8);
impl !Sized for CStr {}
mem::size_of::<CStr>(); // compile error
mem::size_of::<&CStr>() == mem::size_of::<usize>(); That's probably unlikely to happen for awhile though :( |
…eklabnik Improved docs for CStr, CString, OsStr, OsString This expands the documentation for those structs and their corresponding traits, per rust-lang#29354
This is merged; can the issue be closed? (Also, in the parent #29329) |
👍 ❤️ |
Thanks! |
Part of #29329
http://doc.rust-lang.org/std/ffi/
Here's what needs to be done to close out this issue:
CStr
should make the comparison withstr
. it needs a lot of links.CString
should make the comparison withString.
It also needs a lot of links.FromBytesWithNulError
should use the iterator style boilerplate for linking to where it came from.IntoStringError
sameNulError
same.OsStr
should make thestr
comparison, and needs a lot more elaboartion. It should look likeCStr
.OsString
should make the comparison withString
, and should look a lot likeCString
.The text was updated successfully, but these errors were encountered: