Skip to content

shared-only fields #5

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

Open
nikomatsakis opened this issue May 25, 2017 · 3 comments
Open

shared-only fields #5

nikomatsakis opened this issue May 25, 2017 · 3 comments

Comments

@nikomatsakis
Copy link
Owner

nikomatsakis commented May 25, 2017

Proposal

The current RFC proposes only "mutable" fields. That is, if you have an &mut T, and T: Trait, you can mutate the fields declared in Trait. However, it'd be nice to be able to have "shared-only" fields, where the fields act shared no matter what. So even with a &mut T, you can only get a shared borrow of those fields.

Among other things, this is needed if we ever wish to support defining traits with fields that can be implemented by &T types. Example:

trait Foo {
    value: u32
}

impl Foo for &u32 {
    value = *self
}

Right now, though, that is blocked by #4 in any case.

Shared-only fields are also interesting because they would have looser overlap requirements (i.e., two shared-only fields could point at the same data).

Interactions:

@glaebhoerl
Copy link

glaebhoerl commented May 25, 2017

(What does it mean when a P-essential is blocked on a P-nice-to-have?)

Anyway, this seems like a nice-to-have to me, but awkardly, syntax-wise the most obvious (and likely overall best) way to signify this would be by the absence of a mut qualifier - that is, "normal" mutable fields would be let mut or whatever. So we probably want to decide one way or another on the syntax aspect at least before stabilizing the core feature.

(Edit: I see you mentioned the same thing in #3.)

@burdges
Copy link

burdges commented May 25, 2017

I think "blocked" means #4 requires adding mut here so that smart pointer Derefs can do their thing.

@nikomatsakis
Copy link
Owner Author

@glaebhoerl

(What does it mean when a P-essential is blocked on a P-nice-to-have?)

Are you referring to #4? This particular issue is not blocked on #4, I don't think, it just "interacts" with it. (In particular, combining the two enables fields that are reachable through an &-ref.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants