From 74b0cab9b534d3ac20f57cf1cd14487bd9d2b5a1 Mon Sep 17 00:00:00 2001 From: imWildCat Date: Sat, 21 Oct 2023 06:16:07 -0400 Subject: [PATCH] use record exported types --- .../apple/HelloAppleDemoApp/ViewController.swift | 10 ++++------ hello/src/lib.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hello/platforms/apple/HelloAppleDemoApp/ViewController.swift b/hello/platforms/apple/HelloAppleDemoApp/ViewController.swift index 7e842bd..b6fe832 100644 --- a/hello/platforms/apple/HelloAppleDemoApp/ViewController.swift +++ b/hello/platforms/apple/HelloAppleDemoApp/ViewController.swift @@ -1,20 +1,18 @@ -// - -import UIKit import Hello +import UIKit class ViewController: UIViewController { - override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. print(rustGreeting(to: "Bob")) print(Hello.add(a: 1, b: 2)) - + Task { let str = await Hello.sayAfter(ms: 1500, who: "Async") print(str) } + + print(Hello.addObj(a: RustDemoObj(value: 1), b: RustDemoObj(value: 2))) } } - diff --git a/hello/src/lib.rs b/hello/src/lib.rs index da7a742..6325983 100644 --- a/hello/src/lib.rs +++ b/hello/src/lib.rs @@ -57,3 +57,15 @@ pub async fn say_after(ms: u64, who: String) -> String { .unwrap_err(); format!("Hello, {who}!") } + +#[derive(uniffi::Record)] +pub struct RustDemoObj { + pub value: i64, +} + +#[uniffi::export] +pub fn add_obj(a: &RustDemoObj, b: &RustDemoObj) -> RustDemoObj { + RustDemoObj { + value: a.value + b.value, + } +}