Crate tf2_enum

Crate tf2_enum 

Source
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§

AttributeDef
Represents the definition of an attribute in the schema.
ItemAttribute
Container type for item attributes.
Level
Level belonging to an ItemLevel.
SpellSet
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.
SpellSetIterator
Iterator for spells.
StrangePartSet
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.
StrangePartSetIterator
Iterator for strange parts.

Enums§

AttributeValue
A value for an attribute.
Capability
Capability.
Class
Class.
CraftClass
Craft class.
CraftMaterialType
Craft material type.
DescriptionFormat
Description format.
EffectType
Effect type.
FootprintsSpell
Footprints spell.
Grade
Grade.
ItemLevel
Item level.
ItemSlot
Item slot.
KillEaterScoreType
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.
KillstreakTier
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.
PaintSpell
Paint spell.
Quality
Quality.
Sheen
Sheen.
Spell
Spell.
StockWeapon
Stock weapons.
StrangePart
Strange part. repr values are mapped to their kill_eater_score_type attribute value. Strings are the name of the kill_eater_score_type, not the name of the strange part.
Wear
Wear.

Traits§

Attribute
Attribute values for an item attribute.
AttributeSet
A fixed set of attributes.
Attributes
Associated attribute values for a set of item attributes.
Colored
Definitions which are associated with colors.
EnumCount
A trait for capturing the number of variants in Enum. This trait can be autoderived by strum_macros.
HasItemDefindex
Definitions which are associated with an item defindex.
IntoEnumIterator
This trait designates that an Enum can be iterated over. It can be auto generated using the EnumIter derive macro.
TryFromIntAttributeValue
Backwards conversion for attributes associated with an integer value.
TryFromPrimitive

Derive Macros§

EnumCount
Add a constant usize equal to the number of variants.
IntoPrimitive
Implements Into<Primitive> for a #[repr(Primitive)] enum.
TryFromPrimitive
Implements TryFrom<Primitive> for a #[repr(Primitive)] enum.