-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Many From
implementations are undocumented
#51430
Comments
add some docs to `From` conversions This adds a helpful document to the bool → int* conversions as well as to the lossless integer conversions. One of #51430 down, some more to go.
@frewsxcv After speaking to @steveklabnik, I'd be willing to mentor this. Can you add the E-easy and E-mentor labels and assign me? |
TutorialTo fix this issue, we have to go through the whole rustc codebase
The goal is to improve this situation. Picking a taskThis assumes some basic git knowledge. If you need help with git, this short tutorial
impl From<Foo> for Bar {
/// Converts a `Foo` into a `Bar`.
/// This conversion does not allocate.
fn from(f: Foo) -> Bar {
//....
}
}
What to documentHave a close look at the implementation and try to find out what it does. Keep an eye out for:
Don't feel bad if the resulting text feels formulaic or repetetive, that's very If you have some brain cycles free, try to find a clear, understandable wording. If you are confused or stuck, please get back here as well. This is what |
This is an incomplete list of
|
Hey @skade, I would be up for the task. I skimmed through I have experienced with JavaScript (and some other languages), but just played around with Rust a bit. Therefore would need some help. |
I’d like to help. Can I work on |
@cruessler Sure! |
@gruberb Hi! I'd be happy to help! How about you open a pull request and we start discussing there? Path is one of the things where "(heap) allocates" vs. "not" is of particular importance. |
Good Morning @skade, I would like to work on liballoc/boxed.rs. I will create a pull request as per the documentation. |
Hi @skade, I would like to work on I will work on them and issue a pull request in due course |
@skade The |
@skade I'd like to take a stab at |
@cruessler If you feel like they can't be improved, it's fine to keep things the way they are. Findings in a comment would be great, than we can mark them as completed and know why. 👍 |
@cypher \o/ go ahead! |
Here’s what I found:
None of the implementations does heap allocation, all of them barely do anything besides bitshifting. These implementations are currently undocumented:
These implementations are currently currently documented and have an example:
Example for documentation:
This implementation only comes with an example:
ConclusionIf the documentation is supposed to be consistent, adding a short sentence (like the one cited above) and an example to every implementation seems like a good solution to me. Since that would be very repetitive, adding the comment in one, central location might be an alternative. What do you think? |
@skade I've pushed a branch with my first stab at documenting the From conversion: https://github.com/cypher/rust/tree/document-from-trait-in-ffi Not sure if I read the various methods right in regards to copying or allocating data, so someone more knowledgable should double-check those. Should I just open a pull request, or do you want to take a look first? |
@skade I'll see what I can do with libserialize/json.rs if that one isn't taken. Edit: I'm probably on the lower end of the target demographic for this kind of E-mentoring. Assuming I get everything sorted with the first one, would it be ok if I did a few of these (or maybe more than a few) to make sure I really get what's going on? Thanks for your time! |
…r=steveklabnik Document From trait implementations for OsStr, OsString, CString, and CStr As part of issue rust-lang#51430 (cc @skade). The allocation and copy claims should be double-checked. r? @steveklabnik
Write docs for SyncOnceCell From and Default impl Part of rust-lang#51430
Write docs for SyncOnceCell From and Default impl Part of rust-lang#51430
Write docs for SyncOnceCell From and Default impl Part of rust-lang#51430
…ocs, r=Mark-Simulacrum Clean up and add doc comments for CStr CC rust-lang#51430
…ocs, r=Mark-Simulacrum Clean up and add doc comments for CStr CC rust-lang#51430
…ocs, r=Mark-Simulacrum Clean up and add doc comments for CStr CC rust-lang#51430
Among other changes, documents whether allocations are necessary to complete the type conversion. Part of rust-lang#51430 Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com> Co-authored-by: Joshua Nelson <github@jyn.dev>
Among other changes, documents whether allocations are necessary to complete the type conversion. Part of rust-lang#51430 Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com> Co-authored-by: Joshua Nelson <github@jyn.dev>
Among other changes, documents whether allocations are necessary to complete the type conversion. Part of rust-lang#51430 Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com> Co-authored-by: Joshua Nelson <github@jyn.dev>
…ersions, r=m-ou-se Add documentation to boxed conversions Among other changes, documents whether allocations are necessary to complete the type conversion. Part of rust-lang#51430, supersedes rust-lang#89199
…ersions, r=m-ou-se Add documentation to boxed conversions Among other changes, documents whether allocations are necessary to complete the type conversion. Part of rust-lang#51430, supersedes rust-lang#89199
Hi @skade, I'd like to do |
May I ask in which directory you guys are calling rg -trust '(?! \s+///.*\n)(\s+#\[inline\])?\s+fn from\(' -U --pcre2 src/ and rg -trust '(?! \s+///.*\n)(\s+#\[inline\])?\s+fn from\(' -U --pcre2 src/ | rg '\blib' but I don't get any outputs from |
…-Simulacrum Document `&CStr` to `CString` conversion Related to rust-lang#51430
…-Simulacrum Document `&CStr` to `CString` conversion Related to rust-lang#51430
…-Simulacrum Document `&CStr` to `CString` conversion Related to rust-lang#51430
Rollup merge of rust-lang#120458 - rytheo:cstr-conversion-doc, r=Mark-Simulacrum Document `&CStr` to `CString` conversion Related to rust-lang#51430
…ark-Simulacrum Document various I/O descriptor/handle conversions Related to rust-lang#51430
Rollup merge of rust-lang#120459 - rytheo:handle-conversion-docs, r=Mark-Simulacrum Document various I/O descriptor/handle conversions Related to rust-lang#51430
Is this something I could pick up? I want to contribute but don't know if this is a good issue. |
While
std::convert::From
has very detailed high level documentation, the implementations often lack docs on how they work and use the default "performs the conversion" boilerplate.This at least includes all
String
methods, also, all integer conversions. Both of these can have interesting behaviour, especially in relation to each other. For example, the different allocation behaviour betweenFrom<Box<str>>
andFrom<&'a str>
is notable and hard to figure out from the source, as it goes through three layers of indirection.The text was updated successfully, but these errors were encountered: