The memory element has a capacity() and a len() method (I think memory.len() might be the appropriate equivalent to self.capacity), why is it necessary to have another struct element capacity in the struct Buffer? This seems like duplicate book-keeping to me, why is that necessary?
see also: example of reduction