Skip to main content

Context

Struct Context 

Source
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>

Source

pub fn is_valid(self) -> bool

Source

pub fn event_dispatcher(self) -> EventDispatcher

Source

pub unsafe fn with<F, R>(self, f: F) -> Result<R, ContextError>
where F: FnOnce(&mut ContextRegistry) -> R + Sync,

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;

Source

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!.

Source

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:

  1. 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_data must return null pointer.
    • Violating this will overwrite an existing pointer, causing a memory leak or double-free.
  2. The ownership and lifetime of data must be correctly managed

    • If data represents 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 FREContextFinalizer callback, where the native data is expected to be cleaned up manually.

Failure to uphold these guarantees may result in undefined behavior, including memory leaks, use-after-free, or double-free errors.

Source

pub fn get_actionscript_data(self) -> Result<Object<'a>, FfiError>

flash.external.ExtensionContext.actionScriptData

Source

pub fn set_actionscript_data(self, object: Object<'_>) -> Result<(), FfiError>

flash.external.ExtensionContext.actionScriptData

Source

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.

Source

pub fn trace(self, msg: impl Into<UCStr>) -> Result<(), FfiError>

Source

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.

Source

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.

Source

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> Clone for Context<'a>

Source§

fn clone(&self) -> Context<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Context<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Context<'a>

Source§

fn eq(&self, other: &Context<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<Object<'a>> for Context<'a>

Attempts to cast an Object into an ExtensionContext, returning Err if it is not.

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.

Source§

type Error = FfiError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Object<'_>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> Copy for Context<'a>

Source§

impl<'a> Eq for Context<'a>

Source§

impl<'a> StructuralPartialEq for Context<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Context<'a>

§

impl<'a> RefUnwindSafe for Context<'a>

§

impl<'a> !Send for Context<'a>

§

impl<'a> !Sync for Context<'a>

§

impl<'a> Unpin for Context<'a>

§

impl<'a> UnsafeUnpin for Context<'a>

§

impl<'a> UnwindSafe for Context<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.