Using Capacitor Plugins from Rust/WASM

Christian Kjær
3 min readJun 25, 2024

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 project
  • capacitor-rs: Bridging code between the Capacitor JS library and our Rust code
  • shared: Our shared code that we might use in appy, and also want to expose in Swift to use in our Widgets or watchOS App
  • mobile: Where we will generate the Swift bindings from via UniFFI, reexporting everything from shared 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…

--

--

Christian Kjær

Founder of codetalk.io and blogging on codethoughts.io 👀 •• Rust/Serverless ❤️ Previously: Director of Eng at Famly 🌱 Built IoT platform at Factbird ☁️