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

Recursive objects break #168

Closed
Elizafox opened this issue Jun 29, 2023 · 5 comments
Closed

Recursive objects break #168

Elizafox opened this issue Jun 29, 2023 · 5 comments

Comments

@Elizafox
Copy link

Hello,

At present, something like this is impossible, due to a recursive type overflow:

use gc::{Gc, GcCell, Finalize, Trace};

#[derive(Finalize, Trace)]
struct Node<T: Trace + ?Sized + 'static> {
    prev: Option<Gc<GcCell<Node<T>>>>,
    next: Option<Gc<GcCell<Node<T>>>>,
    data: T,
}

A workaround that sacrifices type safety I've found (I would never use this in production):

use std::any::Any;
use gc::{Gc, GcCell, Trace, Finalize};

#[derive(Finalize, Trace)]
struct Node {
    prev: Option<Gc<GcCell<Node>>>,
    next: Option<Gc<GcCell<Node>>>,

    #[unsafe_ignore_trace]
    data: Box<dyn Any>,
}

Maybe I'm doing something wrong though. 🤷‍♀️

@Elizafox
Copy link
Author

I think this might actually be a duplicate of #161, you can close it if it is.

@andersk
Copy link
Collaborator

andersk commented Jun 29, 2023

This was already fixed in Git by 7a26eca (#162), but there hasn’t been a release yet.

@Elizafox
Copy link
Author

Alright, I'll consider this fixed then. Any chance this can work on stable?

@andersk
Copy link
Collaborator

andersk commented Jun 30, 2023

Although this was an auxiliary commit on a PR that added a feature requiring Rust nightly, it also happens to make your example work on Rust stable (if that’s what you mean).

@Elizafox
Copy link
Author

Thank you so much! Yeah, this is perfect.

I'll close for now.

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

2 participants