use std::ops::{Index, IndexMut}; pub struct Edge { pub vertex1_index: usize, pub vertex2_index: usize, pub length: f64, pub ferment_intensity: f64, } enum EdgeCell { Free { next_free_cell_id: Option }, Value { data: Edge }, } pub struct EdgesVec { storage: Vec, } impl EdgesVec { pub fn new() -> Self { return Self { storage: Vec::new(), }; } } impl Index for EdgesVec { type Output = Edge; fn index(&self, index: usize) -> &Self::Output { match self.storage.get(index).expect("Edge index out of bounds") { EdgeCell::Free { .. } => panic!("Referenced edge doesn't exists"), EdgeCell::Value { data } => return data, } } } impl IndexMut for EdgesVec { fn index_mut(&mut self, index: usize) -> &mut Self::Output { match self .storage .get_mut(index) .expect("Edge index out of bounds") { EdgeCell::Free { .. } => panic!("Referenced edge doesn't exists"), EdgeCell::Value { data } => return data, } } }