pub struct Context<'a>(/* private fields */);Expand description
A handle to a context that may become invalid under specific conditions.
Invalidity only occurs after the associated ExtensionContext AS3 object
has been disposed. Therefore, callers should be prepared for operations
on Context to fail at appropriate points.
This crate leverages FREGetFREContextFromExtensionContext to enable
more advanced use cases, but doing so also increases overall complexity.
Implementations§
Source§impl<'a> Context<'a>
impl<'a> Context<'a>
pub fn is_valid(self) -> bool
pub fn event_dispatcher(self) -> EventDispatcher
Sourcepub unsafe fn with<F, R>(self, f: F) -> Result<R, ContextError>
pub unsafe fn with<F, R>(self, f: F) -> Result<R, ContextError>
Provides exclusive access to the ContextRegistry in a constrained manner.
§Safety
This method assumes that the native data associated with the Context
was created and is exclusively managed by crate::extension! as a ContextRegistry.
To call this method safely, you must guarantee that the native data
attached to the Context has NOT been manually managed, replaced,
or altered by external code. Violating this assumption may lead to
undefined behavior.
The use of a closure and the Sync bound is intentional: it constrains
the ordering of FFI interactions, while helping prevent data races,
preserving memory safety, and avoiding uncontrolled complexity growth
in cross-boundary usage.
Err=> ContextError::InvalidContext, ContextError::NullData, ContextError::UnexpectedData, ContextError::FfiCallFailed;
Sourcepub fn get_native_data(self) -> Result<FREData, FfiError>
pub fn get_native_data(self) -> Result<FREData, FfiError>
In typical usage of this crate, this function should not be called directly.
This is because the native data is reserved for ContextRegistry and is
automatically managed by crate::extension!.
Sourcepub unsafe fn set_native_data(
self,
data: NonNullFREData,
) -> Result<(), FfiError>
pub unsafe fn set_native_data( self, data: NonNullFREData, ) -> Result<(), FfiError>
In typical usage of this crate, this function should not be called directly.
This is because the native data is reserved for ContextRegistry and is
automatically managed by crate::extension!.
§Safety
This function sets the native data pointer associated with the underlying FREContext.
Calling this function is unsafe because the caller must uphold the following invariants:
-
The native data must not have been previously set
- The context must currently be in an uninitialized state with respect to native data.
- In other words,
Self::get_native_datamust return null pointer. - Violating this will overwrite an existing pointer, causing a memory leak or double-free.
-
The ownership and lifetime of
datamust be correctly managed- If
datarepresents a moved (owned) allocation, the caller is responsible for ensuring that it is eventually freed. - The memory must remain valid for the entire lifetime of the
FREContext. - The allocation must be released no later than in the
FREContextFinalizercallback, where the native data is expected to be cleaned up manually.
- If
Failure to uphold these guarantees may result in undefined behavior, including memory leaks, use-after-free, or double-free errors.
Sourcepub fn get_actionscript_data(self) -> Result<Object<'a>, FfiError>
pub fn get_actionscript_data(self) -> Result<Object<'a>, FfiError>
flash.external.ExtensionContext.actionScriptData
Sourcepub fn set_actionscript_data(self, object: Object<'_>) -> Result<(), FfiError>
pub fn set_actionscript_data(self, object: Object<'_>) -> Result<(), FfiError>
flash.external.ExtensionContext.actionScriptData
Sourcepub unsafe fn call_method(
self,
name: &str,
args: &[Object<'a>],
) -> Result<Object<'a>, ContextError>
pub unsafe fn call_method( self, name: &str, args: &[Object<'a>], ) -> Result<Object<'a>, ContextError>
Calls a registered function by name through this crate’s internal API.
§Safety
To call this method safely, all safety requirements of Self::with
must be upheld. In particular, the native data associated with the
Context must be a valid ContextRegistry created and exclusively
managed by crate::extension!, and must not be manually modified or
replaced by external code.
Violating these conditions may lead to undefined behavior.
pub fn trace(self, msg: impl Into<UCStr>) -> Result<(), FfiError>
Sourcepub fn get_render_mode(
self,
stage: Option<Object<'a>>,
) -> Result<RenderMode, FfiError>
pub fn get_render_mode( self, stage: Option<Object<'a>>, ) -> Result<RenderMode, FfiError>
Return Err if stage is non-null but not a Stage object
This is a minimal safety wrapper around the underlying FFI. Its current placement, shape, and usage are not ideal, and it is hoped that it can be refactored if a more flexible C API becomes available in the AIR SDK.
Sourcepub fn set_render_source(
self,
media_buffer: Object<'a>,
sprite: Object<'a>,
) -> Result<(), FfiError>
pub fn set_render_source( self, media_buffer: Object<'a>, sprite: Object<'a>, ) -> Result<(), FfiError>
air.media.MediaBuffer (AIR SDK 51)
AIR-5963: Add ANE capabilities to render a Sprite using a MediaBuffer - initial support via BitmapData
This is a minimal safety wrapper around the underlying FFI. Its current placement, shape, and usage are not ideal, and it is hoped that it can be refactored if a more flexible C API becomes available in the AIR SDK.
Sourcepub fn with_media_buffer<F, R>(
self,
media_buffer: Object<'a>,
f: F,
) -> Result<R, FfiError>where
F: FnOnce(MediaBufferDataAdapter<'_>) -> R,
pub fn with_media_buffer<F, R>(
self,
media_buffer: Object<'a>,
f: F,
) -> Result<R, FfiError>where
F: FnOnce(MediaBufferDataAdapter<'_>) -> R,
This is a minimal safety wrapper around the underlying FFI. Its current placement, shape, and usage are not ideal, and it is hoped that it can be refactored if a more flexible C API becomes available in the AIR SDK.
Trait Implementations§
Source§impl<'a> TryFrom<Object<'a>> for Context<'a>
impl<'a> TryFrom<Object<'a>> for Context<'a>
The returned Context must be used with caution. It is derived from external state,
and its associated data may be unknown and not managed by this crate. As a result,
the underlying memory may become invalid or outlive its expected lifetime.
This is a minimal safety wrapper around the underlying FFI. Its current placement, shape, and usage are not ideal, and it is hoped that it can be refactored if a more flexible C API becomes available in the AIR SDK.