Skip to content

Library to bundle local Rust library source files into a single file

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

adam-bates/rust_source_bundler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Source Bundler

Crates.io Crates.io MIT/Apache 2.0

Easily bundle local Rust library files into a single file.

This can be useful when importing or generating Rust code as you can include! or include_str! on a single generated file containing all modules.

Example

You can run the program on this library's source files

cargo run --example rust_source_bundler

Usage

Given the following files:

project/src/
|- helpers/
|  |- inner.rs
|  |- mod.rs
|- lib.rs
|- utils.rs

// project/src/lib.rs

pub mod utils;

mod helpers;

use helpers::helper_fn;

pub fn lib_fn() {}
// project/src/utils.rs

pub fn utils_fn() {}
// project/src/helpers/mod.rs

mod inner;

pub use inner::*;

pub fn helper_fn() {}
// project/src/helpers/inner.rs

pub fn inner_fn() {}

You can use this library:

// project/build.rs to generate code on build

fn main() {
    let code = rust_source_bundler::bundle_source("./project/src", "lib.rs").unwrap();
    
    println!("{code}");

    /* Prints:

pub mod utils {
    pub fn utils_fn() {}
}
mod helpers {
    mod inner {
        pub fn inner_fn() {}
    }

    pub use inner::*;

    pub fn helper_fn() {}
}

use helpers::helper_fn;

pub fn lib_fn() {}

    */
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Library to bundle local Rust library source files into a single file

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages