Struct uniffi_macros::fnsig::FnSignature
source · pub(crate) struct FnSignature {
pub kind: FnKind,
pub span: Span,
pub mod_path: String,
pub ident: Ident,
pub name: String,
pub is_async: bool,
pub receiver: Option<ReceiverArg>,
pub args: Vec<NamedArg>,
pub return_ty: TokenStream,
pub looks_like_result: bool,
pub docstring: String,
}
Fields§
§kind: FnKind
§span: Span
§mod_path: String
§ident: Ident
§name: String
§is_async: bool
§receiver: Option<ReceiverArg>
§args: Vec<NamedArg>
§return_ty: TokenStream
§looks_like_result: bool
§docstring: String
Implementations§
source§impl FnSignature
impl FnSignature
pub(crate) fn new_function( sig: Signature, args: ExportFnArgs, docstring: String ) -> Result<Self>
pub(crate) fn new_method( self_ident: Ident, sig: Signature, args: ExportedImplFnArgs, docstring: String ) -> Result<Self>
pub(crate) fn new_constructor( self_ident: Ident, sig: Signature, args: ExportedImplFnArgs, docstring: String ) -> Result<Self>
pub(crate) fn new_trait_method( self_ident: Ident, sig: Signature, args: ExportedImplFnArgs, index: u32, docstring: String ) -> Result<Self>
pub(crate) fn new( kind: FnKind, sig: Signature, name: Option<String>, defaults: DefaultMap, docstring: String ) -> Result<Self>
pub fn lower_return_impl(&self) -> TokenStream
pub fn lift_return_impl(&self) -> TokenStream
sourcepub fn lift_closure(&self, self_lift: Option<TokenStream>) -> TokenStream
pub fn lift_closure(&self, self_lift: Option<TokenStream>) -> TokenStream
Generate a closure that tries to lift all arguments into a tuple.
The closure moves all scaffolding arguments into itself and returns:
- The lifted argument tuple on success
- The field name and error on failure (
Err(&'static str, anyhow::Error>
)
sourcepub fn rust_call_params(&self, self_lift: bool) -> TokenStream
pub fn rust_call_params(&self, self_lift: bool) -> TokenStream
Call a Rust function from a Self::lift_closure success.
This takes an Ok value returned by lift_closure
with the name uniffi_args
and generates
a series of parameters to pass to the Rust function.
sourcepub fn params(&self) -> impl Iterator<Item = TokenStream> + '_
pub fn params(&self) -> impl Iterator<Item = TokenStream> + '_
Parameters expressions for each of our arguments
sourcepub fn scaffolding_fn_ident(&self) -> Result<Ident>
pub fn scaffolding_fn_ident(&self) -> Result<Ident>
Name of the scaffolding function to generate for this function
sourcepub fn scaffolding_param_names(&self) -> impl Iterator<Item = TokenStream> + '_
pub fn scaffolding_param_names(&self) -> impl Iterator<Item = TokenStream> + '_
Scaffolding parameters expressions for each of our arguments
pub fn scaffolding_param_types(&self) -> impl Iterator<Item = TokenStream> + '_
sourcepub(crate) fn metadata_expr(&self) -> Result<TokenStream>
pub(crate) fn metadata_expr(&self) -> Result<TokenStream>
Generate metadata items for this function
pub(crate) fn metadata_items(&self) -> Result<TokenStream>
sourcepub(crate) fn metadata_items_for_callback_interface(
&self
) -> Result<TokenStream>
pub(crate) fn metadata_items_for_callback_interface( &self ) -> Result<TokenStream>
Generate metadata items for callback interfaces
Unfortunately, most of this is duplicate code from Self::metadata_items and
Self::metadata_expr. However, one issue with that code is that it needs to assume if the
arguments are being lifted vs lowered in order to get TYPE_ID_META. That code uses
<Type as Lift>::TYPE_ID_META
for arguments and <Type as LowerReturn>::TYPE_ID_META
for
return types, which works for accidental/historical reasons.
The one exception is callback interfaces (#1947), which are handled by this method.
TODO: fix the metadata system so that this is not needed.