Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert bound UUIDs to Swift and Kotlin types #131

Closed
ianthetechie opened this issue Jul 3, 2024 · 1 comment · Fixed by #251
Closed

Convert bound UUIDs to Swift and Kotlin types #131

ianthetechie opened this issue Jul 3, 2024 · 1 comment · Fixed by #251
Assignees
Labels
android core Related to the Rust core iOS

Comments

@ianthetechie
Copy link
Contributor

ianthetechie commented Jul 3, 2024

Can you spot the issue with this code? It compiles, but will panic when you try to pass the type off to a Rust function at runtime.

FerrostarCoreFFI.SpokenInstruction(text: text,
                                   ssml: ssmlText,
                                   triggerDistanceBeforeManeuver: distanceAlongStep,
                                   utteranceId: Uuid())

Stumped? Well, Uuid isn't the same as UUID, the Swift Foundation class which generates UUIDs. It's a typealias to String, because that's how we serialize UUIDs over the FFI.

The result is that it's trivial to think you've got correct code, since it does indeed compile, but get a strange Rust panic at runtime. The panic looks like this by the way, which makes it sound like a UniFFI error, but it's really a non-obvious error message from the uuid crate.

Failed to convert arg 'route': invalid length: expected length 32 for simple format, found 0
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: uniffi_core::ffi_converter_impls::<impl uniffi_core::ffi_converter_traits::LowerReturn<UT> for core::result::Result<R,E>>::handle_failed_lift
   3: std::panicking::try
   4: uniffi_core::ffi::rustcalls::rust_call_with_out_status
   5: uniffi_core::ffi::rustcalls::rust_call
   6: _uniffi_ferrostar_fn_func_location_simulation_from_route
  <user code>

I think we can fix this now by telling UniFFI to convert these to a native type. See https://mozilla.github.io/uniffi-rs/latest/udl/custom_types.html#custom-types-in-the-bindings-code for details on how to accomplish this.

In the meantime, if anyone stumbles across this, here's the correct way to write this:

FerrostarCoreFFI.SpokenInstruction(text: text,
                                   ssml: ssmlText,
                                   triggerDistanceBeforeManeuver: distanceAlongStep,
-                                   utteranceId: Uuid())
+                                   utteranceId: UUID().uuidString)
@ianthetechie ianthetechie added android iOS core Related to the Rust core labels Jul 3, 2024
@ianthetechie ianthetechie self-assigned this Jul 3, 2024
@ianthetechie
Copy link
Contributor Author

We may also, incidentally, be able to use something better than strings to pass it back at forth 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android core Related to the Rust core iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant