Skip to main content

fre_rs/types/
mod.rs

1//! 
2//! Abstractions over ActionScript objects for integration with its type system.
3//! 
4
5
6pub mod classes;
7pub mod object;
8pub mod primitive;
9
10use {
11    classes::*,
12    object::*,
13    primitive::*,
14};
15use super::*;
16
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum Type {
20    
21    // Supported by [`FREGetObjectType`].
22    Object,
23    Number,
24    String,
25    ByteArray,
26    Array,
27    Vector,
28    BitmapData,
29    Boolean,
30    Null,
31
32    // Not supported by [`FREGetObjectType`].
33    Named(&'static str),
34    Error,
35    Context3D,
36    Unexpected(FREObjectType),
37
38}
39impl Type {
40    pub fn is_null(self) -> bool {self == Self::Null}
41}
42impl From<FREObjectType> for Type {
43    fn from(value: FREObjectType) -> Self {
44        match value {
45            FREObjectType::FRE_TYPE_OBJECT      => Self::Object,
46            FREObjectType::FRE_TYPE_NUMBER      => Self::Number,
47            FREObjectType::FRE_TYPE_STRING      => Self::String,
48            FREObjectType::FRE_TYPE_BYTEARRAY   => Self::ByteArray,
49            FREObjectType::FRE_TYPE_ARRAY       => Self::Array,
50            FREObjectType::FRE_TYPE_VECTOR      => Self::Vector,
51            FREObjectType::FRE_TYPE_BITMAPDATA  => Self::BitmapData,
52            FREObjectType::FRE_TYPE_BOOLEAN     => Self::Boolean,
53            FREObjectType::FRE_TYPE_NULL        => Self::Null,
54            _ => Self::Unexpected(value),
55        }
56    }
57}
58impl Display for Type {
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        match *self {
61            Self::Named(name) => write!(f, "{name}"),
62            Self::Unexpected(ty) => write!(f, "Unexpected FREObjectType. ({ty:#08X})"),
63            _ => write!(f, "{self:?}"),
64        }
65    }
66}