Skip to content

Implementing AllocRef for actual references #34

Open
@oliver-giersch

Description

@oliver-giersch

From what I can gather from the currently proposed API design, the way the associated types are set up between the traits BuildAllocRef, DeallocRef and AllocRef it would be impossible to implement the latter two for an actual reference as in e.g. impl<'a> AllocRef for &'a CustomAllocator.
If I am not mistaken, this means that &'a CustomAllocator must also implement DeallocRef and needs an associated builder type. However, without GAT it is not possible to implement BuildAllocRef for CustomAllocator and define &'a CustomAllocator as the associated Ref type.

Is my understanding of the intended usage for these traits correct or am I wrong somehow? Furthermore, even if GAT were available and BuildAllocRef were defined as:

pub trait BuildAllocRef {
    type Ref<'a>: DeallocRef + 'a;

    unsafe fn build_alloc_ref<'a>(
        &'a mut self,
        ptr: NonNull<u8>,
        layout: Option<NonZeroLayout>
    ) -> Self::Ref<'a>;
}

This would result in DeallocRef/AllocRef being impossible to implement for any owning handles (like Arc) or ZST handles, since built Ref would be required to be bound to the lifetime of the builder, at least if I understand the proposed GAT RFC correctly.

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