environ 1.1.3

Set scope-limited values can can be accessed statically
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 26.54 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 328.35 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • tetcoin/environ
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • marlonhanks

Safe global references to stack variables.

Set up a global reference with environ! 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 environ;
// create a place for the global reference to exist.
environ!(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.
}