Expand description
Provides enumerated types for models related to the Team Fortress 2 item schema. Other utilities relating to the schema are also included, as well as related item and attribute conversion helpers. This crate provides a number of additional attributes mostly related to trading.
For the most part, definitions here are relatively stable and don’t have any new values added or changed. However, Valve can implement changes to the item schema at any time, which may affect some of the values defined here.
Definitions for things that are often updated like items, skins, and particles are not included.
§Usage
use tf2_enum::{Quality, Spell, ItemLevel, KillstreakTier, IntoEnumIterator};
use std::str::FromStr;
assert_eq!("Unusual".parse::<Quality>().unwrap(), Quality::Unusual);
assert_eq!(Quality::Unusual as u32, 5);
assert_eq!(Spell::HalloweenFire.to_string(), "Halloween Fire");
let level = ItemLevel::KillEaterRank.score_level(9000);
let killstreak_tier = KillstreakTier::Professional;
let full_name = format!("{level} {killstreak_tier} Pomson 6000");
assert_eq!(full_name, "Hale's Own Professional Killstreak Pomson 6000");
/// Iterate over all quality values.
for quality in Quality::iter() {
println!("{quality}");
}
Modules§
- econ_
attributes - Includes commonly-used non-enumerated attributes related to economy items. Included for convenience.
- error
- Provides error types.
- prelude
- Provides a prelude for easy importing of commonly used items.
Structs§
- Attribute
Def - Represents the definition of an attribute in the schema.
- Item
Attribute - Container type for item attributes.
- Level
- Level belonging to an
ItemLevel
. - Spell
Set - Contains up to 2 spells. Although the underlying data structure is an array, this structure
behaves like a set. Most methods mimic those of
HashSet
, with a few differences. - Spell
SetIterator - Iterator for spells.
- Strange
Part Set - Contains up to 3 strange parts. Although the underlying data structure is an array, this
structure behaves like a set. Most methods mimic those of
HashSet
, with a few differences. - Strange
Part SetIterator - Iterator for strange parts.
Enums§
- Attribute
Value - A value for an attribute.
- Capability
- Capability.
- Class
- Class.
- Craft
Class - Craft class.
- Craft
Material Type - Craft material type.
- Description
Format - Description format.
- Effect
Type - Effect type.
- Footprints
Spell - Footprints spell.
- Grade
- Grade.
- Item
Level - Item level.
- Item
Slot - Item slot.
- Kill
Eater Score Type - Kill eater score type. Conversion from strings is not supported due to multiple variants having the same string representation. They can still be formatted into strings.
- Killstreak
Tier - Killstreak tier.
- Killstreaker
- Killstreaker.
- Origin
- Origin.
- Paint
- Paint.
repr
values are mapped to the corresponding hexadecimal color (represented as a u32). For team paints, this is the color for RED team. - Paint
Spell - Paint spell.
- Quality
- Quality.
- Sheen
- Sheen.
- Spell
- Spell.
- Stock
Weapon - Stock weapons.
- Strange
Part - Strange part.
repr
values are mapped to theirkill_eater_score_type
attribute value. Strings are the name of thekill_eater_score_type
, not the name of the strange part. - Wear
- Wear.
Traits§
- Attribute
- Attribute values for an item attribute.
- Attribute
Set - A fixed set of attributes.
- Attributes
- Associated attribute values for a set of item attributes.
- Colored
- Definitions which are associated with colors.
- Enum
Count - A trait for capturing the number of variants in Enum. This trait can be autoderived by
strum_macros
. - HasItem
Defindex - Definitions which are associated with an item defindex.
- Into
Enum Iterator - This trait designates that an
Enum
can be iterated over. It can be auto generated using theEnumIter
derive macro. - TryFrom
IntAttribute Value - Backwards conversion for attributes associated with an integer value.
- TryFrom
Primitive
Derive Macros§
- Enum
Count - Add a constant
usize
equal to the number of variants. - Into
Primitive - Implements
Into<Primitive>
for a#[repr(Primitive)] enum
. - TryFrom
Primitive - Implements
TryFrom<Primitive>
for a#[repr(Primitive)] enum
.