Attribute

Trait Attribute 

Source
pub trait Attribute: Sized {
    const DEFINDEX: u32;
    const ATTRIBUTE: AttributeDef;
    const USES_FLOAT_VALUE: bool;

    // Required method
    fn attribute_float_value(&self) -> Option<f32>;

    // Provided method
    fn attribute_value(&self) -> AttributeValue { ... }
}
Expand description

Attribute values for an item attribute.

Required Associated Constants§

Source

const DEFINDEX: u32

The defindex.

Source

const ATTRIBUTE: AttributeDef

The attribute definition.

Source

const USES_FLOAT_VALUE: bool

Not part of the schema.

This is a marker to specify which attribute field is meaningful to us in obtaining the attribute’s value.

§Kill Count Example
{
    "defindex": 214,
    "value": 918,
    "float_value": 1.28639199025018207e-42
}

This is the “kill_eater” attribute. “918” refers to the number of kills. The float_value field is the same number as a 32-bit float.

You can perform the conversions yourself with the following code:

let value = 918u32;
let float_value = 1.28639199025018207e-42f32;
 
assert_eq!(f32::from_bits(value), float_value);
assert_eq!(float_value.to_bits(), value);
§Sheen Example
{
    "defindex": 2014,
    "value": 1086324736,
    "float_value": 6
}

This is the “killstreak_idleeffect” attribute. “6” refers to the associated sheen ( Sheen::VillainousViolet), but is stored in the float_value field, unlike “kill_eater”. The value field is the same number as a 32-bit float.

While both values refer to the same value, and internally the attribute’s value is its float_value, there are many cases where the float_value doesn’t mean anything to us unless converted to a 32-bit integer from its bits, and if the float_value does mean something to us we don’t want to convert it to an integer. This can be a little confusing, but it’s just how the API is.

By marking each attribute with a uses_float_value flag, we can indicate whether the float_value field is meaningful to use for that attribute.

Required Methods§

Source

fn attribute_float_value(&self) -> Option<f32>

Gets the attribute float value.

Provided Methods§

Source

fn attribute_value(&self) -> AttributeValue

Gets the attribute value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Attribute for FootprintsSpell

Source§

impl Attribute for KillstreakTier

Source§

impl Attribute for Killstreaker

Source§

impl Attribute for Paint

Source§

impl Attribute for PaintSpell

Source§

impl Attribute for Sheen

Source§

impl Attribute for Wear

Source§

impl Attribute for CustomDescAttr

Source§

impl Attribute for CustomNameAttr

Source§

impl Attribute for CustomTextureHi

Source§

impl Attribute for CustomTextureLo

Source§

impl Attribute for DynamicRecipeComponentDefinedItem1

Source§

impl Attribute for DynamicRecipeComponentDefinedItem2

Source§

impl Attribute for DynamicRecipeComponentDefinedItem3

Source§

impl Attribute for DynamicRecipeComponentDefinedItem4

Source§

impl Attribute for DynamicRecipeComponentDefinedItem5

Source§

impl Attribute for DynamicRecipeComponentDefinedItem6

Source§

impl Attribute for DynamicRecipeComponentDefinedItem7

Source§

impl Attribute for DynamicRecipeComponentDefinedItem8

Source§

impl Attribute for DynamicRecipeComponentDefinedItem9

Source§

impl Attribute for DynamicRecipeComponentDefinedItem10

Source§

impl Attribute for EventDate

Source§

impl Attribute for GifterAccountId

Source§

impl Attribute for HalloweenDeathGhosts

Source§

impl Attribute for HalloweenGreenFlames

Source§

impl Attribute for HalloweenPumpkinExplosions

Source§

impl Attribute for HalloweenVoiceModulation

Source§

impl Attribute for IsAustralium

Source§

impl Attribute for IsFestivized

Source§

impl Attribute for KillEater

Source§

impl Attribute for MakersMarkId

Source§

impl Attribute for PaintkitProtoDefIndex

Source§

impl Attribute for SeriesNumber

Source§

impl Attribute for SetAttachedParticle

Source§

impl Attribute for SupplyCrateSeries

Source§

impl Attribute for TauntAttachParticleIndex

Source§

impl Attribute for ToolTargetItem

Source§

impl Attribute for TradableAfterDate

Source§

impl Attribute for UniqueCraftIndex