Skip to main content

AsObject

Trait AsObject 

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

    // Provided methods
    fn as_object(self) -> Object<'a> { ... }
    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 objects of all types.

In typical usage of this crate, this trait should not be implemented directly.

This trait represents a common interface for types that are backed by an FREObject. It is only intended to be implemented when defining a new object type.

§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 struct.

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

Provided Methods§

Source

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

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::Object.

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

Return Err if this is null or undefined.

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 Array<'a>

Source§

const TYPE: Type = Type::Array

Source§

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

Source§

const TYPE: Type = Type::BitmapData

Source§

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

Source§

const TYPE: Type = Type::ByteArray

Source§

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

Source§

const TYPE: Type = Type::Context3D

Source§

impl<'a> AsObject<'a> for ErrorObject<'a>

Source§

const TYPE: Type = Type::Error

Source§

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

Source§

const TYPE: Type = Type::Vector

Source§

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

Source§

const TYPE: Type = Type::Boolean

Source§

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

Source§

const TYPE: Type = Type::Number

Source§

impl<'a> AsObject<'a> for StringObject<'a>

Source§

const TYPE: Type = Type::String

Source§

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

Source§

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

Source§

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

Source§

const TYPE: Type = Type::Object