Crate tf2_price

Source
Expand description

§tf2-price

Utilities for Team Fortress 2 item pricing.

§Usage

use tf2_price::{Currencies, ONE_REF, scrap};
 
let mut currencies = Currencies {
    keys: 5,
    weapons: scrap!(5),
};
 
// add another currencies
currencies += Currencies {
    keys: 2,
    weapons: 0,
};
assert_eq!(currencies, Currencies { keys: 7, weapons: 10 });
 
// add keys
currencies.keys += 5;
assert_eq!(currencies, Currencies { keys: 12, weapons: 10 });
 
// add metal - this value is represented as the number of weapons
currencies.weapons += ONE_REF * 5;
assert_eq!(currencies, Currencies { keys: 12, weapons: 100 });

§Conventions

Metal values are represented as weapons, the smallest unit of currency. To ensure accurate accounting, utilize the provided macros and constants. For instance, by using the ONE_SCRAP constant or the scrap!(1) macro, one scrap will be added to the weapons field. To convert floating point refined values into weapons, use the metal! macro e.g. metal!(1.33) converts into 24 weapons.

In addition, all key values in methods are represented as values in weapons.

Arithmetic operations employ saturating operations, preventing overflow. Adding two currencies each containing i64::MAX will yield i64::MAX instead of wrapping around. Although values are stored as 64-bit integers and typically won’t overflow with reasonable numbers, checked methods are provided for overflow checking if needed.

Modules§

error
Error types.

Macros§

metal
Generates value for metal.
reclaimed
Generates value for reclaimed metal.
refined
Generates value for refined metal.
scrap
Generates value for scrap metal.

Structs§

Currencies
For storing item currencies values.
FloatCurrencies
For storing floating point values of currencies. This is useful for retaining the original values from responses. Convert to Currencies to perform precise arithmetical operations or comparisons.

Enums§

Rounding
Rounding methods for metal values.

Constants§

ONE_REC
Value for one reclaimed metal.
ONE_REF
Value for one refined metal.
ONE_SCRAP
Value for one scrap metal.
ONE_WEAPON
Value for one weapon.

Functions§

checked_get_weapons_from_metal_float
Converts a float value into a metal value.
get_metal_float_from_weapons
Converts a value in weapons into its float value.
get_weapons_from_metal_float
Converts a float value into a metal value (represented as weapons).

Type Aliases§

Currency
The integer type used for currencies.