Commit 95679004 authored by Romain Vimont's avatar Romain Vimont Committed by Luca Barbato

Implement operator[] for PlaneSlice

Implement trait Index to access PlaneSlice rows as if it was a
two-dimensional array.

That way, we can write:

    let row = &plane_slice[5];
    let value = plane_slice[5][3];
parent 8c00a25b
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
use std::iter::FusedIterator; use std::iter::FusedIterator;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::mem; use std::mem;
use std::ops::Range; use std::ops::{Index, Range};
use crate::util::*; use crate::util::*;
...@@ -413,6 +413,13 @@ impl<'a, T: Pixel> PlaneSlice<'a, T> { ...@@ -413,6 +413,13 @@ impl<'a, T: Pixel> PlaneSlice<'a, T> {
} }
} }
impl<'a, T: Pixel> Index<usize> for PlaneSlice<'a, T> {
type Output = [T];
fn index(&self, index: usize) -> &Self::Output {
self.row(index)
}
}
pub struct PlaneMutSlice<'a, T: Pixel> { pub struct PlaneMutSlice<'a, T: Pixel> {
pub plane: &'a mut Plane<T>, pub plane: &'a mut Plane<T>,
pub x: isize, pub x: isize,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment