-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[READY FOR REVIEW] Ch15 edits #898
Conversation
79c08bf
to
6b01ff8
Compare
f5b37d1
to
5401713
Compare
#### A Use Case for Interior Mutability: Mock Objects | ||
|
||
A *mock object* is the general programming concept for a type that stands in | ||
the place of another type during testing. Mock objects simulate real objects, |
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.
A test double is the generic thing that stands in for another. A mock object is a specific type of double that records what happens.
Suggest rewording to
A test double is the general programming concept for a type that stands in the place of another type during testing. Mock objects are specific types of test doubles that record what happens during a test so that we can assert that the correct actions took place.
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.
lookin great!
ordinary struct are that smart pointers implement the `Deref` and `Drop` | ||
traits, and in this chapter we’ll be discussing both of those traits and why | ||
they’re important to smart pointers. | ||
A *pointer* is the generic programming concept for an address to a location |
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.
I'm finding both the original sentence and this re-word a bit awkward; what about
A pointer is a general concept for a variable that contains an address in memory. This address refers to, or "points at", some other data.
*reference*, which we learned about in Chapter 4. References are indicated by | ||
the `&` symbol and borrow the value that they point to. They don't have any | ||
special abilities other than referring to data, but they also don't have any | ||
more overhead than they need to do straightforward referencing, so they're used |
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.
they also don't have any overhead, so they're used
|
||
* `Box<T>` for allocating values on the heap | ||
* `Rc<T>`, a reference counted type that enables multiple ownership | ||
* `Ref` and `RefMut`, accessed through `RefCell<T>`, a type that enforces the |
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.
Ref<T>
and RefMut<T>
second-edition/src/ch15-01-box.md
Outdated
advantage to this can be, help them know when they'd use this? --> | ||
<!-- Correct! Recap below: /Carol --> | ||
|
||
Boxes don't have a lot of performance overhead, but they don't have a lot of |
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.
I am slightly unsure about this phrasing; boxes have no overhead other than being on the heap. Not sure how to best communicate that....
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.
There's the redirection, yeah? Isn't that a bit of overhead? I'm fine saying "Boxes don't have performance overhead other than being on the heap instead of on the stack", how does that sound?
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.
That "redirection" is a consequence of being on the heap, nothing else 😄
how does that sound?
👍
second-edition/src/ch15-01-box.md
Outdated
### Using a `Box` to Store Data on the Heap | ||
|
||
Before we get into a use case for `Box`, let's get familiar with the syntax and | ||
how to interact with values stored within a `Box`. |
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.
either box
or Box<T>
in this paragraph
second-edition/src/ch15-04-rc.md
Outdated
turn it on. Others can come into the room and watch the TV. When the last | ||
person leaves the room, they turn the TV off because it's no longer being used. | ||
If someone turns the TV off while others are still watching it, there'd be | ||
uproar from the remaining TV watchers! |
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.
👍
function and pass a reference to the `Rc` in `a` as an argument. | ||
|
||
We could have called `a.clone()` rather than `Rc::clone(&a)`, but Rust | ||
convention is to use `Rc::clone` in this case. The implementation of `clone` |
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.
... it is?
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.
yup:
- Provide a more explicit way to "clone" a standard reference counted pointer. rfcs#1954
- Add CLONE_ON_REF_PTR lint rust-clippy#2037
also you've heard about this before: rust-lang/rust#42137 (comment)
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.
uuuuuuuuuuuuugh welp time to update my brain. thanks ❤️
certain memory safe scenarios are then allowed, whereas they are disallowed by | ||
the compile time checks. Static analysis, like the Rust compiler, is inherently | ||
conservative. Some properties of code are impossible to detect by analyzing the | ||
code: the most famous exampled is the Halting Problem, which is out of scope of |
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.
example
RefCell<T> is, perhaps a succinct round up would help? --> | ||
<!-- Done /Carol --> | ||
|
||
To recap the reasons to choose `Box<T>`, `Rc<T>`, or `RefCell<T>`: |
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.
putting this at this part of the book feels weird to me; it feels like it should be a summary, but we don't really have "end of the chapter summaries" or anything. hm
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.
yeah i just put it in here to satisfy the comment. it feels a little weird in this spot too :-/ wdyt-- take it out entirely? we do have the ## Summary
section at the end of 15-06?
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.
yeah either take it out or put it in the summary. i'd lean towards taking it out
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.
so natalie said she really liked this section here, that it tied things together before getting deep into interior mutability.
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.
hmmmmmmmmmmm
`Mutex<T>`, which offers interior mutability that's safe to use across threads, | ||
and we'll be discussing its use in the next chapter on concurrency. Check out | ||
the standard library docs for more details on the differences between these | ||
types. |
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.
this whole example is excellent, thanks so much for all the work on it ❤️
@steveklabnik could you review these changes that i made to address comments from you, jake, natalie, and open issues for this chapter? 17da5ac...2fa362e |
Looks good to me, though one of those commit messages is now incorrect in the other direction, as I commented on the issue it's addressing. |
04a432f
to
fc3a73d
Compare
ok, i fixed the commit message and i'm merging this and sending over to nostarch :) thank youuuuuuu |
Ok I think this is ready for review now @steveklabnik <3