Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a458996
first draft of pointer to fields
RustyYato Jun 5, 2019
7eb7ea4
added to the drawbacks and later sections
RustyYato Jun 5, 2019
7ada603
expanded up reference level explanation
RustyYato Jun 5, 2019
6a9405f
updated formatting and added reference to InitPtr
RustyYato Jun 5, 2019
9b98d97
updated parts about field types, updated drawbacks
RustyYato Jun 5, 2019
b816798
added note about the `Copy` trait.
RustyYato Jun 5, 2019
0eb3d5c
added unsafe to `Field` trait
RustyYato Jun 6, 2019
9d82646
added unresolved question: minimizing proposal
RustyYato Jun 6, 2019
a1b545e
Added `?Sized` bounds
RustyYato Jun 6, 2019
8b5e4e2
added some details abot field types
RustyYato Jun 7, 2019
14fc49f
reworked the RFC's presentation
RustyYato Jun 7, 2019
d3cac45
fixed the pin-projection example in guid-level
RustyYato Jun 7, 2019
d001442
fixed typo
RustyYato Jun 7, 2019
d671633
removed `trait Project` and `trait PinProjectable`
RustyYato Jun 24, 2019
08d9ec2
added inverse projections
RustyYato Jun 24, 2019
00de06a
updated motivation
RustyYato Jun 24, 2019
43d559b
reason for removing `Project` and `PinProjectable`
RustyYato Jun 24, 2019
7c5161a
merge
RustyYato Jun 24, 2019
a83911c
moved from `std` to `core`
RustyYato Jun 24, 2019
6da5da2
Update text/0000-ptr-to-field.md
RustyYato Jun 25, 2019
97e2a7f
Update text/0000-ptr-to-field.md
RustyYato Jun 25, 2019
9d78b37
updated wording based off of @CAD97's suggestions
RustyYato Jun 25, 2019
f362e75
Merge branch 'ptr-to-field' of https://github.com/KrishnaSannasi/rfcs…
RustyYato Jun 25, 2019
dece0b1
editted note about pointer metadata
RustyYato Jun 25, 2019
2e77eef
Update text/0000-ptr-to-field.md
RustyYato Jun 25, 2019
e0e7e80
Apply suggestions from code review
RustyYato Jun 25, 2019
da3afb6
Some more changes from @CAD97's review
RustyYato Jun 25, 2019
21cf26b
added note about enum variants as types
RustyYato Jun 25, 2019
6b31b65
Merge branch 'ptr-to-field' of https://github.com/KrishnaSannasi/rfcs…
RustyYato Jun 25, 2019
00b4d4b
fixed inverse projecting UB examples
RustyYato Jun 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed the pin-projection example in guid-level
fixed typo
moved notes about syntax to unresolved questions
  • Loading branch information
RustyYato committed Jun 7, 2019
commit d3cac452be1206187ca4be63485c8e095ad7a103
40 changes: 25 additions & 15 deletions text/0000-ptr-to-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ trait Project<F: Field> {
}
```

This trait takes a pointer/smart pointer/reference and gives back a projections that represents a field on the pointee.
This trait takes a pointer/smart pointer/reference and gives back a projection that represents a field on the pointee.

i.e.

For raw pointers we could implement this as so
i.e. For raw pointers we could implement this as so

```rust
impl<T: ?Sized, F: Field<Parent = T>> Project<F> for *const T {
Expand Down Expand Up @@ -159,29 +157,38 @@ unsafe impl PinProjectable for Foo.field {}
Here is a toy example of how to use this api:
Given the implementation of `Project for Pin<&mut T>`
```rust
use std::project::Project;
/// Some other crate foo

struct Foo {
bar: u32,
pub bar: u32,
qaz: u32,
hal: u32,
ptr: *const u32,
pin: PhantomPinned
}

// These type annotations are unnecessary, but I put them in for clarity
unsafe impl PinProjectable for Foo.bar {}

/// main.rs

fn main() {
use std::project::Project;
use foo::Foo;

let foo : Pin<Box<Foo> = Box::pin(...);
// These type annotations are unnecessary, but I put them in for clarity

let foo : Pin<&mut Foo> = foo.as_mut();
let foo : Pin<Box<Foo> = Box::pin(...);

let bar : Pin<&mut u32> = foo.project(Foo.bar);
let foo : Pin<&mut Foo> = foo.as_mut();

*bar = 10;
...
let bar : Pin<&mut u32> = foo.project(Foo.bar);

*bar = 10;
}
```

In entirely safe code, we are able to set the value of a field inside a pinned type!
In entirely safe code (in `main.rs`), we are able to set the value of a field inside a pinned type!
We still need some `unsafe` to tell that it is indeed safe to project through the pin, but that falls on the owner of `Foo`.

# Reference-level explanation
[reference-level-explanation]: #reference-level-explanation
Expand Down Expand Up @@ -215,9 +222,9 @@ You can make a field type for the following types of types (some example syntax
* tuple structs `Foo(T, U, ...)`
* `Foo.0`
* structs `struct Foo { field: Field, ... }`
* same syntax as tuple struct
* `Foo.field`
* unions `union Foo { field: Field }`
* same syntax as tuple struct
* same syntax as structs
* constructing a field type is `unsafe`, this is because accessing fields of `union`s is unsafe

The compiler can decide whether to actual generate a field type, this is to help compile times (if you don't use field types, then the compiler shouldn't slow down too much because of this feature).
Expand Down Expand Up @@ -359,6 +366,9 @@ where F: PinProjectable {

- Syntax for the type fields
- not to be decided before accepting this RFC, but must be decided before stabilization
- Some other variations of the syntax are ...
- `Type::field` // This is bad because it conflicts with associated method, and there isn't a way to disambiguate them easily
- `Type~field` // This adds a new sigil to the language
- Do we want a dedicated syntax to go with the Project trait?
- If yes, the actual syntax can be decided after accepting this RFC and before stabilization

Expand Down