Struct uniffi_bindgen::interface::Object
source · 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
impl Object
pub fn name(&self) -> &str
sourcepub fn rust_name(&self) -> String
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.
pub fn imp(&self) -> &ObjectImpl
pub fn is_trait_interface(&self) -> bool
pub fn has_callback_interface(&self) -> bool
pub fn has_async_method(&self) -> bool
pub fn constructors(&self) -> Vec<&Constructor>
pub fn primary_constructor(&self) -> Option<&Constructor>
pub fn alternate_constructors(&self) -> Vec<&Constructor>
pub fn methods(&self) -> Vec<&Method>
pub fn get_method(&self, name: &str) -> Method
pub fn uniffi_traits(&self) -> Vec<&UniffiTrait>
pub fn ffi_object_clone(&self) -> &FfiFunction
pub fn ffi_object_free(&self) -> &FfiFunction
pub fn ffi_init_callback(&self) -> &FfiFunction
pub fn docstring(&self) -> Option<&str>
pub fn iter_ffi_function_definitions( &self ) -> impl Iterator<Item = &FfiFunction>
pub fn derive_ffi_funcs(&mut self) -> Result<()>
sourcepub fn ffi_callbacks(&self) -> Vec<FfiCallbackFunction>
pub fn ffi_callbacks(&self) -> Vec<FfiCallbackFunction>
For trait interfaces, FfiCallbacks to define for our methods, otherwise an empty vec.
sourcepub fn vtable_definition(&self) -> Option<FfiStruct>
pub fn vtable_definition(&self) -> Option<FfiStruct>
For trait interfaces, the VTable struct to define. Otherwise None.
sourcepub fn vtable_methods(&self) -> Vec<(FfiCallbackFunction, &Method)>
pub fn vtable_methods(&self) -> Vec<(FfiCallbackFunction, &Method)>
Vec of (ffi_callback_name, method) pairs