Skip to main content

1. Simple

Simple Rust...

fn f(a: String, b: Vec<String>) -> MyStruct { ... }

...called from Dart, without manual intervention.

print(f(a: 'Hello', b: ['World']));

2. Fancy

Let's see how fancy we can support:

//  Arbitrarily fancy Rust types
struct Garden { land: whatever::fancy::Land }

//  Complex but auto-translatable
enum Tree { A { name: (String, i32), children: Option<Vec<Tree>> }, B }

//  Support functions & methods
impl Garden {
    //  Allow async & sync Rust
    async fn plant(
        //  Support T/&T/&mut T
        &mut self,
        tree: Tree,
        //  Rust can also call Dart
        chooser: impl Fn(String) -> bool,
        //  Error translation ; zero copy
    ) -> Result<Vec<u8>, FancyError> {
        ...
    }
}

Still seamlessly call in Dart:

var tree = Tree.a(('x', 42), [Tree.b()]);
//  Async & sync Dart
print(await garden.plant(tree, (a) => true));