diff --git a/.cargo/config.toml b/.cargo/config.toml index c30d988..f470805 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -4,4 +4,11 @@ rustflags = ["-C", "link-arg=-fuse-ld=lld"] # sudo apt -y install lld [target.'cfg(target_os = "macos")'] # For faster link times ($ brew install michaeleisel/zld/zld ) -rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld"] \ No newline at end of file +rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld"] + +# Run time env. vars. see main.rs for usage +[env] +FOO = "bar" +XX = "42" +PATH_TO_SOME_TOOL = { value = "bin/tool", relative = true } +USERNAME = { value = "test_user", force = true } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4c9aee3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "rust-analyzer.linkedProjects": [ + "./Cargo.toml" + ], + "rust-analyzer.showUnlinkedFileNotification": false +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 8a5cf83..f7ebd08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,18 @@ clap = "4.0.32" [features] foo = [] # feature has no explicit dependencies +# Todo: how to use them? +# Compile time env. vars +# To use at runtime, ss .cargo/config.toml +[env] +RUST_BACKTRACE="1" +AA=1 +BB=true +FOO = "bar" +XX = 42 +PATH_TO_SOME_TOOL = { value = "bin/tool", relative = true } +USERNAME = { value = "test_user", force = true } + # # All workspace members should inherit these keys for package declarations. # [workspace.package] # authors = ["Aptos Labs "] diff --git a/src/env.vars.rs b/src/env.vars.rs new file mode 100644 index 0000000..4e5aa39 --- /dev/null +++ b/src/env.vars.rs @@ -0,0 +1,11 @@ + +// Run time env. vars use +// .cargo/config.toml +// [env] +// ... +// see main.rs for usage + +// Todo +// Compile time env. vars use +// Cargo.toml +// [env] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5473cff..6b6a64d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,11 @@ mod closure; fn main() { + // 0) Use runtime env. vars. See [env] in Cargo.toml + let xx: i32 = env!("XX").parse().unwrap(); + println!("xx: {:?}", xx); // 42 + + // 1) Minigrep --------------------------------------------- // Usage: // cargo r search-str file.txt diff --git a/src/temp.rs b/src/temp.rs index cb149e6..fccb258 100644 --- a/src/temp.rs +++ b/src/temp.rs @@ -5,3 +5,9 @@ // assert_eq!(32, 32); // } + +#[test] +fn ex1_ww() { + // println!("xx: {:?}", xx); + assert_eq!(42, 42); +}