Remove Nth Node From End of List in Rust

impl Solution {
    pub fn remove_nth_from_end(head: Option<Box<ListNode>>, n: i32) -> Option<Box<ListNode>> {
        // Create a dummy head to handle edge cases like removing the first node.
        let mut dummy = Some(Box::new(ListNode { val: 0, next: head }));
        let mut slow = &mut dummy;
        let mut fast = &slow.clone();

        // Move fast pointer n steps ahead.
        for _ in 0..=n {
            fast = &fast.as_ref().unwrap().next;
        }

        // Move both pointers until fast reaches the end.
        while fast.is_some() {
            slow = &mut slow.as_mut().unwrap().next;
            fast = &fast.as_ref().unwrap().next;
        }

        // Remove the nth node from the end.
        let next = slow.as_mut().unwrap().next.as_mut().unwrap().next.take();
        slow.as_mut().unwrap().next = next;

        dummy.unwrap().next
    }
}

Next