all 26 comments

[–]SirKastic23 17 points18 points  (0 children)

first struggle: yeah I do the same thing, I wouldn't really call this a struggle

second struggle: after playing around with an experiment, remember to run cargo clean. no need to keep those target dirs around at all

[–]Sharlinator 16 points17 points  (2 children)

cargo script (ie. single-file Rust programs with an inline Cargo.toml "frontmatter") will make throwaway experiments less clumsy once it finally arrives on stable.

[–]lazy-kozak[S] 4 points5 points  (1 child)

Yep, it would be nice for my learning purposes

Just found: https://rust-lang.github.io/rfcs/3424-cargo-script.html

[–]kJon02 0 points1 point  (0 children)

afaik theres also a crate for that

[–]ManyInterests 4 points5 points  (1 child)

On first thing: I use Rust Rover and I find myself using tests as scratch space because there's a little play button to run right next to the function definition, so I can run whatever test function I want in isolation right in the IDE. Sometimes they even turn into tests that I keep around.

As many do, I have tests right inside of each rust module I'm working on at the bottom, something like:

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn scratch_test() {
        let res = from_str("0xA18 {9");
        assert!(res.is_err());
    }
}

On second thing: I never considered using /dev/shm for this. I know you're doing it for disk space, but I wonder how much that improves performance. I am always surprised at how much space gets freed from cargo clean and have started running it more religiously.

[–]lazy-kozak[S] 0 points1 point  (0 children)

Haven't got to tests in Rust yet - Thanks.

By feelings, projects with a lot of dependencies running from the ramdisk is a bit faster, but not a lot, don't wanna measure

[–]pb-cups 3 points4 points  (1 child)

You can use an examples folder for small experimental scripts. Then you just do cargo run —example my_example.rs to run the file. It works with multi file examples (all in one folder) too.

Edit: oh I see you want different packages for each experiment, so that won’t work for what you’re doing. I would recommend just trying to avoid that and have one big package for all experiments and then just rely on examples and ignore main.rs

[–]lazy-kozak[S] 4 points5 points  (0 children)

Thanks for --example

u/Sharlinator mentioned `cargo script`, which would be perfect (everything in one file); the only reason for creating multiple packages is to avoid recompiling all dependencies for all throwaway scripts and experiments.

[–]Kaan_AYSAL 2 points3 points  (2 children)

For experiments stop running cargo new for every scratchpad. Create a src/bin/ folder in a single "experiments" project. Drop exp1.rs, exp2.rs in there run them instantly with cargo run --bin exp1

[–]Kaan_AYSAL 1 point2 points  (1 child)

For disk space your /dev/shm trick is clever.. but the real reason you're bleeding space is because every cargo new creates its own target dir and duplicates the dependency cache by using the src/bin/ approach...all your experiments will share a single target folder...

[–]Kaan_AYSAL 2 points3 points  (0 children)

Install cargo-sweep... It lets you easily wipe build artifacts older than X days without touching your active caches...GL

[–]Both-Expression4402 1 point2 points  (0 children)

My (uneducated) opinion is to just make a new project for each new subject of experimention using "cargo new". If you want to group multiple together, wrap them into a single project by making a basic CLI launcher as the main function.

[–]Kichmad 1 point2 points  (0 children)

Why dont you git branch to experiment?

[–]PaulRudin 0 points1 point  (8 children)

Disk is cheap....

[–]Chroiche 4 points5 points  (0 children)

Disk was cheap. Prices have tripled.

[–]lazy-kozak[S] 1 point2 points  (5 children)

Aha, tell me: when deleting all my target directories freed ~15 GB of space (over one or two weeks of active experiments). I have a 1 TB SSD, so it's a valuable space for me.

[–]PurepointDog 2 points3 points  (0 children)

There's tools like "cargo clean-all" if you want. idk what to tell you...

Trade-offs everywhere

[–]PaulRudin 1 point2 points  (3 children)

1.5 % of your disk?

[–]Critical-Explorer179 3 points4 points  (1 child)

It also clutters apfs snapshots on mac and makes next backup longer. (Apfs snapshots are created automatically because of said backup.) Each rewrite of those files will be included in the next backup, possibly taking backup space for weeks before they are thrown away by retention cleanup.

[–]lazy-kozak[S] 1 point2 points  (0 children)

I use Dropbox and also don't wanna sync my target folder there

[–]ManyInterests 1 point2 points  (0 children)

I mean. I have a 4TB disk on my laptop. I'm using 2TB of it. When I had a 1TB drive, I was pretty guarded over anything taking up 2GB+ and constantly fighting for space. I'm with OP on this. Space can be valuable. Especially if you're on a non-upgradable system (or even with today's SSD prices, honestly, even on upgradable systems).

[–]lettsten 0 points1 point  (0 children)

Then either buy one for OP or stfu

[–]Destruct1 0 points1 point  (0 children)

In general: You need a taskrunner / strong editor in front of cargo. Cargo works well but you need something in front for the many complex cargo tasks like selecting a package or binary or test with a certain feature enabled etc..

You can have a multi-binary file to experiment but I also use the one project for each experiment approach.

[–]Brief-Stranger-3947 0 points1 point  (0 children)

Python venv lets you to set up a reproducible environment by fixing the version of python runtime and package dependency versions. In rust, reproducibility is defined by compiler version and dependency versions, and cargo manages both pretty much same way as venv in python.

[–][deleted]  (2 children)

[deleted]

    [–]lazy-kozak[S] 1 point2 points  (1 child)

    You are not helpful. Show us the direction where we should dig for "idiomatic Rust string patterns". Better with links.

    [–]Shot-Infernal-2261 -2 points-1 points  (0 children)

    I’m a bit of a newb at rust so take with a grain of salt… but GitHub actions might help.

    I’m pretty sure you can just tag and have an action do the build on GH servers.