#global #piston #singleton #setting-up

current

A library for setting current values for stack scope, such as application structure

8 releases

Uses old Rust 2015

0.1.2 Sep 6, 2016
0.1.1 Jun 24, 2015
0.0.10 Apr 4, 2015
0.0.7 Feb 21, 2015
0.0.5 Jan 21, 2015

#1975 in Rust patterns

Download history 49/week @ 2024-07-19 40/week @ 2024-07-26 49/week @ 2024-08-02 63/week @ 2024-08-09 36/week @ 2024-08-16 38/week @ 2024-08-23 52/week @ 2024-08-30 35/week @ 2024-09-06 35/week @ 2024-09-13 47/week @ 2024-09-20 30/week @ 2024-09-27 13/week @ 2024-10-04 28/week @ 2024-10-11 25/week @ 2024-10-18 21/week @ 2024-10-25 33/week @ 2024-11-01

107 downloads per month
Used in 7 crates (5 directly)

MIT license

6KB
96 lines

current Build Status

A library for setting current values for stack scope, such as application structure

Example project: Sea Birds' Breakfast

How to use it

See Best coding practices with current objects

This also posts safety guidelines for the library.

Motivation

In game programming, there are many kinds of "current" values:

  • The current window
  • The current device
  • The current sound driver
  • The current player object

There are two ways to use this library:

  • An unsafe version that ease refactoring between current objects and mutable references
  • A safe version that can be used in experimental library design

By setting these up as "current" values, you don't have to pass them around to each method. For example, you can write code like this (demonstrating the unsafe version):

e.press(|button| {
    let gun = unsafe { &mut *current_gun() };
    let player = unsafe { &mut *current_player() };
    if button == SHOOT {
        gun.shoot(player.aim);
    }
});

How to contribute

No runtime deps

Features