Struct uniffi_bindgen::interface::ComponentInterface
source · 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
impl ComponentInterface
pub fn new(crate_name: &str) -> Self
sourcepub fn from_webidl(idl: &str, module_path: &str) -> Result<Self>
pub fn from_webidl(idl: &str, module_path: &str) -> Result<Self>
Parse a ComponentInterface
from a string containing a WebIDL definition.
sourcepub fn from_metadata(group: MetadataGroup) -> Result<Self>
pub fn from_metadata(group: MetadataGroup) -> Result<Self>
Create a ComponentInterface
from a MetadataGroup
Public so that external binding generators can use it.
sourcepub fn add_metadata(&mut self, group: MetadataGroup) -> Result<()>
pub fn add_metadata(&mut self, group: MetadataGroup) -> Result<()>
Add a metadata group to a ComponentInterface
.
sourcepub fn namespace(&self) -> &str
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.
pub fn namespace_docstring(&self) -> Option<&str>
pub fn uniffi_contract_version(&self) -> u32
sourcepub fn enum_definitions(&self) -> impl Iterator<Item = &Enum>
pub fn enum_definitions(&self) -> impl Iterator<Item = &Enum>
Get the definitions for every Enum type in the interface.
sourcepub fn get_enum_definition(&self, name: &str) -> Option<&Enum>
pub fn get_enum_definition(&self, name: &str) -> Option<&Enum>
Get an Enum definition by name, or None if no such Enum is defined.
sourcepub fn record_definitions(&self) -> impl Iterator<Item = &Record>
pub fn record_definitions(&self) -> impl Iterator<Item = &Record>
Get the definitions for every Record type in the interface.
sourcepub fn get_record_definition(&self, name: &str) -> Option<&Record>
pub fn get_record_definition(&self, name: &str) -> Option<&Record>
Get a Record definition by name, or None if no such Record is defined.
sourcepub fn function_definitions(&self) -> &[Function]
pub fn function_definitions(&self) -> &[Function]
Get the definitions for every Function in the interface.
sourcepub fn get_function_definition(&self, name: &str) -> Option<&Function>
pub fn get_function_definition(&self, name: &str) -> Option<&Function>
Get a Function definition by name, or None if no such Function is defined.
sourcepub fn object_definitions(&self) -> &[Object]
pub fn object_definitions(&self) -> &[Object]
Get the definitions for every Object type in the interface.
sourcepub fn get_object_definition(&self, name: &str) -> Option<&Object>
pub fn get_object_definition(&self, name: &str) -> Option<&Object>
Get an Object definition by name, or None if no such Object is defined.
fn callback_interface_callback_definitions( &self ) -> impl IntoIterator<Item = FfiCallbackFunction> + '_
sourcefn callback_interface_vtable_definitions(
&self
) -> impl IntoIterator<Item = FfiStruct> + '_
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.
sourcepub fn callback_interface_definitions(&self) -> &[CallbackInterface]
pub fn callback_interface_definitions(&self) -> &[CallbackInterface]
Get the definitions for every Callback Interface type in the interface.
sourcepub fn get_callback_interface_definition(
&self,
name: &str
) -> Option<&CallbackInterface>
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.
sourcepub fn has_async_callback_interface_definition(&self) -> bool
pub fn has_async_callback_interface_definition(&self) -> bool
Get the definitions for every Callback Interface type in the interface.
sourcepub fn iter_callables(&self) -> impl Iterator<Item = &dyn Callable>
pub fn iter_callables(&self) -> impl Iterator<Item = &dyn Callable>
Get the definitions for every Method type in the interface.
sourcepub fn should_generate_error_read(&self, e: &Enum) -> bool
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.
sourcepub fn iter_external_types(
&self
) -> impl Iterator<Item = (&String, String, ExternalKind, bool)>
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)
sourcepub fn iter_custom_types(&self) -> impl Iterator<Item = (&String, &Type)>
pub fn iter_custom_types(&self) -> impl Iterator<Item = (&String, &Type)>
Get details about all Type::Custom
types
sourcepub fn iter_types(&self) -> impl Iterator<Item = &Type>
pub fn iter_types(&self) -> impl Iterator<Item = &Type>
Iterate over all known types in the interface.
sourcefn iter_types_in_item<'a>(
&'a self,
item: &'a Type
) -> impl Iterator<Item = &'a Type> + 'a
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.
sourcepub fn item_contains_object_references(&self, item: &Type) -> bool
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.
sourcepub fn item_contains_unsigned_types(&self, item: &Type) -> bool
pub fn item_contains_unsigned_types(&self, item: &Type) -> bool
Check whether the given item contains any (possibly nested) unsigned types
sourcepub fn contains_optional_types(&self) -> bool
pub fn contains_optional_types(&self) -> bool
Check whether the interface contains any optional types
sourcepub fn contains_sequence_types(&self) -> bool
pub fn contains_sequence_types(&self) -> bool
Check whether the interface contains any sequence types
sourcepub fn contains_map_types(&self) -> bool
pub fn contains_map_types(&self) -> bool
Check whether the interface contains any map types
sourcepub fn contains_object_types(&self) -> bool
pub fn contains_object_types(&self) -> bool
Check whether the interface contains any object types
fn ffi_namespace(&self) -> &str
sourcepub fn ffi_uniffi_contract_version(&self) -> FfiFunction
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
sourcepub fn ffi_rustbuffer_alloc(&self) -> FfiFunction
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.
sourcepub fn ffi_rustbuffer_from_bytes(&self) -> FfiFunction
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.
sourcepub fn ffi_rustbuffer_free(&self) -> FfiFunction
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.
sourcepub fn ffi_rustbuffer_reserve(&self) -> FfiFunction
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.
sourcepub fn ffi_rust_future_poll(
&self,
return_ffi_type: Option<FfiType>
) -> FfiFunction
pub fn ffi_rust_future_poll( &self, return_ffi_type: Option<FfiType> ) -> FfiFunction
Builtin FFI function to poll a Rust future.
sourcepub fn ffi_rust_future_complete(
&self,
return_ffi_type: Option<FfiType>
) -> FfiFunction
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.
sourcepub fn ffi_rust_future_cancel(
&self,
return_ffi_type: Option<FfiType>
) -> FfiFunction
pub fn ffi_rust_future_cancel( &self, return_ffi_type: Option<FfiType> ) -> FfiFunction
Builtin FFI function for cancelling a Rust Future
sourcepub fn ffi_rust_future_free(
&self,
return_ffi_type: Option<FfiType>
) -> FfiFunction
pub fn ffi_rust_future_free( &self, return_ffi_type: Option<FfiType> ) -> FfiFunction
Builtin FFI function for freeing a Rust Future
fn rust_future_ffi_fn_name( &self, base_name: &str, return_ffi_type: Option<FfiType> ) -> String
sourcepub fn has_async_fns(&self) -> bool
pub fn has_async_fns(&self) -> bool
Does this interface contain async functions?
sourcepub fn iter_future_callback_params(&self) -> impl Iterator<Item = FfiType>
pub fn iter_future_callback_params(&self) -> impl Iterator<Item = FfiType>
Iterate over T
parameters of the FutureCallback<T>
callbacks in this interface
sourcepub fn iter_async_result_types(&self) -> impl Iterator<Item = ResultType>
pub fn iter_async_result_types(&self) -> impl Iterator<Item = ResultType>
Iterate over return/throws types for async functions
sourcepub fn ffi_definitions(&self) -> impl Iterator<Item = FfiDefinition> + '_
pub fn ffi_definitions(&self) -> impl Iterator<Item = FfiDefinition> + '_
Iterate over all Ffi definitions
fn builtin_ffi_definitions( &self ) -> impl IntoIterator<Item = FfiDefinition> + '_
sourcepub fn iter_ffi_function_definitions(
&self
) -> impl Iterator<Item = FfiFunction> + '_
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.
sourcepub fn iter_ffi_function_definitions_non_async(
&self
) -> impl Iterator<Item = FfiFunction> + '_
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
sourcepub fn iter_user_ffi_function_definitions(
&self
) -> impl Iterator<Item = &FfiFunction> + '_
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
sourcepub fn iter_rust_buffer_ffi_function_definitions(
&self
) -> impl Iterator<Item = FfiFunction>
pub fn iter_rust_buffer_ffi_function_definitions( &self ) -> impl Iterator<Item = FfiFunction>
List all FFI functions definitions for RustBuffer functionality.
fn all_possible_return_ffi_types(&self) -> impl Iterator<Item = Option<FfiType>>
sourcepub fn iter_futures_ffi_function_definitions(
&self
) -> impl Iterator<Item = FfiFunction> + '_
pub fn iter_futures_ffi_function_definitions( &self ) -> impl Iterator<Item = FfiFunction> + '_
List all FFI functions definitions for async functionality.
sourcepub fn iter_checksums(&self) -> impl Iterator<Item = (String, u16)> + '_
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
pub fn iter_checksum_ffi_functions( &self ) -> impl Iterator<Item = FfiFunction> + '_
sourcepub(crate) fn add_enum_definition(&mut self, defn: Enum) -> Result<()>
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
.
sourcepub(crate) fn add_record_definition(&mut self, defn: Record) -> Result<()>
pub(crate) fn add_record_definition(&mut self, defn: Record) -> Result<()>
Adds a newly-parsed record definition to the ComponentInterface
.
sourcepub(crate) fn add_function_definition(&mut self, defn: Function) -> Result<()>
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
.
pub(crate) fn add_constructor_meta( &mut self, meta: ConstructorMetadata ) -> Result<()>
pub(crate) fn add_method_meta(&mut self, meta: impl Into<Method>) -> Result<()>
pub(crate) fn add_uniffitrait_meta( &mut self, meta: UniffiTraitMetadata ) -> Result<()>
pub(crate) fn add_object_meta(&mut self, meta: ObjectMetadata) -> Result<()>
sourcefn add_object_definition(&mut self, defn: Object) -> Result<()>
fn add_object_definition(&mut self, defn: Object) -> Result<()>
Called by APIBuilder
impls to add a newly-parsed object definition to the ComponentInterface
.
pub fn is_name_used_as_error(&self, name: &str) -> bool
sourcepub(crate) fn add_callback_interface_definition(
&mut self,
defn: CallbackInterface
)
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
.
pub(crate) fn add_trait_method_meta( &mut self, meta: TraitMethodMetadata ) -> Result<()>
sourcepub fn check_consistency(&self) -> Result<()>
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.
sourcepub fn derive_ffi_funcs(&mut self) -> Result<()>
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.