#leetcode #utility #api-bindings #proc-macro

macro lcrt-macro

A simple utility crate to help writing leetcode solutions in rust

1 unstable release

0.1.0 Feb 8, 2023

#46 in #leetcode

Apache-2.0

12KB
240 lines

LCRT (Leetcode Runtime)

Crates.io License: Apache 2.0

LCRT is a really simple utility crate to help writing leetcode solutions in rust. It leverages proc macros in rust to reduce the boilerplate code that we need to write.

How to use

To use this library, please add the following into the dependencies in the Cargo.toml file:

[dependencies]
lcrt-macro = "0.1"
lcrt = "0.1"

Then in your local library, in lib.rs file, please add the macro use as below.

#[macro_use]
extern crate lcrt_macro;

Then we can start writing code like this:

#[solution]
impl Solution {
    pub fn add_two_numbers(
        _l1: Option<Box<ListNode>>,
        _l2: Option<Box<ListNode>>,
    ) -> Option<Box<ListNode>> {
        None
    }
}

Underlying, it will alternate the code as below:

mod p2_add_two_numbers {
    use lcrt::*;
    pub struct Solution {}
    impl Solution {
        pub fn add_two_numbers(
            l1: Option<Box<ListNode>>,
            l2: Option<Box<ListNode>>,
        ) -> Option<Box<ListNode>> {
        }
    }
}

License

Apache-2.0: https://www.apache.org/licenses/LICENSE-2.0

Dependencies

~0.6–1MB
~24K SLoC