Skip to content
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

DynLinkedList #91

Open
conradludgate opened this issue May 2, 2024 · 0 comments
Open

DynLinkedList #91

conradludgate opened this issue May 2, 2024 · 0 comments

Comments

@conradludgate
Copy link

I wanted to have a linked list of Arc<dyn DynTask> for a toy async runtime I am working on. It took a bit of effort but I did eventually manage to define an adaptor that works. I thought I would share it here for lack of any other suitable discussion place.

The basis of this impl is the FatLink, which is a linked list link + a type-erased get_value function that the Adapter impl uses.

pub(crate) struct FatLink<D: ?Sized> {
    link: XorLinkedListAtomicLink,
    get_value: unsafe fn(link: NonNull<FatLink<D>>) -> *const D,
}

Unfortunately, I needed to add this get_link method to the DynTask trait, which requires feature(arbitrary_self_types). I could not figure out a way to avoid the nightly dep here.

    unsafe fn get_link(self: *const Self) -> NonNull<FatLink<dyn DynTask>> {
        <Self as FatLinked<dyn DynTask>>::get_link(self)
    }

https://github.com/conradludgate/arc-discharge/blob/dbd9b0aeb0d1389262a203eeff3bc2e9b0c91a37/src/linked_list.rs

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

No branches or pull requests

1 participant