Skip to content

Recursive objects break #168

@Elizafox

Description

@Elizafox

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. 🤷‍♀️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions