Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAPI Docs: ffi #29354
Comments
steveklabnik
added
the
A-docs
label
Oct 26, 2015
steveklabnik
referenced this issue
Oct 26, 2015
Closed
The Standard Library Documentation Checklist #29329
This comment has been minimized.
This comment has been minimized.
seankerr
commented
Nov 16, 2015
|
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. |
steveklabnik
referenced this issue
Jan 6, 2016
Closed
Explain what an "OS string" is in OsStr/OsString docs #30743
This comment has been minimized.
This comment has been minimized.
|
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. |
steveklabnik
added
the
E-mentor
label
Mar 8, 2017
This comment has been minimized.
This comment has been minimized.
|
I am happy to mentor anyone who wants to tackle this issue. |
This comment has been minimized.
This comment has been minimized.
seankerr
commented
Mar 9, 2017
|
@steveklabnik I'd be happy to write the docs on these provided some guidance. When are you available for a quick doc lesson? |
This comment has been minimized.
This comment has been minimized.
|
@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. |
steveklabnik
added
the
T-doc
label
Mar 10, 2017
This comment has been minimized.
This comment has been minimized.
|
@seankerr I've updated the issue with some more details here |
steveklabnik
added
P-medium
E-help-wanted
E-medium
and removed
A-docs
labels
Mar 24, 2017
This comment has been minimized.
This comment has been minimized.
jck
commented
Mar 25, 2017
|
I would also like to volunteer for writing the ffi docs. |
This comment has been minimized.
This comment has been minimized.
|
Great, thank you @jck ! Let me know if you need any help. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Might be good to mention at the module level that FFI stands for "foreign function interface". |
This comment has been minimized.
This comment has been minimized.
|
Small example of something to include in |
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 24, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm familiar with this module and would be happy to update the docs. Should I just start submitting PRs? |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
I'll continue with these docs next week. Do those two commits look like going in the right direction? |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
That's a good question. @rust-lang/libs? |
This comment has been minimized.
This comment has been minimized.
|
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 :( |
federicomenaquintero
referenced this issue
Sep 26, 2017
Merged
Improved docs for CStr, CString, OsStr, OsString #44855
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Oct 13, 2017
This comment has been minimized.
This comment has been minimized.
|
This is merged; can the issue be closed? (Also, in the parent #29329) |
This comment has been minimized.
This comment has been minimized.
|
|
steveklabnik
closed this
Nov 21, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
steveklabnik commentedOct 26, 2015
•
edited
Part of #29329
http://doc.rust-lang.org/std/ffi/
Here's what needs to be done to close out this issue:
CStrshould make the comparison withstr. it needs a lot of links.CStringshould make the comparison withString.It also needs a lot of links.FromBytesWithNulErrorshould use the iterator style boilerplate for linking to where it came from.IntoStringErrorsameNulErrorsame.OsStrshould make thestrcomparison, and needs a lot more elaboartion. It should look likeCStr.OsStringshould make the comparison withString, and should look a lot likeCString.