diff --git a/src/_impl_bdd_partial_valuation.rs b/src/_impl_bdd_partial_valuation.rs index 34e9e3f..eba3d14 100644 --- a/src/_impl_bdd_partial_valuation.rs +++ b/src/_impl_bdd_partial_valuation.rs @@ -121,13 +121,18 @@ impl Index for BddPartialValuation { type Output = Option; fn index(&self, index: BddVariable) -> &Self::Output { - &self.0[usize::from(index.0)] + let index = usize::from(index.0); + if index < self.0.len() { + &self.0[index] + } else { + &None + } } } impl IndexMut for BddPartialValuation { fn index_mut(&mut self, index: BddVariable) -> &mut Self::Output { - &mut self.0[usize::from(index.0)] + self.mut_cell(index) } }