codeitlikemiley / cargo-runner Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
When on a single file rust script , pressing CMD + R
we should check for the first line of the file to contain
#!/usr/bin/env -S cargo +nightly -Zscript
we should use a pattern since we can also declare this as
#!/usr/bin/env cargo +nightly -Zscript
if the pattern match then we should
execute:
./filename.rs
User should be the one to make the their single file rust script executable?
or on the first run if it is not executable then make the file executable
2nd and succeeding run would just invoke ./filename.rs
While cmd-R is convenient, sometimes we need to start our runs with arguments, like:
$ cargo run -- --num_agents=5 --use_submarine_base
Suggestions:
Clarify the documentation to explain how arguments are handled by cargo-runner
.
Add a mechanism, if not present, to allow adding and changing arguments.
Naturally, we wouldn't want to interfere with the convenience of the simple cmd-R command. So maybe shift-cmd-R brings up a dialog box for parameters? Or cargo-runner
would look for a default file like .cargo-runner-args
and append its contents, if present? Either way, it should default to the last used arguments.
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use hover_bench::fibonacci;
/// if we place our cursor on line: 30 `c.bench_function`
/// parse the id which is fib_100 //TODO: Create this fn
/// we use the get_package fn to get package
/// we use find_cargo fn to get the nearest cargo.toml on workspace
/// read file content of cargo.toml
/// parse and check if we have [[bench]] // TODO: adjust CargoType
/// if we have push each new value to a our vec of benches // TODO: add logic to pushing element that match on list of bench
///
/// use case 1: benches/fibonacci.rs or benches/fibonacci/main.rs (default naming convention)
/// `Cargo.toml`
/// ```toml
/// [[bench]]
/// name = "fibonacci"
/// harness = false
/// ```
/// use case 2: custom path - benches/same_name/same_name.rs
/// ```toml
/// [[bench]]
/// name = "same_name"
/// harness = false
/// path = "benches/same_name/same_name.rs"
/// ```
///
/// TODO: generate commands the following commands
/// Commands to run
/// 1. Run specific benchmark on specific crate
/// ```rust
/// cargo bench --package hover_bench --bench fibonacci
/// ```
/// 2. Run specific benchmark on specific crate and specific input
/// ```sh
/// cargo bench --package hover_bench --bench fibonacci -- fib_100
/// ```
fn criterion_benchmark(c: &mut Criterion) { // TODO: Pressing CMD+R here or outside of this scope we should run cmd #1
//TODO:pressing CMD + R below should invoke cmd #2
c.bench_function("fib_100", |b| b.iter(|| fibonacci(black_box(100))));
}
// tuple type macro with at least 2 params, we can add as much benchmark function to run
criterion_group!(benches, criterion_benchmark); // TODO: this would run command #1
// this is the same as calling fn main () {}
criterion_main!(benches); // TODO: this would run command #1
There are cases when a user uses a non rust convention parameters
e.g.
-- /path/to/file1
which resolves to
cargo run -p packageName --bin binName -- --=/path/to/file1
that should resolve to
cargo run -p packageName --bin binName -- path/to/file1
also passing text without --
right now is erroring out Cannot read properties of undefined (reading 'replace')
not all CLI built with rust arent using the cli convention as such there would be error on the overriding of parameters
possible solution is...
pass in the text as is....
on nightly version of rust we can do something like this
see: https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html
#![feature(test)]
extern crate test;
pub fn add_two(a: i32) -> i32 {
a + 2
}
#[cfg(test)]
mod tests {
use super::*;
use test::Bencher;
#[test]
fn it_works() {
assert_eq!(4, add_two(2));
}
#[bench]
fn bench_add_two(b: &mut Bencher) {
b.iter(|| add_two(2));
}
}
note:
we need to parse #![feature(test)] , for this to be a valid nightly rust bench
then matching #[bench] pattern
placing our cursor on any of this line
#[bench]
fn bench_add_two(b: &mut Bencher) {
b.iter(|| add_two(2));
}
should trigger the appropriate bench command
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.