How to use method inside another method?
07:22 20 Dec 2025

I'm trying to learn Rust be rewriting a few of my small projects in C++ to Rust, but borrow checker seems to apply unreasonable rules caused be it's limitations. The code in question is:

pub struct ParticleEngine {
    system: Vec,
    width: u16, height: u16,
    buffer: Vec,
    fps: u8
}

impl ParticleEngine {
    pub fn tick(&mut self) {
      let mut rng = rand::rng();
    
      for archetype in &mut self.system {
        for particle in &mut archetype.particles {
          self.buffer[self.coordinates_to_buffer_index(particle.x, particle.y)] = b' ';
    
          particle.y.wrapping_add_signed(archetype.speed);
    
          particle.x = rng.random::();
          particle.y = rng.random::();

          self.buffer[self.coordinates_to_buffer_index(particle.x, particle.y)] = archetype.character;
        }
      }
    }
    
    fn coordinates_to_buffer_index(&self, x: u16, y: u16) -> usize {
      return (self.width * y + x) as usize;
    }

    //...
}

Not mentioning the rest of the code, the logic is simple: each tick we get the list of archetypes of particles. It contains a list of particles objects that must be updated. When particles are updated, their position is drawn in the buffer: a simple Vec. To consistently parse coordinates to offset, the coordinates_to_buffer_index is introduced.

Borrow checker doesn't like that when we are mutating particles via tick->self, function call tries to take another reference coordinates_to_buffer_index->self, even tho we are only accessing width, that doesn't have any mutable reference.

The question: how to work around it without creating a bunch of overhead for safety that doesn't do anything?

A few solutions that were online that I don't think are a good fit is: make a clone of the array (way too much overhead), create a list of actions and apply them later (way too much overhead), turn the method into a function (boilerplate code, not ideal, but seems like the only acceptable solution), macros of in lined formula (basically the previous, but riskier). Is there anything else I've missed that won't feel like a workaround?

rust