Skip to content

Any reason Ref can't just be one reference? #3

Description

@jgarvin
pub struct Ref<'a, T: 'a> {
    borrow_count: &'a Cell<isize>,
    value: &'a T,
}

AFAICT these two references always point to adjacent data:

struct RefManagerInnerData<T> {
    borrow_count: Cell<isize>,
    value: T,
}

Is there any reason to not prefer:

pub struct Ref<'a, T: 'a> {
    inner: &'a RefManagerInnerData<T>,
}

One issue I see is the mutable case:

#[derive(Debug)]
pub struct RefMut<'a, T: 'a> {
    borrow_count: &'a Cell<isize>,
    value: &'a mut T,
}

Because here one of the references is immutable and the other is mutable. However AFAICT we could just use a pointer instead, and present the same safe interface.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions