32 lines
766 B
Rust
32 lines
766 B
Rust
#[derive(PartialEq, Eq, Clone, Debug)]
|
|
pub struct ListNode {
|
|
pub val: i32,
|
|
pub next: Option<Box<ListNode>>
|
|
}
|
|
|
|
impl ListNode {
|
|
#[inline]
|
|
pub fn new(val: i32) -> Self {
|
|
Self { next: None, val }
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! list {
|
|
() => { None };
|
|
( $first:expr ) => { Some(Box::new(ListNode::new($first))) };
|
|
( $first:expr, $($x:expr),+ ) => {
|
|
{
|
|
let mut head = Box::new(ListNode::new($first));
|
|
let mut tail = &mut head;
|
|
#[allow(unused_assignments)]
|
|
{
|
|
$(
|
|
tail.next = Some(Box::new(ListNode::new($x)));
|
|
tail = tail.next.as_mut().unwrap();
|
|
)*
|
|
}
|
|
Some(head)
|
|
}
|
|
};
|
|
}
|