Skip to content

Commit 9f597fb

Browse files
authored
Merge pull request #2 from ferrous-systems/johann-2
Revise guide-level explaination
2 parents 8f760cb + b5d63de commit 9f597fb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

text/0000-stabilize-arbitrary-self-types.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Allow types that implement the new `trait Receiver<Target=Self>` to be the recei
1212
[motivation]: #motivation
1313

1414
Today, methods can only be received by value, by reference, by mutable reference, or by one of a few blessed smart pointer types from `libstd` (`Arc<Self>`, `Box<Self>`, `Pin<Self>` and `Rc<Self>`).
15-
This has always intended to be generalized to support any kind of pointer, such as an `MyPtr<Self>`. Since late 2017, it has been available on nightly under the `arbitrary_self_types` feature for types that implement `Deref<Target=Self>`.
15+
This has always intended to be generalized to support any kind of pointer, such as an `CustomPtr<Self>`. Since late 2017, it has been available on nightly under the `arbitrary_self_types` feature for types that implement `Deref<Target=Self>`.
1616

1717
Because different kinds of "smart pointers" can constrain the semantics in non trivial ways, traits can rely on certain assumptions about the receiver of their method. Just implementing the trait *for* a smart pointer doesn't allow that kind of reliance.
1818

@@ -37,19 +37,26 @@ trait Receiver {
3737
}
3838
```
3939

40-
Shorthand exists, so that `self` with no ascription is of type `Self`, `&self` is of type `&Self` and `&mut self` is of type `&mut Self`. All of the following self types are valid:
40+
The `Receiver` trait is already implemented for a few types from the standard, i.e.
41+
- smart pointer: `Arc<Self>`, `Box<Self>`, `Pin<Self>` and `Rc<Self>`
42+
- references: `&Self`, `&mut Self` and `Self`
43+
- raw pointer: `*const Self` and `*mut Self`
44+
45+
Shorthand exists for references, so that `self` with no ascription is of type `Self`, `&self` is of type `&Self` and `&mut self` is of type `&mut Self`.
46+
47+
All of the following self types are valid:
4148

4249
```rust
4350
trait Foo {
44-
fn by_value(self: Self);
45-
fn by_ref(self: &Self);
46-
fn by_ref_mut(self: &mut Self);
51+
fn by_value(self /* self: Self */);
52+
fn by_ref(&self /* self: &Self */);
53+
fn by_ref_mut(&mut self /* self: &mut Self */);
4754
fn by_box(self: Box<Self>);
4855
fn by_rc(self: Rc<Self>);
4956
fn by_custom_ptr(self: CustomPtr<Self>);
5057
}
5158

52-
struct CustomPtr<T>(Box<T>);
59+
struct CustomPtr<T>(*const T);
5360

5461
impl<T> Receiver for CustomPtr<T> {
5562
type Target = T;
@@ -70,7 +77,9 @@ impl MyType {
7077

7178
## Object safety
7279

73-
The `Receiver` trait is object safe.
80+
TODO:
81+
- DispatchFromDyn
82+
- What is the relation with Lukas' [RFC "Unsize and CoerceUnsize v2"](https://github.com/ferrous-systems/unsize-experiments)?
7483

7584
# Reference-level explanation
7685
[reference-level-explanation]: #reference-level-explanation

0 commit comments

Comments
 (0)