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§
Sourceconst ATTRIBUTE: AttributeDef
const ATTRIBUTE: AttributeDef
The attribute definition.
Sourceconst USES_FLOAT_VALUE: bool
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§
Sourcefn attribute_float_value(&self) -> Option<f32>
fn attribute_float_value(&self) -> Option<f32>
Gets the attribute float value.
Provided Methods§
Sourcefn attribute_value(&self) -> AttributeValue
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".