#tweak #inline #value #file-change

inline_tweak

Tweak values directly from the source code

22 stable releases

1.2.2 Apr 9, 2025
1.2.1 Feb 27, 2025
1.1.2 Jan 25, 2025
1.1.1 Feb 4, 2024
1.0.8 Sep 18, 2020

#16 in Configuration

Download history 547/week @ 2025-02-24 246/week @ 2025-03-03 298/week @ 2025-03-10 198/week @ 2025-03-17 249/week @ 2025-03-24 181/week @ 2025-03-31 297/week @ 2025-04-07 162/week @ 2025-04-14 255/week @ 2025-04-21 286/week @ 2025-04-28 380/week @ 2025-05-05 705/week @ 2025-05-12 392/week @ 2025-05-19 245/week @ 2025-05-26 179/week @ 2025-06-02 223/week @ 2025-06-09

1,137 downloads per month
Used in 8 crates (5 directly)

CC0 license

42KB
730 lines

inline_tweak

Crates.io

Tweak any literal directly from your code, changes to the source appear while running the program.
It works by parsing the file when a change occurs.

The library is minimal with 0 dependencies.
In release mode, the tweaking code is disabled and compiled away.

The derive feature exposes a proc macro to turn all literals from a function body into tweakable values.

inline_tweak is based on this blogpost by tuxedo labs.

Usage

use inline_tweak::*;

fn main() {
    loop {
        println!("{}", tweak!(3.14)); // Try changing the value while the application is running
    }
}

Extra features

derive

The derive feature allows to tweak any number/bool/char literal in a function. It avoids cluttering the code with inline_tweak::tweak! calls.

#[inline_tweak::tweak_fn]
fn main() {
    loop {
       let v = 1.0; // Try changing this value!
       println!("{}", v);
       std::thread::sleep(Duration::from_millis(200)); // or even this value :)
    }
}

Note that it requires syn/quote/proc_macro2 dependencies which makes the crate slower to compile.
Contrary to tweak!, it does not allow tweaking literals in macro calls (like println!), as it cannot reliably replace literals by a function call since macros can have custom syntax.

watch!

inline_tweak provides a watch!() macro that sleeps until the file is modified, akin to a breakpoint:

use inline_tweak::*;

fn main() {
    loop {
        println!("{}", tweak!("hello world"));
        watch!(); // The thread will sleep here until anything in the file changes
    }
}

Expressions

inline_tweak allows to tweak expressions by providing a value later. For example:

tweak!(rng.gen_range(0.0, 1.0))

can then be replaced by a constant value by modifying the file (even while the application is running) to

tweak!(5.0; rng.gen_range(0.0, 1.0)) // will always return 5.0

See the "expression" example in action

Note that this works only for expressions that return a tweakable type. (number/boolean literals)

release_tweak!

The release_tweak! macro acts exactly like tweak! except that it also works in release mode.
It is accessible behind the feature flag "release_tweak" which is not enabled by default.

Installation

Simply add this line to your Cargo.toml

inline_tweak = "1.0.10"

Dependencies

~155KB