Module crux_core::typegen

source ·
Expand description

Generation of foreign language types (currently Swift, Java, TypeScript) for Crux

In order to use this module, you’ll need a separate crate from your shared library, possibly called shared_types. This is necessary because we need to reference types from your shared library during the build process (

This module is behind the feature called typegen, and is not compiled into the default crate.

Ensure that you have the following line in the Cargo.toml of your shared_types library.

crux_core = { version = "0.6", features = ["typegen"] }
  • Your shared_types library, will have an empty, since we only use it for generating foreign language type declarations.
  • Create a in your shared_types library, that looks something like this:
use shared::{App, EffectFfi, Event};
use crux_core::{bridge::Request, typegen::TypeGen};
use uuid::Uuid;

fn generate_types() {
   let mut gen = TypeGen::new();

   let sample_events = vec![Event::SendUuid(Uuid::new_v4())];


   let temp = assert_fs::TempDir::new().unwrap();
   let output_root = temp.join("crux_core_typegen_test");

   gen.swift("SharedTypes", output_root.join("swift"))
       .expect("swift type gen failed");"com.example.counter.shared_types", output_root.join("java"))
       .expect("java type gen failed");

   gen.typescript("shared_types", output_root.join("typescript"))
       .expect("typescript type gen failed");


  • The TypeGen struct stores the registered types so that they can be generated for foreign languages use TypeGen::new() to create an instance



Type Aliases