1
macro_rules! next_node_as_ref {3
$a.as_ref().unwrap().next6
macro_rules! next_node_as_mut {8
$a.as_mut().unwrap().next12
pub fn swap_pairs(mut head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {16
let mut cur_node = &mut head;18
// while we have something to work with (.next has something)19
while cur_node.is_some() && next_node_as_ref!(cur_node).is_some() {20
// .take() Takes the value out of the option, leaving a None in its place.21
let mut even_node = next_node_as_mut!(cur_node).take();23
// taking next odd node's value24
let next_odd_node = next_node_as_mut!(even_node).take();25
// cur_node's .next points to next odd node26
next_node_as_mut!(cur_node) = next_odd_node;27
// even node's .next points to cur_node28
next_node_as_mut!(even_node) = cur_node.take();29
// switching cur_node with even node30
cur_node.replace(even_node.unwrap());31
// point cursor to .next.next32
cur_node = &mut next_node_as_mut!(next_node_as_mut!(cur_node));