Skip to main content

fre_rs/types/
mod.rs

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