pub fn next(&mut self) {
        let ix = self.pixel.iter().position(|p| *p == MAX_INTENSITY).unwrap();
        let next_ix: usize;
        if ix == 0 {
            // We reached left border -> turn around
            self.direction = Direction::Right;
        }
        else if ix == self.pixel.len() - 1 { 
            // We reached right border -> turn around
            self.direction = Direction::Left;
        }

        // Calculate next index of leading light
        next_ix = ix + match self.direction { Direction::Left => -1, Direction::Right => 1 } as usize;

        // Reduce intensity of remaining lights
        self.pixel.iter_mut().for_each(|p| if *p > 0 { *p -= 1; });

        // Set leading light
        self.pixel[next_ix] = MAX_INTENSITY;
    }
/// Advance LED to next position.
Advance LED to next position.
Advance LED to next position .
pub fn next(&mut self) {
        let ix = self.pixel.iter().position(|p| *p == MAX_INTENSITY).unwrap();
        let next_ix: usize;
        if ix == 0 {
            // We reached left border -> turn around
            self.direction = Direction::Right;
        }
        else if ix == self.pixel.len() - 1 { 
            // We reached right border -> turn around
            self.direction = Direction::Left;
        }
        // Calculate next index of leading light
        next_ix = ix + match self.direction { Direction::Left => -1, Direction::Right => 1 } as usize;
        // Reduce intensity of remaining lights
        self.pixel.iter_mut().for_each(|p| if *p > 0 { *p -= 1; });
        // Set leading light
        self.pixel[next_ix] = MAX_INTENSITY;
    }
pub fn next ( & mut self ) { let ix = self . pixel . iter ( ) . position ( | p | * p == MAX_INTENSITY ) . unwrap ( ) ; let next_ix : usize ; if ix == 0 { // We reached left border -> turn around self . direction = Direction :: Right ; } else if ix == self . pixel . len ( ) - 1 { // We reached right border -> turn around self . direction = Direction :: Left ; } // Calculate next index of leading light next_ix = ix + match self . direction { Direction :: Left => - 1 , Direction :: Right => 1 } as usize ; // Reduce intensity of remaining lights self . pixel . iter_mut ( ) . for_each ( | p | if * p > 0 { * p -= 1 ; } ) ; // Set leading light self . pixel [ next_ix ] = MAX_INTENSITY ; }
Advance LED to next position.
Advance LED to next position .
&mut self
&mut self