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

Used enum instead of dyn trait #14

Merged
merged 1 commit into from
May 27, 2024
Merged

Used enum instead of dyn trait #14

merged 1 commit into from
May 27, 2024

Conversation

TobiasJacob
Copy link
Collaborator

@TobiasJacob TobiasJacob commented May 27, 2024

At first I tried using Rc<RefCell<Primitive>>, which made it impossible to downcast without losing the reference.

Then I realised, that ParametricCell defined like in the following is all we need. Basically, the trick is to put the Rc<RefCell<...>> INSIDE the enum, not the enum INSIDE the Rc<RefCell<...>>

pub enum ParametricCell {
    Point2(Rc<RefCell<point2::Point2>>),
    Line(Rc<RefCell<line::Line>>),
    Arc(Rc<RefCell<arc::Arc>>),
    Circle(Rc<RefCell<circle::Circle>>),
}

Now everything works just nicely, and we dont need any weird serilization logic anymore. Type information can be added or removed from an Parametric-like object without altering its memory location or needing to clone it.

@dzervas
Copy link
Collaborator

dzervas commented May 27, 2024

looks good! 🎉

@TobiasJacob TobiasJacob merged commit c27675f into main May 27, 2024
3 of 4 checks passed
@TobiasJacob TobiasJacob deleted the refactor-enums branch May 27, 2024 20:51
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

Successfully merging this pull request may close these issues.

2 participants