pub struct ComponentInterface {
    pub(crate) types: TypeUniverse,
    enums: BTreeMap<String, Enum>,
    records: BTreeMap<String, Record>,
    functions: Vec<Function>,
    objects: Vec<Object>,
    callback_interfaces: Vec<CallbackInterface>,
    errors: HashSet<String>,
    callback_interface_throws_types: BTreeSet<Type>,
}
Expand description

The main public interface for this module, representing the complete details of an interface exposed by a rust component and the details of consuming it via an extern-C FFI layer.

Fields§

§types: TypeUniverse

All of the types used in the interface.

§enums: BTreeMap<String, Enum>

The high-level API provided by the component.

§records: BTreeMap<String, Record>§functions: Vec<Function>§objects: Vec<Object>§callback_interfaces: Vec<CallbackInterface>§errors: HashSet<String>§callback_interface_throws_types: BTreeSet<Type>

Implementations§

source§

impl ComponentInterface

source

pub fn new(crate_name: &str) -> Self

source

pub fn from_webidl(idl: &str, module_path: &str) -> Result<Self>

Parse a ComponentInterface from a string containing a WebIDL definition.

source

pub fn from_metadata(group: MetadataGroup) -> Result<Self>

Create a ComponentInterface from a MetadataGroup Public so that external binding generators can use it.

source

pub fn add_metadata(&mut self, group: MetadataGroup) -> Result<()>

Add a metadata group to a ComponentInterface.

source

pub fn namespace(&self) -> &str

The string namespace within which this API should be presented to the caller.

This string would typically be used to prefix function names in the FFI, to build a package or module name for the foreign language, etc.

source

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

source

pub fn uniffi_contract_version(&self) -> u32

source

pub fn enum_definitions(&self) -> impl Iterator<Item = &Enum>

Get the definitions for every Enum type in the interface.

source

pub fn get_enum_definition(&self, name: &str) -> Option<&Enum>

Get an Enum definition by name, or None if no such Enum is defined.

source

pub fn record_definitions(&self) -> impl Iterator<Item = &Record>

Get the definitions for every Record type in the interface.

source

pub fn get_record_definition(&self, name: &str) -> Option<&Record>

Get a Record definition by name, or None if no such Record is defined.

source

pub fn function_definitions(&self) -> &[Function]

Get the definitions for every Function in the interface.

source

pub fn get_function_definition(&self, name: &str) -> Option<&Function>

Get a Function definition by name, or None if no such Function is defined.

source

pub fn object_definitions(&self) -> &[Object]

Get the definitions for every Object type in the interface.

source

pub fn get_object_definition(&self, name: &str) -> Option<&Object>

Get an Object definition by name, or None if no such Object is defined.

source

fn callback_interface_callback_definitions( &self ) -> impl IntoIterator<Item = FfiCallbackFunction> + '_

source

fn callback_interface_vtable_definitions( &self ) -> impl IntoIterator<Item = FfiStruct> + '_

Get the definitions for callback FFI functions

These are defined by the foreign code and invoked by Rust.

source

pub fn callback_interface_definitions(&self) -> &[CallbackInterface]

Get the definitions for every Callback Interface type in the interface.

source

pub fn get_callback_interface_definition( &self, name: &str ) -> Option<&CallbackInterface>

Get a Callback interface definition by name, or None if no such interface is defined.

source

pub fn has_async_callback_interface_definition(&self) -> bool

Get the definitions for every Callback Interface type in the interface.

source

pub fn iter_callables(&self) -> impl Iterator<Item = &dyn Callable>

Get the definitions for every Method type in the interface.

source

pub fn should_generate_error_read(&self, e: &Enum) -> bool

Should we generate read (and lift) functions for errors?

This is a workaround for the fact that lower/write can’t be generated for some errors, specifically errors that are defined as flat in the UDL, but actually have fields in the Rust source.

source

pub fn iter_external_types( &self ) -> impl Iterator<Item = (&String, String, ExternalKind, bool)>

Get details about all Type::External types. Returns an iterator of (name, crate_name, kind)

source

pub fn iter_custom_types(&self) -> impl Iterator<Item = (&String, &Type)>

Get details about all Type::Custom types

source

pub fn iter_types(&self) -> impl Iterator<Item = &Type>

Iterate over all known types in the interface.

source

pub fn get_type(&self, name: &str) -> Option<Type>

Get a specific type

source

fn iter_types_in_item<'a>( &'a self, item: &'a Type ) -> impl Iterator<Item = &'a Type> + 'a

Iterate over all types contained in the given item.

This method uses iter_types to iterate over the types contained within the given type, but additionally recurses into the definition of user-defined types like records and enums to yield the types that they contain.

source

pub fn item_contains_object_references(&self, item: &Type) -> bool

Check whether the given item contains any (possibly nested) Type::Object references.

This is important to know in language bindings that cannot integrate object types tightly with the host GC, and hence need to perform manual destruction of objects.

source

pub fn item_contains_unsigned_types(&self, item: &Type) -> bool

Check whether the given item contains any (possibly nested) unsigned types

source

pub fn contains_optional_types(&self) -> bool

Check whether the interface contains any optional types

source

pub fn contains_sequence_types(&self) -> bool

Check whether the interface contains any sequence types

source

pub fn contains_map_types(&self) -> bool

Check whether the interface contains any map types

source

pub fn contains_object_types(&self) -> bool

Check whether the interface contains any object types

source

fn ffi_namespace(&self) -> &str

source

pub fn ffi_uniffi_contract_version(&self) -> FfiFunction

Builtin FFI function to get the current contract version This is needed so that the foreign language bindings can check that they are using the same ABI as the scaffolding

source

