2 unstable releases

0.2.0 Aug 6, 2023
0.1.0 Aug 7, 2021

#390 in Compression


Used in 2 crates

MIT/Apache

18KB
300 lines

rustminify

CI codecov dependency status

A tool for minifying Rust code.

rustminify-cli (Binary)

Crates.io Crates.io

 cargo install rustminify-cli
 rustminify --remove-docs <<EOF
//! crate-level doc

fn main() {
    println!("{}", module::f());
}

mod module {
    //! module-level doc

    /// doc for an item
    pub(crate) fn f() -> i32 {
        1 + 1
    }
}
EOF
fn main(){println!("{}",module::f());}mod module{pub(crate)fn f()->i32{1+1}}

rustminify (Library)

Crates.io Crates.io

 cargo add rustminify
use syn::parse_quote;

assert_eq!(
    r#"fn main(){println!("{}",module::f());}mod module{pub(crate)fn f()->i32{1+1}}"#,
    rustminify::minify_file(&rustminify::remove_docs(parse_quote! {
        //! crate-level doc

        fn main() {
            println!("{}", module::f());
        }

        mod module {
            //! module-level doc

            /// doc for an item
            pub(crate) fn f() -> i32 {
                1 + 1
            }
        }
    })),
);

License

Dual-licensed under MIT or Apache-2.0.


lib.rs:

Minifies Rust code.

use syn::parse_quote;

assert_eq!(
    r#"fn main(){println!("{}",module::f());}mod module{pub(crate)fn f()->i32{1+1}}"#,
    rustminify::minify_file(&rustminify::remove_docs(parse_quote! {
        //! crate-level doc

        fn main() {
            println!("{}", module::f());
        }

        mod module {
            //! module-level doc

            /// doc for an item
            pub(crate) fn f() -> i32 {
                1 + 1
            }
        }
    })),
);

Dependencies

~1.5MB
~37K SLoC