Beyond the &

20 points by gignico 13 hours ago on lobsters | 3 comments

In this proposal it looks like you put “feature flags” in the trait impl to tell the compiler the semantics?

        // Tell the borrow checker that multiple references can be made to the
        // same place at the same time:
        const ACCESS: AccessKind = AccessKind::Shared;

That seems…odd. Aren’t marker traits the normal way to communicate semantics? Are there other things like this in Rust that I haven’t noticed or is this a new technique?

[OP] gignico | 2 hours ago

I think this is new, yes. I think the point is that you have to choose among a number of possible values. Marker traits are Boolean. And there is nothing in the type system which can tell “implement exactly one of these traits”. On the other hand the associated constant of enum type is telling exactly that.

Sure, that part makes sense. I guess since this doesn't have any actual participation in the type system (unlike marker traits) I would have expected it to be a builtin attribute instead.

    // Tell the borrow checker that multiple references can be made to the
    // same place at the same time:
    #[access_kind(Shared)]
    unsafe impl<'a, T> BorrowPlace<&'a T> for RefHandle<'a, T> {