cargo-snippet
A snippet extractor for competitive programmers.
You can manage code snippet with test and bench !!
Installing
You need nightly rust.
$ cargo install cargo-snippet --features="binaries"
Usage
Create a project for snippet.
$ cargo new mysnippet
Add dependencies to Cargo.toml.
[]
= "0.1"
Add this to src/lib.rs.
Write some snippet codes and tests.
// Annotate snippet name
// Also works
// Equivalent to #[snippet = "lcm"]
// Include snippet
You can test.
$ cargo test
Extract snippet !
$ cargo snippet
snippet gcd
fn gcd(a: u64, b: u64) -> u64 {
if b == 0 {
a
} else {
gcd(b, a % b)
}
}
snippet gcd_list
fn gcd(a: u64, b: u64) -> u64 {
if b == 0 {
a
} else {
gcd(b, a % b)
}
}
fn gcd_list(list: &[u64]) -> u64 {
list.iter().fold(list[0], |a, b| gcd(a, b));
}
snippet lcm
fn lcm(a: u64, b: u64) -> u64 {
a / gcd(a, b) * b
}
snippet mymath
fn gcd(a: u64, b: u64) -> u64 {
if b == 0 {
a
} else {
gcd(b, a % b)
}
}
fn lcm(a: u64, b: u64) -> u64 {
a / gcd(a, b) * b
}
Example
My snippets here.
Supported output format
- Neosnippet
- VScode
- Ultisnips
You can specify output format via -t
option.
See cargo snippet -h
.