#static #local #cell

no-std local_static

Local static variable

2 releases

0.1.1 Jan 21, 2025
0.1.0 Jan 21, 2025

#594 in Embedded development

Download history 178/week @ 2025-01-18 12/week @ 2025-01-25 4/week @ 2025-02-01 2/week @ 2025-02-08

196 downloads per month

MIT license

6KB
68 lines

LocalStatic

LocalStatic is a interior mutable library that provides a way to store variables in static storage, allowing initialization at compile time and being unsafe-friendly for embedded programs.

Using LocalStatic in a multi-threaded or multi-core environment is extremely dangerous. Please use other thread-safe libraries such as lazy_static, once_cell, etc.

Usage

use local_static::LocalStatic;

{
	static TICK: LocalStatic<Tick> = LocalStatic::new();

	let tick = TICK.get_mut();
	if tick.elapsed_time().to_millis() >= 500 {
		*tick = Tick::now();

		//do something
	}
}

No runtime deps