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 object types.
45///
46pub mod as3 {
47 use super::*;
48 pub use crate::types::{
49 classes::{Array, Vector, ByteArray, BitmapData, Context3D, ErrorObject as Error},
50 object::{Object},
51 primitive::{int, uint, Number, Boolean, StringObject as String}
52 };
53
54 /// Although `'static`, it must not be used outside the Flash runtime main thread,
55 /// or related APIs may return errors or panic due to failed assertions.
56 ///
57 #[allow(non_upper_case_globals)]
58 pub const null: Object = unsafe {transmute(std::ptr::null_mut::<FREObject>())};
59}
60
61/// [`fre-sys`](https://crates.io/crates/fre-sys)
62///
63pub mod c {pub use fre_sys::*;}
64pub mod prelude {
65 pub use crate::{
66 as3,
67 types::{Type, object::{AsObject, TryAs}},
68 context::{Context, CurrentContext},
69 data::Data,
70 event::*,
71 function::FunctionSet,
72 validated::*,
73 };
74 pub use std::any::Any;
75}
76
77/// Internal implementation details of the crate. Not intended for public use.
78///
79#[doc(hidden)]
80pub mod __private {
81 thread_local! {
82 /// Thread-local storage for caching panic information,
83 /// which will be propagated to the Flash Runtime.
84 pub static LAST_PANIC_INFO: std::cell::RefCell<Option<String>> = std::cell::RefCell::new(None);
85 }
86 pub(crate) trait Sealed {}
87}
88
89pub mod context;
90pub mod data;
91pub mod error;
92pub mod event;
93pub mod function;
94mod macros;
95pub mod misc;
96pub mod types;
97pub mod validated;
98pub mod utils;
99
100
101use {
102 prelude::*,
103 c::prelude::*,
104 data::ExtensionData,
105 error::*,
106 function::*,
107 utils::*,
108 __private::Sealed,
109};
110use std::{
111 cell::{RefCell},
112 collections::HashMap,
113 error::Error,
114 ffi::{CStr, CString, NulError, c_void, c_char},
115 fmt::{self, Debug, Display},
116 marker::PhantomData,
117 mem::{transmute, size_of, size_of_val},
118 ptr::{NonNull},
119 str::Utf8Error,
120 sync::{Arc, Mutex},
121};