What is a crate attribute and where do I add it?

A crate attribute is an attribute (#[…]) that applies to the enclosing context (#![…]). This attribute must be added to the top of your crate root, thus the context is the crate itself: #![attribute_name] #![attribute_name(arg1, …)] If you are creating a library — the crate root will be a file called lib.rs an application — … Read more

Why are Rust executables so huge?

Rust uses static linking to compile its programs, meaning that all libraries required by even the simplest Hello world! program will be compiled into your executable. This also includes the Rust runtime. To force Rust to dynamically link programs, use the command-line arguments -C prefer-dynamic; this will result in a much smaller file size but … Read more

What is an idiomatic way to have shared utility functions for integration tests and benchmarks?

Create a shared crate (preferred) As stated in the comments, create a new crate. You don’t have to publish the crate to crates.io. Just keep it as a local unpublished crate inside your project and mark it as a development-only dependency. This is best used with version 2 of the Cargo resolver. . ├── Cargo.toml … Read more

Package with both a library and a binary?

Tok:tmp doug$ du -a 8 ./Cargo.toml 8 ./src/bin.rs 8 ./src/lib.rs 16 ./src Cargo.toml: [package] name = “mything” version = “0.0.1” authors = [“me <[email protected]>”] [lib] name = “mylib” path = “src/lib.rs” [[bin]] name = “mybin” path = “src/bin.rs” src/lib.rs: pub fn test() { println!(“Test”); } src/bin.rs: extern crate mylib; // not needed since Rust edition … Read more