pub fn ffi_rustbuffer_alloc(&self) -> FfiFunction

Builtin FFI function for allocating a new RustBuffer. This is needed so that the foreign language bindings can create buffers in which to pass complex data types across the FFI.

source

pub fn ffi_rustbuffer_from_bytes(&self) -> FfiFunction

Builtin FFI function for copying foreign-owned bytes This is needed so that the foreign language bindings can create buffers in which to pass complex data types across the FFI.

source

pub fn ffi_rustbuffer_free(&self) -> FfiFunction

Builtin FFI function for freeing a RustBuffer. This is needed so that the foreign language bindings can free buffers in which they received complex data types returned across the FFI.

source

pub fn ffi_rustbuffer_reserve(&self) -> FfiFunction

Builtin FFI function for reserving extra space in a RustBuffer. This is needed so that the foreign language bindings can grow buffers used for passing complex data types across the FFI.

source

pub fn ffi_rust_future_poll( &self, return_ffi_type: Option<FfiType> ) -> FfiFunction

Builtin FFI function to poll a Rust future.

source

pub fn ffi_rust_future_complete( &self, return_ffi_type: Option<FfiType> ) -> FfiFunction

Builtin FFI function to complete a Rust future and get it’s result.

We generate one of these for each FFI return type.

source

pub fn ffi_rust_future_cancel( &self, return_ffi_type: Option<FfiType> ) -> FfiFunction

Builtin FFI function for cancelling a Rust Future

source

pub fn ffi_rust_future_free( &self, return_ffi_type: Option<FfiType> ) -> FfiFunction

Builtin FFI function for freeing a Rust Future

source

fn rust_future_ffi_fn_name( &self, base_name: &str, return_ffi_type: Option<FfiType> ) -> String

source

pub fn has_async_fns(&self) -> bool

Does this interface contain async functions?

source

pub fn iter_future_callback_params(&self) -> impl Iterator<Item = FfiType>

Iterate over T parameters of the FutureCallback<T> callbacks in this interface

source

pub fn iter_async_result_types(&self) -> impl Iterator<Item = ResultType>

Iterate over return/throws types for async functions

source

pub fn ffi_definitions(&self) -> impl Iterator<Item = FfiDefinition> + '_

Iterate over all Ffi definitions

source

fn builtin_ffi_definitions( &self ) -> impl IntoIterator<Item = FfiDefinition> + '_

source

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

List the definitions of all FFI functions in the interface.

The set of FFI functions is derived automatically from the set of higher-level types along with the builtin FFI helper functions.

source

pub fn iter_ffi_function_definitions_non_async( &self ) -> impl Iterator<Item = FfiFunction> + '_

Alternate version of iter_ffi_function_definitions for languages that don’t support async

source

pub fn iter_user_ffi_function_definitions( &self ) -> impl Iterator<Item = &FfiFunction> + '_

List all FFI functions definitions for user-defined interfaces

This includes FFI functions for:

  • Top-level functions
  • Object methods
  • Callback interfaces
source

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

List all FFI functions definitions for RustBuffer functionality.

source

fn all_possible_return_ffi_types(&self) -> impl Iterator<Item = Option<FfiType>>

source

pub fn iter_futures_ffi_function_definitions( &self ) -> impl Iterator<Item = FfiFunction> + '_

List all FFI functions definitions for async functionality.

source

pub fn iter_checksums(&self) -> impl Iterator<Item = (String, u16)> + '_

List all API checksums to check

Returns a list of (export_symbol_name, checksum) items

source

pub fn iter_checksum_ffi_functions( &self ) -> impl Iterator<Item = FfiFunction> + '_

source

pub(crate) fn add_enum_definition(&mut self, defn: Enum) -> Result<()>

Called by APIBuilder impls to add a newly-parsed enum definition to the ComponentInterface.

source

pub(crate) fn add_record_definition(&mut self, defn: Record) -> Result<()>

Adds a newly-parsed record definition to the ComponentInterface.

source

pub(crate) fn add_function_definition(&mut self, defn: Function) -> Result<()>

Called by APIBuilder impls to add a newly-parsed function definition to the ComponentInterface.

source

pub(crate) fn add_constructor_meta( &mut self, meta: ConstructorMetadata ) -> Result<()>

source

pub(crate) fn add_method_meta(&mut self, meta: impl Into<Method>) -> Result<()>

source

pub(crate) fn add_uniffitrait_meta( &mut self, meta: UniffiTraitMetadata ) -> Result<()>

source

pub(crate) fn add_object_meta(&mut self, meta: ObjectMetadata) -> Result<()>

source

fn add_object_definition(&mut self, defn: Object) -> Result<()>

Called by APIBuilder impls to add a newly-parsed object definition to the ComponentInterface.

source

pub fn is_name_used_as_error(&self, name: &str) -> bool

source

pub(crate) fn add_callback_interface_definition( &mut self, defn: CallbackInterface )

Called by APIBuilder impls to add a newly-parsed callback interface definition to the ComponentInterface.

source

pub(crate) fn add_trait_method_meta( &mut self, meta: TraitMethodMetadata ) -> Result<()>

source

pub fn check_consistency(&self) -> Result<()>

Perform global consistency checks on the declared interface.

This method checks for consistency problems in the declared interface as a whole, and which can only be detected after we’ve finished defining the entire interface.

source

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

Automatically derive the low-level FFI functions from the high-level types in the interface.

This should only be called after the high-level types have been completed defined, otherwise the resulting set will be missing some entries.

Trait Implementations§

source§

impl Debug for ComponentInterface

source§

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

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

impl Default for ComponentInterface

source§

fn default() -> ComponentInterface

Returns the “default value” for a type. Read more

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