#values #statically #accessed #global #stack #reference #scope-limited

no-std environ

Set scope-limited values can can be accessed statically

Show the crate…

3 releases (stable)

1.1.3 May 29, 2021
1.1.2 Mar 3, 2021
0.0.0 Mar 3, 2021

#49 in #statically

Download history 279/week @ 2023-12-18 224/week @ 2023-12-25 96/week @ 2024-01-01 245/week @ 2024-01-08 176/week @ 2024-01-15 133/week @ 2024-01-22 120/week @ 2024-01-29 180/week @ 2024-02-05 216/week @ 2024-02-12 134/week @ 2024-02-19 248/week @ 2024-02-26 267/week @ 2024-03-04 190/week @ 2024-03-11 241/week @ 2024-03-18 455/week @ 2024-03-25 459/week @ 2024-04-01

1,415 downloads per month
Used in 149 crates (via externalities)

Apache-2.0

16KB
315 lines

Tetsy Environ - A form of Environmental to set scope-limited values can can be accessed statically

.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 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.
}

No runtime deps

Features