feat: add rust-script

This commit is contained in:
2022-08-06 01:14:04 +08:00
parent 70f202e982
commit a65b8f0aae
67 changed files with 5086 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
use std::env;
pub fn main() {
// Test that CARGO_TARGET_DIR is not set by rust-script to avoid
// interfering with cargo calls done by the script.
// See https://github.com/fornwall/rust-script/issues/27
let env_variable = env::var("CARGO_TARGET_DIR");
println!("--output--");
println!(
"{:?}",
matches!(env_variable, Err(env::VarError::NotPresent))
);
}

View File

@@ -0,0 +1 @@
hello, including script

View File

@@ -0,0 +1,10 @@
/// ```cargo
/// [dependencies]
/// boolinator = "=0.1.0"
/// ```
use boolinator::Boolinator;
pub fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}

View File

@@ -0,0 +1,10 @@
//! ```cargo
//! [dependencies]
//! boolinator = "=0.1.0"
//! ```
use boolinator::Boolinator;
pub fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}

View File

@@ -0,0 +1,3 @@
use std::fs::File;
File::open("__rust-script-this-file-does-not-exist.txt")?;

View File

@@ -0,0 +1,4 @@
println!("--output--");
if let Some(arg) = std::env::args().skip(1).next() {
println!("Argument: {}", arg);
}

View File

@@ -0,0 +1,6 @@
fn main() {
println!("--output--");
for (i, arg) in std::env::args().enumerate() {
println!("{:>4}: {:?}", format!("[{}]", i), arg);
}
}

View File

@@ -0,0 +1,14 @@
//! This is merged into a default manifest in order to form the full package manifest:
//!
//! ```cargo
//! [dependencies]
//! boolinator = "=0.1.0"
//! tokio = { version = "1", features = ["full"] }
//! ```
use boolinator::Boolinator;
#[tokio::main]
async fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}

View File

@@ -0,0 +1,12 @@
use std::env;
fn main() {
println!("--output--");
let path = env::var("RUST_SCRIPT_PATH").expect("CSSP wasn't set");
assert!(path.ends_with("script-cs-env.rs"));
assert_eq!(env::var("RUST_SCRIPT_SAFE_NAME"), Ok("script-cs-env".into()));
assert_eq!(env::var("RUST_SCRIPT_PKG_NAME"), Ok("script-cs-env".into()));
let base_path = env::var("RUST_SCRIPT_BASE_PATH").expect("CSBP wasn't set");
assert!(base_path.ends_with("data"));
println!("Ok");
}

View File

@@ -0,0 +1,6 @@
extern crate boolinator;
use boolinator::Boolinator;
fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}

View File

@@ -0,0 +1,16 @@
/*!
```cargo
[features]
dont-panic = []
```
*/
#[cfg(feature="dont-panic")]
fn main() {
println!("--output--");
println!("Keep calm and borrow check.");
}
#[cfg(not(feature="dont-panic"))]
fn main() {
panic!("Do I really exist from an external, non-subjective point of view?");
}

View File

@@ -0,0 +1,11 @@
//! This is merged into a default manifest in order to form the full package manifest:
//!
//! ```cargo
//! [dependencies]
//! boolinator = "=0.1.0"
//! ```
use boolinator::Boolinator;
fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}

View File

@@ -0,0 +1,11 @@
#!/usr/bin/env rust-script
/// This is merged into a default manifest in order to form the full package manifest:
///
/// ```cargo
/// [dependencies]
/// boolinator = "=0.1.0"
/// ```
use boolinator::Boolinator;
println!("--output--");
println!("{:?}", true.as_some(1));

View File

@@ -0,0 +1,13 @@
/*!
This is merged into a default manifest in order to form the full package manifest:
```cargo
[dependencies]
boolinator = "=0.1.0"
```
*/
use boolinator::Boolinator;
fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}

View File

@@ -0,0 +1,4 @@
fn main() {
println!("--output--");
println!("Ok");
}

View File

@@ -0,0 +1,12 @@
use std::env;
mod script_module {
include!(concat!(env!("RUST_SCRIPT_BASE_PATH"), "/script-module.rs"));
}
fn main() {
println!("--output--");
let s = include_str!(concat!(env!("RUST_SCRIPT_BASE_PATH"), "/file-to-be-included.txt"));
assert_eq!(script_module::A_VALUE, 1);
println!("{}", s);
}

View File

@@ -0,0 +1,12 @@
fn main() {
println!("--output--");
println!("Hello, World!");
}
/**
```cargo
[dependencies]
i-cant-decide-whether-you-should = ["live", "die"]
```
*/
fn dummy() {}

View File

@@ -0,0 +1 @@
pub const A_VALUE: i32 = 1;

View File

@@ -0,0 +1,4 @@
fn main() {
println!("--output--");
println!("Hello, World!");
}

View File

@@ -0,0 +1,9 @@
// cargo-deps: boolinator="=0.1.0"
// You can also leave off the version number, in which case, it's assumed
// to be "*". Also, the `cargo-deps` comment *must* be a single-line
// comment, and it *must* be the first thing in the file, after the
// shebang.
use boolinator::Boolinator;
println!("--output--");
println!("{:?}", true.as_some(1));

View File

@@ -0,0 +1,10 @@
// cargo-deps: boolinator="=0.1.0"
// You can also leave off the version number, in which case, it's assumed
// to be "*". Also, the `cargo-deps` comment *must* be a single-line
// comment, and it *must* be the first thing in the file, after the
// shebang.
use boolinator::Boolinator;
fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}

View File

@@ -0,0 +1,10 @@
/*!
```cargo
[dependencies]
slow-build = { version = "0.1.0", path = "slow-build" }
```
*/
fn main() {
println!("--output--");
println!("Ok");
}

View File

@@ -0,0 +1,2 @@
#[test]
fn test() {}

View File

@@ -0,0 +1,6 @@
#![feature(lang_items)]
fn main() {
println!("--output--");
println!("`#![feature]` *may* be used!");
}

View File

@@ -0,0 +1 @@
/Cargo.lock

View File

@@ -0,0 +1,10 @@
[package]
name = "slow-build"
version = "0.1.0"
authors = ["Daniel Keep <daniel.keep@gmail.com>"]
build = "slow-build-build.rs"
[lib]
name = "slow_build"
path = "slow-build-lib.rs"

View File

@@ -0,0 +1,5 @@
fn main() {
println!("Sleeping for 2 seconds...");
std::thread::sleep(std::time::Duration::from_millis(2000));
println!("Done.");
}

View File

@@ -0,0 +1,9 @@
// cargo-deps: boolinator="0.1.0"
#{prelude}
extern crate boolinator;
use boolinator::Boolinator;
fn main() {
println!("{:?}", Boolinator::as_option({#{script}}));
}

View File

@@ -0,0 +1,9 @@
// cargo-deps: boolinator="0.1.0"
#{prelude}
extern crate boolinator;
use boolinator::Boolinator;
fn main() {
println!("{:?}", Boolinator::as_option({#{script}}));
}

View File

@@ -0,0 +1,11 @@
#{prelude}
fn main() {
match {#{script}} {
script_result => {
let text = script_result.to_string();
let text = text.to_uppercase();
println!("{}", text);
}
}
}

View File

@@ -0,0 +1,6 @@
// cargo-deps: chrono
extern crate chrono;
fn main() {
println!("--output--");
println!("Hello");
}

View File

@@ -0,0 +1,4 @@
fn main() {
println!("--output--");
println!("hello, world");
}