#environmental #statically #u32 #toml #tag-description

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

#561 in Encoding

Download history 53235/week @ 2025-01-29 60386/week @ 2025-02-05 67967/week @ 2025-02-12 54649/week @ 2025-02-19 54314/week @ 2025-02-26 57546/week @ 2025-03-05 58662/week @ 2025-03-12 52580/week @ 2025-03-19 60484/week @ 2025-03-26 52900/week @ 2025-04-02 49057/week @ 2025-04-09 43731/week @ 2025-04-16 64156/week @ 2025-04-23 50917/week @ 2025-04-30 45759/week @ 2025-05-07 44099/week @ 2025-05-14

214,827 downloads per month
Used in 864 crates (20 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

OSZAR »