1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
use crate::Node; /// Trick to make possible using a value field as key pub struct Inserter<'a, T> { values: &'a mut Vec<T>, to: &'a mut Vec<Node>, } impl<'a, T> Inserter<'a, T> { /// Consumes self and insert a value #[inline] pub fn insert(self, value: T) { self.values.push(value); let index = self.values.len() - 1; self.to.push(Node::new_value_index(index)); } pub(crate) fn new(values: &'a mut Vec<T>, to: &'a mut Vec<Node>) -> Self { Self{values, to} } }