Skip to content
Discussion options

You must be logged in to vote

You have two options

  1. Use Assets::remove to get ownership of the image asset temporarily, then use Assets::set to reinsert it back.
  2. Use a closure or a trait. The end-user API becomes honestly unpleasant, but as a general rule, inversion of control is very useful to work around lifetime limitations in rust.
trait ModifyImage {
    fn modify_1(&mut self, image: &mut Image);
    fn modify_2(&mut self, image: &mut Image);
}
fn modificator(
    assets: &mut Assets<Image>,
    handle1: &Handle<Image>,
    handle2: &Handle<Image>,
    modificator: &mut impl ModifyImage,
) {
    let Some(image1) = assets.get_mut(handle1) else { return; };
    modificator.modify_1(image1);
    let Some(image2) = …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Droggelbecher
Comment options

@nicopap
Comment options

nicopap Apr 12, 2023
Collaborator

@Droggelbecher
Comment options

@nicopap
Comment options

nicopap Apr 12, 2023
Collaborator

Answer selected by Droggelbecher
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