Skip to content

More idiomatic way for this? Using raw pointer in a Resource to read data from a reference coming from another library. #2805

Answered by DJMcNab
GGalizzi asked this question in Q&A
Discussion options

You must be logged in to vote

We've had someone asking for this before (although it was called Context in that case).
Basically, your solution is safe, but we definitely could add a wrapper for it - interestingly we could make this non-bevy_ecs exclusive using some privacy cleverness - i.e. it could be a third party crate.

By the way, an alternative is to use a commands like system. Something like:

struct RltkCommands(Vec<Box<dyn FnMut(&mut Rltk + Send + Sync + 'static)>>);
//.. in snippet_of_a_render_sys - assuming you have made the trivial commands
my_res_rltk_commands.push(move |ctx| ctx.set(position.x, position.y, render.fg, render.bg, render.glyph));
// in GameState:
    let mut commands = self.ecs.get_resource_mut

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@GGalizzi
Comment options

Answer selected by GGalizzi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants