This project provides some aids for writing leetcode in rust language.
method 1:
- [Folk and] clone this repo.
- in your leetcode cargo.toml, add:
[dependencies] cauly-rust-leetcode-utils={path="path/to/cauly-rust-leetcode-utils"}
- use data structures from cauly-rust-leetcode-utils ("use cauly_rust_leetcode_utils::..")
- run
cargo run --manifest-path=path/to/cauly-rust-leetcode-utils/Cargo.toml | clip.exe
to format and copy code that goes into leetcode editor.
method 2 (for those who dont want to download cauly-rust-leetcode-utils):
- run
cargo install cauly-rust-leetcode-utils
, this gives you a program calledrlfmt
- in your leetcode cargo.toml, add:
[dependencies] cauly-rust-leetcode-utils="LATEST_VERSION"
- use data structures from cauly-rust-leetcode-utils ("use cauly_rust_leetcode_utils::..")
- run
rlfmt | clip.exe
to format and copy code that goes into leetcode editor.
- rlfmt takes 1 parameter for input .rs file. If no parameter is provided, it looks for
lib.rs
,src/lib.rs
, then fail. - rlfmt will delete
pub struct Solution;
orstruct Solution;
which is not necessary for leetcode. - rlfmt will look for
use cauly_rust_leetcode_utils::XXX
and replace with actual source code. - finally rlfmt prints the result to output, so that you can redirect it to clipboard with
clip.exe
in windows, orxsel -i
in linux.