pub struct Object {
    pub(super) name: String,
    pub(super) imp: ObjectImpl,
    pub(super) module_path: String,
    pub(super) constructors: Vec<Constructor>,
    pub(super) methods: Vec<Method>,
    pub(super) uniffi_traits: Vec<UniffiTrait>,
    pub(super) ffi_func_clone: FfiFunction,
    pub(super) ffi_func_free: FfiFunction,
    pub(super) ffi_init_callback: Option<FfiFunction>,
    pub(super) docstring: Option<String>,
}
Expand description

An “object” is an opaque type that is passed around by reference, can have methods called on it, and so on - basically your classic Object Oriented Programming type of deal, except without elaborate inheritance hierarchies. Some can be instantiated.

In UDL these correspond to the interface keyword.

At the FFI layer, objects are represented by an opaque integer handle and a set of functions a common prefix. The object’s constructors are functions that return new objects by handle, and its methods are functions that take a handle as first argument. The foreign language binding code is expected to stitch these functions back together into an appropriate class definition (or that language’s equivalent thereof).

TODO:

  • maybe “Class” would be a better name than “Object” here?

Fields§

§name: String§imp: ObjectImpl

How this object is implemented in Rust

§module_path: String§constructors: Vec<Constructor>§methods: Vec<Method>§uniffi_traits: Vec<UniffiTrait>§ffi_func_clone: FfiFunction§ffi_func_free: FfiFunction§ffi_init_callback: Option<FfiFunction>§docstring: Option<String>

Implementations§

source§

impl Object

source

pub fn name(&self) -> &str

source

pub fn rust_name(&self) -> String

Returns the fully qualified name that should be used by Rust code for this object. Includes r#, traits get a leading dyn. If we ever supported associated types, then this would also include them.

source

pub fn imp(&self) -> &ObjectImpl

source

pub fn is_trait_interface(&self) -> bool

source

pub fn has_callback_interface(&self) -> bool

source

pub fn has_async_method(&self) -> bool

source

pub fn constructors(&self) -> Vec<&Constructor>

source

pub fn primary_constructor(&self) -> Option<&Constructor>

source

pub fn alternate_constructors(&self) -> Vec<&Constructor>

source

pub fn methods(&self) -> Vec<&Method>

source

pub fn get_method(&self, name: &str) -> Method

source

pub fn uniffi_traits(&self) -> Vec<&UniffiTrait>

source

pub fn ffi_object_clone(&self) -> &FfiFunction

source

pub fn ffi_object_free(&self) -> &FfiFunction

source

pub fn ffi_init_callback(&self) -> &FfiFunction

source

pub fn docstring(&self) -> Option<&str>

source

pub fn iter_ffi_function_definitions( &self ) -> impl Iterator<Item = &FfiFunction>

source

pub fn derive_ffi_funcs(&mut self) -> Result<()>

source

pub fn ffi_callbacks(&self) -> Vec<FfiCallbackFunction>

For trait interfaces, FfiCallbacks to define for our methods, otherwise an empty vec.

source

pub fn vtable(&self) -> Option<FfiType>

For trait interfaces, the VTable FFI type

source

pub fn vtable_definition(&self) -> Option<FfiStruct>

For trait interfaces, the VTable struct to define. Otherwise None.

source

pub fn vtable_methods(&self) -> Vec<(FfiCallbackFunction, &Method)>

Vec of (ffi_callback_name, method) pairs

source

pub fn iter_types(&self) -> TypeIterator<'_>

Trait Implementations§

source§

impl AsType for Object

source§

fn as_type(&self) -> Type

source§

impl Checksum for Object

source§

fn checksum<__H: Hasher>(&self, state: &mut __H)

source§

impl Clone for Object

source§

fn clone(&self) -> Object

Returns a copy 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 Debug for Object

source§

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

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

impl From<ObjectMetadata> for Object

source§

fn from(meta: ObjectMetadata) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.