Skip to main content

AsObject

Trait AsObject 

Source
pub unsafe trait AsObject<'a>:
    Sealed
    + Sized
    + Debug
    + Display
    + Copy
    + Into<Object<'a>>
    + Into<FREObject> {
    const TYPE: Type;

    // Provided methods
    fn as_object(self) -> Object<'a> { ... }
    unsafe fn as_unchecked<T: AsObject<'a>>(self) -> T { ... }
    unsafe fn from_unchecked<O: AsObject<'a>>(object: O) -> Self { ... }
    fn as_ptr(self) -> FREObject { ... }
    fn is_null(self) -> bool { ... }
    fn get_type(self) -> Type { ... }
    fn get_property(self, name: UCStr) -> Result<Object<'a>, ExternalError<'a>> { ... }
    fn set_property<O: AsObject<'a>>(
        self,
        name: UCStr,
        value: O,
    ) -> Result<(), ExternalError<'a>> { ... }
    fn call_method(
        self,
        name: UCStr,
        args: Option<&[Object<'_>]>,
    ) -> Result<Object<'a>, ExternalError<'a>> { ... }
    fn toString(self) -> Result<String<'a>, ExternalError<'a>> { ... }
}
Expand description

An abstraction over all AS3 objects.

This trait is Sealed and should not be implemented manually.

To define a new AS3 class, use the class! macro.

§Safety

Implementing this trait requires strict guarantees about memory layout. The implementing type must be layout-compatible with FREObject. In practice, this means it must be annotated with #[repr(transparent)] and wrap the underlying FREObject without altering its representation.

This requirement exists because the methods provided by this trait may perform reinterpretation of the underlying memory. Failure to uphold these guarantees will result in undefined behavior.

Required Associated Constants§

Source

const TYPE: Type

The Type associated with the class.

This does not represent the actual runtime type of the object.

Provided Methods§

Source

fn as_object(self) -> Object<'a>

Source

unsafe fn as_unchecked<T: AsObject<'a>>(self) -> T

Casts this object to T without checks.

Prefer to use TryAs::try_as instead whenever possible.

§Safety

The concrete object type must be fully determined, must be type-checked and validated in AS3, and the conversion must strictly follow the semantics of the AS3 as operator.

Violating these requirements may cause related APIs to perform illegal FFI calls, which may panic even if those APIs do not explicitly document panics. Violations may also result in undefined behavior.

Source

unsafe fn from_unchecked<O: AsObject<'a>>(object: O) -> Self

Casts an object to Self without checks.

Prefer to use TryAs::try_as instead whenever possible.

§Safety

The concrete object type must be fully determined, must be type-checked and validated in AS3, and the conversion must strictly follow the semantics of the AS3 as operator.

Violating these requirements may cause related APIs to perform illegal FFI calls, which may panic even if those APIs do not explicitly document panics. Violations may also result in undefined behavior.

Source

fn as_ptr(self) -> FREObject

Source

fn is_null(self) -> bool

Source

fn get_type(self) -> Type

Returns the runtime type of the object.

The result depends on the underlying FREGetObjectType implementation. Most unsupported types return Type::NonNullObject.

Source

fn get_property(self, name: UCStr) -> Result<Object<'a>, ExternalError<'a>>

Source

fn set_property<O: AsObject<'a>>( self, name: UCStr, value: O, ) -> Result<(), ExternalError<'a>>

Source

fn call_method( self, name: UCStr, args: Option<&[Object<'_>]>, ) -> Result<Object<'a>, ExternalError<'a>>

Source

fn toString(self) -> Result<String<'a>, ExternalError<'a>>

Returns Err when this is null or undefined.

Returns Err when an AS3 error occurs.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> AsObject<'a> for BitmapData<'a>

Source§

const TYPE: Type = crate::types::Type::BitmapData

Source§

impl<'a> AsObject<'a> for Context3D<'a>

Source§

impl<'a> AsObject<'a> for MediaBuffer<'a>

Source§

impl<'a> AsObject<'a> for NativeWindow<'a>

Source§

impl<'a> AsObject<'a> for Stage3D<'a>

Source§

impl<'a> AsObject<'a> for Stage<'a>

Source§

impl<'a> AsObject<'a> for Array<'a>

Source§

const TYPE: Type = crate::types::Type::Array

Source§

impl<'a> AsObject<'a> for ByteArray<'a>

Source§

const TYPE: Type = crate::types::Type::ByteArray

Source§

impl<'a> AsObject<'a> for Error<'a>

Source§

impl<'a> AsObject<'a> for Vector<'a>

Source§

const TYPE: Type = crate::types::Type::Vector

Source§

impl<'a> AsObject<'a> for Boolean<'a>

Source§

const TYPE: Type = crate::types::Type::Boolean

Source§

impl<'a> AsObject<'a> for Number<'a>

Source§

const TYPE: Type = crate::types::Type::Number

Source§

impl<'a> AsObject<'a> for String<'a>

Source§

const TYPE: Type = crate::types::Type::String

Source§

impl<'a> AsObject<'a> for int<'a>

Source§

impl<'a> AsObject<'a> for uint<'a>

Source§

impl<'a> AsObject<'a> for NonNullObject<'a>

Source§

const TYPE: Type = Type::NonNullObject

Source§

impl<'a> AsObject<'a> for Object<'a>