/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use proc_macro2::TokenStream; use quote::{quote, quote_spanned}; use syn::{visit_mut::VisitMut, Item, Type};
mod attributes; mod callback_interface; mod item; mod scaffolding; mod trait_interface; mod utrait;
// TODO(jplatte): Ensure no generics, … // TODO(jplatte): Aggregate errors instead of short-circuiting, wherever possible
pub(crate) fn expand_export( mut item: Item,
all_args: proc_macro::TokenStream,
udl_mode: bool,
) -> syn::Result<TokenStream> { let mod_path = mod_path()?; // If the input is an `impl` block, rewrite any uses of the `Self` type // alias to the actual type, so we don't have to special-case it in the // metadata collection or scaffolding code generation (which generates // new functions outside of the `impl`).
rewrite_self_type(&mut item);
// trying to split `udl_mode` into "no meta" and "other" let include_meta = !udl_mode;
/// Rewrite Self type alias usage in an impl block to the type itself. /// /// For example, /// /// ```ignore /// impl some::module::Foo { /// fn method( /// self: Arc<Self>, /// arg: Option<Bar<(), Self>>, /// ) -> Result<Self, Error> { /// todo!() /// } /// } /// ``` /// /// will be rewritten to /// /// ```ignore /// impl some::module::Foo { /// fn method( /// self: Arc<some::module::Foo>, /// arg: Option<Bar<(), some::module::Foo>>, /// ) -> Result<some::module::Foo, Error> { /// todo!() /// } /// } /// ``` pubfn rewrite_self_type(item: &mut Item) { let item = match item {
Item::Impl(i) => i,
_ => return,
};
struct RewriteSelfVisitor<'a>(&'a Type);
impl VisitMut for RewriteSelfVisitor<'_> { fn visit_type_mut(&mutself, i: &mutType) { match i { Type::Path(p) if p.qself.is_none() && p.path.is_ident("Self") => {
*i = self.0.clone();
}
_ => syn::visit_mut::visit_type_mut(self, i),
}
}
}
letmut visitor = RewriteSelfVisitor(&item.self_ty); for item in &mut item.items {
visitor.visit_impl_item_mut(item);
}
}
/// Alter the tokens wrapped with the `[uniffi::export]` if needed pubfn alter_input(item: &Item) -> TokenStream { match item {
Item::Trait(item_trait) => alter_trait(item_trait),
_ => quote! { #item },
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-08-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.