-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arbitrary self types v2: book changes.
Preliminary book changes for Arbitrary Self Types v2. The listing number is currently out of order and this will need fixing, I suspect, but keeping things there unchanged for reviewability meanwhile.
- Loading branch information
Showing
4 changed files
with
59 additions
and
0 deletions.
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] |
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 | ||
} | ||
} | ||
|
||
struct Pointee; | ||
|
||
impl Pointee { | ||
fn hello(self: &CustomSmartPointer<Self>) { | ||
println!("Hello!"); | ||
} | ||
} | ||
|
||
fn main() { | ||
let ptr = CustomSmartPointer(Pointee); | ||
ptr.hello(); | ||
} |
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