#variables #values #env-var #access #scoped #cargo-toml #statically

no-std environmental

Set scope-limited values can can be accessed statically

7 stable releases

1.1.4 Nov 30, 2022
1.1.3 May 12, 2021
1.1.2 Sep 30, 2020
1.1.1 Jan 9, 2020
1.0.0 Sep 13, 2018

#21 in Configuration

Download history 49118/week @ 2024-07-28 53788/week @ 2024-08-04 69874/week @ 2024-08-11 49992/week @ 2024-08-18 60762/week @ 2024-08-25 65925/week @ 2024-09-01 60176/week @ 2024-09-08 56558/week @ 2024-09-15 61480/week @ 2024-09-22 63406/week @ 2024-09-29 61010/week @ 2024-10-06 58287/week @ 2024-10-13 65406/week @ 2024-10-20 53076/week @ 2024-10-27 70816/week @ 2024-11-03 53167/week @ 2024-11-10

244,358 downloads per month
Used in 784 crates (18 directly)

Apache-2.0

19KB
386 lines

Environmental

.Summary [source, toml]

include::Cargo.toml[lines=2..5]

.Description

include::src/lib.rs[tag=description]

lib.rs:

Safe global references to stack variables.

Set up a global reference with environmental! macro giving it a name and type. Use the using function scoped under its name to name a reference and call a function that takes no parameters yet can access said reference through the similarly placed with function.

Examples

#[macro_use] extern crate environmental;
// create a place for the global reference to exist.
environmental!(counter: u32);
fn stuff() {
  // do some stuff, accessing the named reference as desired.
  counter::with(|i| *i += 1);
}
fn main() {
  // declare a stack variable of the same type as our global declaration.
  let mut counter_value = 41u32;
  // call stuff, setting up our `counter` environment as a reference to our counter_value var.
  counter::using(&mut counter_value, stuff);
  println!("The answer is {:?}", counter_value); // will print 42!
  stuff();	// safe! doesn't do anything.
}

No runtime deps

Features