Skip to content
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

Merged
merged 6 commits into from Aug 2, 2017
Merged

Add simple docs example for struct Cell #43423

merged 6 commits into from Aug 2, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jul 23, 2017

No description provided.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @BurntSushi (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

/// // WORKS, special_field is mutable because it is Cell
/// immutable.special_field.set(new_value);
/// assert_eq!(immutable.special_field.get(), new_value);
/// ```
Copy link
Member

Choose a reason for hiding this comment

The 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 Examples header. I'd also like to see some prose describing what the example is trying to show.

cc @steveklabnik

Copy link
Author

@ghost ghost Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some prose and example section.
BTW: I'd see reference to this blog post:
https://ricardomartins.cc/2016/06/08/interior-mutability
in the docs. but perhaps adding links to blog post is not the way of doing docs. :)

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 Cell is all about then read the blog post once to get the concept easily.. .

@BurntSushi BurntSushi added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 24, 2017
Copy link
Member

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits, and the build is failing.

@@ -187,6 +187,34 @@ use ops::{Deref, DerefMut, CoerceUnsized};
use ptr;

/// A mutable memory location.
///
/// # Example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be Examples even though there's only one, for consistency

///
/// # Example
///
/// Here you can see how using `Cell<T>` allows to use muttable field inside
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutable, not muttable

/// # Example
///
/// Here you can see how using `Cell<T>` allows to use muttable field inside
/// immutable struct (which is also called "interior mutability").
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single quotes here please!

Tymoteusz Jankowski added 2 commits July 24, 2017 18:01
@ghost
Copy link
Author

ghost commented Jul 24, 2017

@steveklabnik done

Copy link
Member

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry! just some last-minute white space changes; I must have missed them before?

This is good to go once that's fixed; I want to make sure this is consistent with the rest of the standard library.

@@ -187,6 +187,29 @@ use ops::{Deref, DerefMut, CoerceUnsized};
use ptr;

/// A mutable memory location.
/// # Examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put a /// above and below this line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like here? 8286075

Because i put it at first place and it was the cause of CI failure (something related to tidy check)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. you had trailing whitespace; that was the only issue, not the ///s. In other words

"///"

not

"/// "

make sense?

/// # Examples
/// Here you can see how using `Cell<T>` allows to use mutable field inside
/// immutable struct (which is also called 'interior mutability').
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also above this line

/// let new_value = 100;
/// // ERROR, because my_struct is immutable
/// // immutable.regular_field = new_value;
/// // WORKS, although `my_struct` is immutable, field `special_field` is mutable because it is Cell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also one above this line

/// };
///
/// let new_value = 100;
/// // ERROR, because my_struct is immutable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also one above this line

/// // immutable.regular_field = new_value;
///
/// // WORKS, although `my_struct` is immutable, field `special_field` is mutable because it is Cell
/// immutable.special_field.set(new_value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main isn't the issue. here's the error

01:00:45] 	error[E0425]: cannot find value `immutable` in this scope

[01:00:45]   --> <anon>:22:1

[01:00:45]    |

[01:00:45] 22 | immutable.special_field.set(new_value);

[01:00:45]    | ^^^^^^^^^ not found in this scope

[01:00:45] 

[01:00:45] error[E0425]: cannot find value `immutable` in this scope

[01:00:45]   --> <anon>:23:12

[01:00:45]    |

[01:00:45] 23 | assert_eq!(immutable.special_field.get(), new_value);

[01:00:45]    |            ^^^^^^^^^ not found in this scope

[01:00:45] 

on this line, you use something called "immutable" but you never defined it; it's called my_struct above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right.. maybe i should go to sleep for today :)

@ghost
Copy link
Author

ghost commented Jul 25, 2017

r? @steveklabnik is it ok, what do you think?

@carols10cents carols10cents added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 31, 2017
@carols10cents
Copy link
Member

carols10cents commented Jul 31, 2017

friendly ping for review @steveklabnik !

@carols10cents
Copy link
Member

r? @steveklabnik

@steveklabnik
Copy link
Member

@bors: r+ rollup

@xliiv thanks a ton! Sorry for the delays again ☹️

@bors
Copy link
Contributor

bors commented Jul 31, 2017

📌 Commit d429a4e has been approved by steveklabnik

@ghost
Copy link
Author

ghost commented Jul 31, 2017

@steveklabnik you are welcome :)
I didn't know that contributing to rust is so easy (at least contributing to docs)

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Aug 2, 2017
bors added a commit that referenced this pull request Aug 2, 2017
Rollup of 6 pull requests

- Successful merges: #43389, #43423, #43581, #43585, #43597, #43598
- Failed merges:
@bors bors merged commit d429a4e into rust-lang:master Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants