Skip to content

Add widestring support and improve Rust ABI parameter handling - #185

Merged
Branden Bonaby (bbonaby) merged 8 commits into
mainfrom
update-wstring-string-codegen
Jan 28, 2026
Merged

Branden Bonaby (bbonaby) merged 8 commits into
mainfrom
update-wstring-string-codegen

Conversation

@bbonaby

@bbonaby Branden Bonaby (bbonaby) commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor

Why is this change needed?

This PR introduces initial widestring support and refines Rust ABI code generation to better align with FlatBuffers semantics and idiomatic Rust borrowing patterns.

What changed?

  • Added widestring as a workspace dependency and replaced the custom edl::WString wrapper with widestring::U16String / U16Str throughout generated Rust code.
  • Updated generated function signatures to use borrowed forms where appropriate (e.g. Option<&T>, Option<&mut T>, string slices for in parameters).
  • Introduced a shared assign_if_some helper to safely propagate optional out / inout values from ABI results.
  • Simplified and centralized Rust type generation logic for:
    • Optional<T>
    • Vec<T> vs slices for in parameters
    • Arrays
    • String and wstring handling
    • Updated generated enclave and host stubs to correctly clone, copy, or borrow values based on directionality and type.
    • Added explicit conversion implementations between ABI WStringT and widestring::U16String.
    • Updated sample code to use &str instead of &String for string inputs and U16Str instead of &edl::WString for wstring inputs.

How was this tested?

  • Confirmed both hello world, and userboundkey sample build and both run as expected without regressions.

Motivation

These changes:

  • Rust developers expect slices and string slices for [in] values rather than borrowing owned types when they won't be modifying them.
  • Reduce unnecessary allocations in generated Rust code. For [in] types in the past developers may have had to allocate an owned string (to_string() or vec type (to_vec) just to pass data to the codegen functions. Then in the codegen'd code we have to make a copy of them anyway when converting it to a flatbuffer type. Now we have one less allocation since the [in] will be a slice.
  • Make ownership and mutability explicit at the API boundary. We now only pass mutable owned types for [inout] and [out] parameters.
  • Lay the groundwork for more idiomatic and maintainable Rust codegen going forward

@bbonaby
Branden Bonaby (bbonaby) merged commit 8e9fe9e into main Jan 28, 2026
19 checks passed
@bbonaby
Branden Bonaby (bbonaby) deleted the update-wstring-string-codegen branch February 6, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants