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

Support returning owned slices (at least backend-optionally) #786

Open
Manishearth opened this issue Feb 13, 2025 · 2 comments
Open

Support returning owned slices (at least backend-optionally) #786

Manishearth opened this issue Feb 13, 2025 · 2 comments
Labels
A-type-system Area: Additions and improvements to the types Diplomat supports

Comments

@Manishearth
Copy link
Contributor

Currently we support returning borrowed slices, which in non-shared-heap backends (Java, Dart, JS, Kotlin) introduce a conversion to their native heap array type.

This works great, except sometimes you just have owned data. We should support returning Box<[u8]> and friends, which converts in non-shared-heap backends, and in shared-heap backends (C++) is either unsupported, also converts, or returns a diplomat-runtime type.

Related potential question: Should diplomat support returning native Rust heap types?

Generally Diplomat tries not to provide target-language wrappers, we provide diplomat::span in C++ as a compatability thing but what we don't do is have an entire library of diplomat specific types that wrap Rust types passed over FFI. Libraries like crubit do this and they should, Diplomat's general attitude here is that if you want such a type you should make your own with exactly the APIs you need.

So, no, unless we can make it a backend attribute transform.

@Manishearth
Copy link
Contributor Author

cc @emarteca @maurer @mgeisler This would help get rid of RustOwnedBytes in your code.

@Manishearth Manishearth added the A-type-system Area: Additions and improvements to the types Diplomat supports label Feb 13, 2025
@Manishearth
Copy link
Contributor Author

Note: when implementing this we may need to take care to ensure that returned owned vs static things are handled differently, see #798 for a similar bugfix in Dart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Additions and improvements to the types Diplomat supports
Projects
None yet
Development

No branches or pull requests

1 participant