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

Chapter 45: Lifetimes and Assigning Renderable components #160

Open
Zij-IT opened this issue Feb 21, 2021 · 0 comments
Open

Chapter 45: Lifetimes and Assigning Renderable components #160

Zij-IT opened this issue Feb 21, 2021 · 0 comments

Comments

@Zij-IT
Copy link

Zij-IT commented Feb 21, 2021

While going along with the tutorial, it was mentioned that you couldn't resolve the lifetime issues at the time. I am just dropping this off as a solution with lifetimes. My Renderer component differs slightly from the tutorial one, so I have adapted my code to it for this.

I believe the reason that the lifetimes are necessary, is because EntityBuilder::with() returns Self. This means that the passed EntityBuilder must live at least as long as assign_render is running, and since we build upon the passed builder, the one that we return must also live as long as the passed EntityBuilder, hence the connection between the three.

fn assign_render<'a>(new_entity: EntityBuilder<'a>, render: &RawRender) -> EntityBuilder<'a> {
    new_entity.with(Renderable {
            glyph: render.glyph,
            fg: render.fg,
            bg: render.bg,
            colors,
    })
}
@Zij-IT Zij-IT changed the title Chapter 45: Lifetime Chapter 45: Lifetimes and Assigning Renderable components Feb 21, 2021
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