You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: text/0000-stabilize-arbitrary-self-types.md
+16-7
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Allow types that implement the new `trait Receiver<Target=Self>` to be the recei
12
12
[motivation]: #motivation
13
13
14
14
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>`.
16
16
17
17
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.
18
18
@@ -37,19 +37,26 @@ trait Receiver {
37
37
}
38
38
```
39
39
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:
41
48
42
49
```rust
43
50
traitFoo {
44
-
fnby_value(self:Self);
45
-
fnby_ref(self:&Self);
46
-
fnby_ref_mut(self:&mutSelf);
51
+
fnby_value(self/* self: Self */);
52
+
fnby_ref(&self/* self: &Self */);
53
+
fnby_ref_mut(&mutself/* self: &mut Self */);
47
54
fnby_box(self:Box<Self>);
48
55
fnby_rc(self:Rc<Self>);
49
56
fnby_custom_ptr(self:CustomPtr<Self>);
50
57
}
51
58
52
-
structCustomPtr<T>(Box<T>);
59
+
structCustomPtr<T>(*constT);
53
60
54
61
impl<T> ReceiverforCustomPtr<T> {
55
62
typeTarget=T;
@@ -70,7 +77,9 @@ impl MyType {
70
77
71
78
## Object safety
72
79
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)?
0 commit comments