Skip to main content

fre_rs/
lib.rs

1//!
2//! Safe, ergonomic Rust abstraction over the AIR Native Extension (ANE) C API ([`fre-sys`](https://crates.io/crates/fre-sys)) for native-side development.
3//!
4//! ## Getting Started
5//!
6//! The primary entry points of this crate are the macros [`extension!`] and [`function!`].
7//! Refer to their documentation for details and examples.
8//!
9//! # Flash Runtime Extension Lifecycle
10//!
11//! ```text
12//!                                   Flash-runtime ━━━━┓
13//!                                                     ┃
14//!          ExtensionContext.loadExtension ━━━━━━━━━━━━┫
15//!                ↓                                    ┃
16//!    ┏━━━━ Extension-Load ━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
17//!    ┃           ↓                                    ┃
18//!    ┃     Initializer → Extension-Data               ┃
19//!    ┃           ↓                                    ┃
20//!    ┃  ┏━━ ExtensionContext.createExtensionContext ━━┫
21//!    ┃  ┃        ↓                                    ┃
22//!    ┃  ┃    Context-Initializer → Context-Data       ┃
23//!    ┃  ┃        ↓            ↓    ↓         ↓        ┃
24//!    ┃  ┃    Function-Data → Function  Extension-Data ┃
25//!    ┃  ┃                     ↑                       ┃
26//!    ┃  ┣━━ ExtensionContext.call ━━━━━━━━━━━━━━━━━━━━┫
27//!    ┃  ┃                                             ┃
28//!    ┃  ┃                        Extension-Data       ┃
29//!    ┃  ┃                              ↑              ┃
30//!    ┃  ┃    Context-Data ≈ `ContextRegistry`         ┃
31//!    ┃  ┃        ↓                     ↑              ┃
32//!    ┃  ┃    Context-Finalizer    Function-Data       ┃
33//!    ┃  ┃        ↑                                    ┃
34//!    ┃  ┗━━ ExtensionContext.dispose ━━━━━━━━━━━━━━━━━┫
35//!    ┃                                                ┃
36//!    ┃            Extension-Data → Finalizer          ┃
37//!    ┃                                 ↑              ┃
38//!    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━ Extension-Unload ━━━━┛
39//! ```
40//!
41
42
43
44/// Namespace for ActionScript 3 classes and objects.
45/// 
46pub mod as3 {
47    use super::*;
48    pub use crate::types::{
49        display::*,
50        misc::*,
51        object::{Object},
52        primitive::*,
53    };
54
55    /// Although `'static`, using [`null`] outside the Flash runtime main thread,
56    /// or within certain restricted closure call stacks (when an object is acquired
57    /// and the runtime is constrained) is unsupported. Related APIs may return errors in such cases.
58    /// 
59    #[allow(non_upper_case_globals)]
60    // 
61    // ALL APIS THAT MAY BE USED IN UNSUPPORTED CASES MUST HANDLE ERRORS CORRECTLY AND MUST NOT PANIC. (`AsObject`, `Object`)
62    // 
63    pub const null: Object<'static> = unsafe {transmute(std::ptr::null_mut::<FREObject>())};
64}
65
66/// [`fre-sys`](https://crates.io/crates/fre-sys)
67/// 
68pub mod c {pub use fre_sys::*;}
69pub mod prelude {
70    pub use crate::{
71        as3,
72        types::{Type, object::{Object, NonNullObject, AsObject, AsNonNullObject, TryAs}},
73        context::{Context, CurrentContext},
74        data::Data,
75        event::*,
76        function::{FunctionSet, trace},
77        validated::*,
78    };
79    pub use std::any::Any;
80}
81pub mod context;
82pub mod data;
83pub mod error;
84pub mod event;
85pub mod function;
86mod macros;
87pub mod misc;
88pub mod types;
89pub mod validated;
90pub mod utils;
91
92
93use {
94    prelude::*,
95    c::*,
96    data::ExtensionData,
97    error::*,
98    function::*,
99    misc::*,
100    utils::*,
101};
102use std::{
103    borrow::Cow,
104    cell::{RefCell},
105    collections::HashMap,
106    ffi::{CStr, CString, NulError, c_void, c_char},
107    fmt::{self, Debug, Display},
108    marker::PhantomData,
109    mem::{MaybeUninit, transmute},
110    ptr::{NonNull},
111    rc::Rc,
112    str::Utf8Error,
113    sync::{Arc, Mutex},
114};
115
116
117/// Internal implementation details of the crate. Not intended for public use.
118/// 
119#[doc(hidden)]
120pub mod __private {
121    pub unsafe trait Sealed {}
122    pub(crate) const SEALED: () = ();
123    pub mod context {
124        pub use crate::context::stack::{with, with_initializer, with_method};
125    }
126}
127