20 releases
0.3.16 | Sep 26, 2023 |
---|---|
0.3.15 | Aug 2, 2022 |
0.3.14 | Jul 22, 2022 |
0.3.8 | Jun 26, 2022 |
0.2.8 | Aug 13, 2021 |
#1397 in Command line utilities
30KB
516 lines
rust-bundler-cp
This project is based on rust-bundler
Creates a single-source-file version of a Cargo package. It's designed for Competitive Programming like Codeforces.
I'm using rust-bundler-cp with my codeforces template https://github.com/Endle/rust_codeforce_template,
Features
- Uses Syn to parse and manipulate a complete syntax tree, instead of doing replacement with regular expression.
- Replaces
extern crate my_lib;
inmain.rs
with the contents oflib.rs
. - Expands
mod my_mod;
declarations intomod my_mod { ... }
blocks. - rustfmt needs to be available in
PATH
, i.e.dnf install rustfmt
. I'll consider bundlerustfmt
in my code later.
Example
Input:
// src/internal.rs:
pub fn hello_world() {
println!("Hello, world!");
}
// src/lib.rs:
mod internal;
pub use internal::hello_world;
// src/main.rs:
extern crate example;
fn main() {
example::hello_world();
}
Output:
mod internal {
pub fn hello_world() {
println!("Hello, world!");
}
}
pub use internal::hello_world;
fn main() {
hello_world();
}
More examples in tests/testdata.
Usage
Install:
$ cargo install rust_bundler_cp
Run:
$ rust_bundler_cp --input path/to/project >output.rs
$ rust_bundler_cp --input path/to/project --binary a
Similar Projects
- This project is based on slava-sh /rust-bundler
- lpenz/rust-sourcebundler is based on regular expressions, whereas this project manipulates the syntax tree
- MarcosCosmos/cg-rust-bundler
- golang.org/x/tools/cmd/bundle for Go
Dependencies
~6–19MB
~277K SLoC