windows_bindgen/tables/
constant.rs

1use super::*;
2
3impl std::fmt::Debug for Constant {
4    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
5        f.debug_tuple("Constant").field(&self.value()).finish()
6    }
7}
8
9impl Constant {
10    pub fn ty(&self) -> Type {
11        Type::from_element_type(self.usize(0)).unwrap()
12    }
13
14    pub fn value(&self) -> Value {
15        let mut blob = self.blob(2);
16
17        match self.ty() {
18            Type::I8 => Value::I8(blob.read_i8()),
19            Type::U8 => Value::U8(blob.read_u8()),
20            Type::I16 => Value::I16(blob.read_i16()),
21            Type::U16 => Value::U16(blob.read_u16()),
22            Type::I32 => Value::I32(blob.read_i32()),
23            Type::U32 => Value::U32(blob.read_u32()),
24            Type::I64 => Value::I64(blob.read_i64()),
25            Type::U64 => Value::U64(blob.read_u64()),
26            Type::F32 => Value::F32(blob.read_f32()),
27            Type::F64 => Value::F64(blob.read_f64()),
28            Type::String => Value::String(blob.read_utf16()),
29            rest => panic!("{rest:?}"),
30        }
31    }
32}