-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Arbitrary self types v2: book changes. #4174
Draft
adetaylor
wants to merge
10
commits into
rust-lang:main
Choose a base branch
from
adetaylor:arbitrary-self-types-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
29722ea
Arbitrary self types v2: book changes.
adetaylor a1b42a5
Update listings/ch15-smart-pointers/listing-15-30/src/main.rs
adetaylor 90ab8e9
Update listings/ch15-smart-pointers/listing-15-30/src/main.rs
adetaylor 6e82fe0
Update src/ch15-02-deref.md
adetaylor 4c71485
Update listings/ch15-smart-pointers/listing-15-30/src/main.rs
adetaylor 74e01ff
Update src/ch15-02-deref.md
adetaylor 7dc229f
Update src/ch15-02-deref.md
adetaylor 4d99460
File rename.
adetaylor 8cf061f
Tweaks.
adetaylor eb80d90
Possible fix.
adetaylor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "deref-method-example" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
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. Here, the overall idea seems good, but I want to make a couple tweaks to make it fit better with the flow of the text. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![feature(arbitrary_self_types)] | ||
// TODO remove before we land this | ||
|
||
use std::ops::Deref; | ||
|
||
struct CustomSmartPointer<T>(T); | ||
|
||
impl<T> Deref for CustomSmartPointer<T> { | ||
type Target = T; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
adetaylor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
struct Pointee; | ||
|
||
impl Pointee { | ||
fn hello(self: &CustomSmartPointer<Self>) { | ||
println!("Hello!"); | ||
adetaylor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
fn main() { | ||
let ptr = CustomSmartPointer(Pointee); | ||
ptr.hello(); | ||
adetaylor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Per comments below, let’s for now rename the listing to be
listing-15-XX
. It will becomelisting-15-14
, but I am going to have to do some work to reorder the rest of them, including checking alllll the existing references in the text.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.
Thanks for all these changes - I've committed them all to the branch, renamed the files, and made a couple of tweaks to get the example to build. I don't believe we can or should merge this until
arbitrary_self_types
is stabilized, which hopefully will fix the remaining CI error. Let me know if I should squash the commits or do anything else meanwhile. Cheers! (and incidentally, I originally learned Rust mostly from The New Rustacean!)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.
Excellent—I’ll review again tomorrow, and then we can just mark it as blocked till it is stabilized, and get it merged!
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.
Oh, and I will probably do some work to get it integrated/integrate-able with the print version so that it ends up in the next print edition!
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.
(You cannot imagine how much it delights me to hear that note about New Rustacean!)