-
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
Add simple docs example for struct Cell #43423
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,29 @@ use ops::{Deref, DerefMut, CoerceUnsized}; | |
use ptr; | ||
|
||
/// A mutable memory location. | ||
/// | ||
/// ``` | ||
/// use std::cell::Cell; | ||
/// | ||
/// struct SomeStruct { | ||
/// regular_field: u8, | ||
/// special_field: Cell<u8>, | ||
/// } | ||
/// | ||
/// let my_struct = SomeStruct { | ||
/// regular_field: 0, | ||
/// special_field: Cell::new(1), | ||
/// }; | ||
/// | ||
/// let new_value = 100; | ||
/// | ||
/// // ERROR, because my_struct is immutable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also one above this line |
||
/// // immutable.regular_field = new_value; | ||
/// | ||
/// // WORKS, special_field is mutable because it is Cell | ||
/// immutable.special_field.set(new_value); | ||
/// assert_eq!(immutable.special_field.get(), new_value); | ||
/// ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this follows the prevailing style in the docs. For example, I think it is at least missing an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added some prose and example section. Maybe it's just me but I was reading this https://doc.rust-lang.org/std/cell/ a few times and still didn't know what |
||
/// | ||
/// See the [module-level documentation](index.html) for more. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also above this line