Struggle with borrow checker at popping from list implementation

⚓ Rust    📅 2025-10-04    👤 surdeus    👁️ 4      

surdeus

My attempt at linked list implementation in Rust hit at stumbling block of pop method implementation.

I have googled for a solution, but so far found only cheesy versions which avoid the problem by popping an element from head(front) of reversed list.

  • list's element does not implements Clone or Copy
  • order of elements in list is important, new one has to be appended at the end
  • removal of an element is from the end

There is a link to playground, with my sloppy take where it fails at borrow checker at attempt to extract return value from mutable borrow:

Can you provide your List::pop method implementation or give some hint at least how to refactor the code?

5 posts - 4 participants

Read full topic

🏷️ Rust_feed