leetcode_rust/linked_list.rs
1#![allow(dead_code)]
2
3#[derive(PartialEq, Eq, Debug)]
4pub struct ListNode {
5 pub val: i32,
6 pub next: Option<Box<ListNode>>,
7}
8
9impl ListNode {
10 #[inline]
11 pub fn new(val: i32) -> Self {
12 ListNode { next: None, val }
13 }
14}
15
16//#[macro_export]
17//macro_rules! linkedlist {
18// () => { None };
19// ($($e: expr), *) => {
20// {
21// let mut head = Box::new($crate::ListNode::new(0));
22// let mut ref_head = &mut head;
23//
24// $(
25// ref_head.next = Some(Box::new($crate::ListNode::new($e)));
26// ref_head = ref_head.next.as_mut().unwrap();
27// )*
28//
29// // avoid reassign
30// let _ = ref_head;
31// head.next
32// }
33// };
34//}
35
36//#[cfg(test)]
37//mod tests {
38// #[test]
39// fn test1() {
40// let mut list = linkedlist![1, 2, 3];
41// }
42//}