Member-only story
Using Capacitor Plugins from Rust/WASM
Not a Medium member? Read the post here for free.
This is a part of the post:
Capacitor is normally used in combination with JavaScript projects, so there is little help available if you want to use it in a Rust/WASM project. Worry not! That’s exactly what we’ll take a look at in this post.
Since Capacitor is a JS framework there will be a little extra work involved in interacting with any plugins, but it’s honestly not a lot we need to do. Let’s take a quick tour through what I’ve set up in the example repository https://github.com/Tehnix/template-mobile-wasm.
We’ve set up four crates:
appy
: Our Leptos App, Capacitor, and the XCode projectcapacitor-rs
: Bridging code between the Capacitor JS library and our Rust codeshared
: Our shared code that we might use inappy
, and also want to expose in Swift to use in our Widgets or watchOS Appmobile
: Where we will generate the Swift bindings from via UniFFI, reexporting everything fromshared
that’s made available to UniFFI via the macros
In this post we’ll focus on the capacitor-rs
and appy
crates, which contain our Capacitor bridge…