-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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: thread #29378
Comments
I am happy to mentor anyone who wants to tackle this issue. |
I would be interested in taking on the documentation improvement of |
@OldManMike awesome! Please let me know if you need anything. |
I am not (by any means) an expert on this topic but I'd love to help on this one, as @steveklabnik says: writting docs is the best way to learn something |
I believe I will be taking the joinHandle and Thead docs |
Rewrote the thread struct docs rust-lang#29378
I would like to tackle this issue too and add an example on Result. Feel free to stop me if you are already working on it! (but it seems nobody took it right now) |
Ok so I still need some mentoring! Here is a (working) example I quickly wrote for use std::thread;
fn main() {
let child = thread::spawn(move || panic!("Oups"));
let res: thread::Result<()> = child.join();
match res {
Ok(_) => println!("this is fine"),
Err(_) => println!("thread panicked"),
}
} I think (but not sure) this example could help because type is explicit, so the user know what he can do with this @steveklabnik asked:
But I'm not sure to understand what does "use std::thread; thread::Result" means. I read an other example in std on Anyway, I'm not sure my example follows best practices. And I'm not sure it's useful. So, once again @steveklabnik please help! :) |
It's what you wrote, specifically use std::thread;
let res: thread::Result<()> ... that is, you use this style instead of
I think this example is okay, but we might be able to make it better! What about a function that does the spawn and join, and returns the result? then, you wouldn't be adding the extra type for no reason, as the function signature would use it. This is similar to how the The question is what that function should do... |
Okay, I think you mean: use std::thread;
fn spawn_and_join() -> thread::Result<()> {
let child = thread::spawn(move || panic!("Oups"));
child.join()
}
fn main() {
match spawn_and_join() {
Ok(_) => println!("this is fine"),
Err(_) => println!("thread panicked"),
}
} But...
From there I'm a bit lost: my example has still no sense (what's that fn open_file_in_thread() -> thread::Result<()> {
let child = thread::spawn(move || {
File::open("foo.txt").unwrap();
// etc.
});
child.join()
} But it's a "not real" example either. Should I give up? EDIT: Maybe a file copy in a thread could be more realistic: use std::thread;
use std::fs;
fn copy_in_thread() -> thread::Result<()> {
thread::spawn(move || { fs::copy("foo.txt", "bar.txt").unwrap(); }).join()
}
fn main() {
match copy_in_thread() {
Ok(_) => println!("this is fine"),
Err(_) => println!("thread panicked"),
}
} |
join method returns a thread::Result Join method returns a std::thread::Result, not a std::result::Result: https://doc.rust-lang.org/std/thread/struct.JoinHandle.html#method.join Maybe I misunderstood something. I have seen this mistake(?) because I wanted to tackle this issue rust-lang#29378 (about Result). It's still one of my first PR. Sorry if I missed something.
join method returns a thread::Result Join method returns a std::thread::Result, not a std::result::Result: https://doc.rust-lang.org/std/thread/struct.JoinHandle.html#method.join Maybe I misunderstood something. I have seen this mistake(?) because I wanted to tackle this issue rust-lang#29378 (about Result). It's still one of my first PR. Sorry if I missed something.
@steveklabnik Hey ! I'm a bit rusty (haven't rusted in a year or so), so I'm looking to get back to it by helping with the docs, which item still need documentation in the list ? Cheers |
@gamazeps wonderful! Everything except the last one is still open, and that's because there's a PR open, but not merged, hence no checkmark. |
@steveklabnik Ok, sign me in for:
Should be done by wednesdy in the worst case scenario :) |
Add an example to std::thread::Result type This PR is a part of #29378. I submit this PR with the help (mentoring) of @steveklabnik. I'm still not sure my request is good enough but I don't want to spoil the issue with too much questions so I continue here. r? @steveklabnik
…umeGomez [Doc] Explain why `thread::yield_now` could be used. Part of rust-lang#29378. r? @steveklabnik
…eGomez [Doc] Implrove `thread::Builder`'s doc. Part of rust-lang#29378 . - Explains *why* we would use the builder instead ofthe free function. - Changes the parent-child explanation for a spawned-caller in `thread::Builder::spawn` - Adds a link to `io::Result` in `thread::Builder` - Corrects the return type doc in `thread::Builder::spawn` r? @rust-lang/docs
[Doc] Add links to the `thread::LocalKey` doc. Part of rust-lang#29378 . I do not know exactly what should be done for the `cleanup` part, if you have any idea I'll gladly do it. r? @rust-lang/docs
…umeGomez [Doc] Explain why `thread::yield_now` could be used. Part of rust-lang#29378. r? @steveklabnik
…eGomez [Doc] Implrove `thread::Builder`'s doc. Part of rust-lang#29378 . - Explains *why* we would use the builder instead ofthe free function. - Changes the parent-child explanation for a spawned-caller in `thread::Builder::spawn` - Adds a link to `io::Result` in `thread::Builder` - Corrects the return type doc in `thread::Builder::spawn` r? @rust-lang/docs
[Doc] Add links to the `thread::LocalKey` doc. Part of rust-lang#29378 . I do not know exactly what should be done for the `cleanup` part, if you have any idea I'll gladly do it. r? @rust-lang/docs
@gamazeps thank you so much! ❤️ |
…umeGomez [Doc] Explain why `thread::yield_now` could be used. Part of rust-lang#29378. r? @steveklabnik
…eGomez [Doc] Implrove `thread::Builder`'s doc. Part of rust-lang#29378 . - Explains *why* we would use the builder instead ofthe free function. - Changes the parent-child explanation for a spawned-caller in `thread::Builder::spawn` - Adds a link to `io::Result` in `thread::Builder` - Corrects the return type doc in `thread::Builder::spawn` r? @rust-lang/docs
[Doc] Add links to the `thread::LocalKey` doc. Part of rust-lang#29378 . I do not know exactly what should be done for the `cleanup` part, if you have any idea I'll gladly do it. r? @rust-lang/docs
…umeGomez [Doc] Explain why `thread::yield_now` could be used. Part of rust-lang#29378. r? @steveklabnik
…eGomez [Doc] Implrove `thread::Builder`'s doc. Part of rust-lang#29378 . - Explains *why* we would use the builder instead ofthe free function. - Changes the parent-child explanation for a spawned-caller in `thread::Builder::spawn` - Adds a link to `io::Result` in `thread::Builder` - Corrects the return type doc in `thread::Builder::spawn` r? @rust-lang/docs
[Doc] Add links to the `thread::LocalKey` doc. Part of rust-lang#29378 . I do not know exactly what should be done for the `cleanup` part, if you have any idea I'll gladly do it. r? @rust-lang/docs
…umeGomez [Doc] Explain why `thread::yield_now` could be used. Part of rust-lang#29378. r? @steveklabnik
…eGomez [Doc] Implrove `thread::Builder`'s doc. Part of rust-lang#29378 . - Explains *why* we would use the builder instead ofthe free function. - Changes the parent-child explanation for a spawned-caller in `thread::Builder::spawn` - Adds a link to `io::Result` in `thread::Builder` - Corrects the return type doc in `thread::Builder::spawn` r? @rust-lang/docs
[Doc] Add links to the `thread::LocalKey` doc. Part of rust-lang#29378 . I do not know exactly what should be done for the `cleanup` part, if you have any idea I'll gladly do it. r? @rust-lang/docs
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn` Part of rust-lang#29378. Explains why the constraints on the closure and its return value are `'static` and `Send`. Allows to tick of `thread::spawn` from the list of things to document in the `thread` module. r? @steveklabnik
Part of rust-lang#29378 . - Adds an example of a thread detaching. - Expands what `detaching` means.
[Doc] Expands `detach` documentation in `thread::JoinHande`. Part of rust-lang#29378 . - Adds an example of a thread detaching. - Expands what `detaching` means. r? @steveklabnik
Hi @steveklabnik! I'd LOVE to help bring this across the finish line but with the last documentation issue for the module docs. I'd greatly appreciate some guidance with where to start if it's possible 🙂 |
Hey @seanprashad that'd be amazing! One option is
Which would be a bunch of work but might be the way to go. Basically, I don't think the docs are organized well; they're kind of just a random collection of thoughts. So I think the first task is, how do we want to organize these docs? Generally, good module docs show an overview of the module conceptually, and then highlight key APIs. Maybe we can start there? |
Quoting myself above:
We haven't come up with a good plan for the module docs, and so I'm going to close this ticket. If anyone has specific thoughts about improving them, please open a new ticket with details! Thanks. |
Part of #29329
http://doc.rust-lang.org/std/thread/
Here's what needs to be done to close out this issue:
Builder
's docs are... okay. Just very uninspired.JoinHandle
doesn't go into enough detail, and should show off, for example, the detach behavior.LocalKey
could use some links and general cleanup.Thread
has very little and very boring docs.panicking
could use some more advice on when to use this.park
should have its module documentation inlined here, and cleaned up.park_timeout
could use links topark
spawn
needs a lot more docs generally. It's the main interface to this module!yield_now
doesn't explain any of the "why".Result
should at least show off the "use std::thread; thread::Result" pattern, like all module-specificResult
types.The text was updated successfully, but these errors were encountered: