Expand description
Provides utilities for Team Fortress 2 item pricing.
§Usage
use tf2_price::{Currencies, ref_to_weps};
let mut currencies = Currencies {
keys: 5,
weapons: ref_to_weps!(1.33), // 1.33 refined metal
};
// add keys
currencies.keys += 5;
assert_eq!(currencies, Currencies { keys: 10, weapons: 24 });
// add metal - this value is represented as the number of weapons
currencies.weapons += ref_to_weps!(0.33);
assert_eq!(currencies, Currencies { keys: 10, weapons: 30 });
// add another currencies
currencies += Currencies {
keys: 2,
weapons: 0,
};
assert_eq!(currencies, Currencies { keys: 12, weapons: 30 });§Conventions
Metal values are represented as weapons, the smallest unit of currency. To ensure accurate
accounting, utilize the provided constants. To convert floating point refined values into
weapons, use the ref_to_weps macro e.g. ref_to_weps!(1.33) converts into 24 weapons.
Arithmetic operations employ
saturating operations,
preventing overflow. Adding two currencies that exceed i64::MAX will yield i64::MAX instead
of wrapping around. You can also utilize the checked_* methods if checking for overflow is
needed.
Modules§
- error
- Error types.
Macros§
- ref_
to_ weps - Converts a refined metal value into weapons. While this method is convenient, keep in mind that macros in Rust can increase compilation time and binary size, so don’t overuse them. Prefer using the constants provided from this crate.
Structs§
- Currencies
- For storing item currencies values.
- Float
Currencies - For storing floating point values of currencies. This is useful for retaining the original
values from responses. Convert to
Currenciesto perform precise arithmetical operations or comparisons.
Enums§
- Rounding
- Rounding methods for metal values.
Constants§
- ONE_REC
- Value for one reclaimed metal (represented as weapons).
- ONE_REF
- Value for one refined metal (represented as weapons).
- ONE_
SCRAP - Value for one scrap metal (represented as weapons).
- 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.