Giter VIP home page Giter VIP logo

inline_tweak's Introduction

inline_tweak

Crates.io

inline_tweak is based on this blogpost by tuxedo labs.

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, only requiring the lazy_static dependency to hold modified values.
In release mode, the tweaking code is disabled and compiled away.

Usage

use inline_tweak::*;

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

Extra features

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.9"

inline_tweak's People

Contributors

uriopass avatar rasmusgo avatar ratysz avatar benfrankel avatar trevorcow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.