2 releases
Uses old Rust 2015
0.1.1 | Apr 23, 2018 |
---|---|
0.1.0 | Apr 22, 2018 |
#41 in #expand
11KB
197 lines
rust-bundler
Creates a single-source-file version of a Cargo package.
Features
- Replaces
extern crate my_lib;
inmain.rs
with the contents oflib.rs
. - Expands
mod my_mod;
declarations intomod my_mod { ... }
blocks.
Example
Input:
// src/lib.rs:
mod internal;
pub use internal::hello_world;
// src/internal.rs:
pub fn hello_world() {
println!("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 bundler
Run:
$ bundle path/to/project >output.rs
Library Usage
[dependencies]
bundler = "0.1.1"
extern crate bundler;
fn main() {
let code = bundler::bundle("path/to/project");
println!("{}", code);
}
Similar Projects
- lpenz/rust-sourcebundler is based on regular expressions, whereas this project manipulates the syntax tree
- golang.org/x/tools/cmd/bundle for Go
Dependencies
~11MB
~219K SLoC