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 RustString's + operator #224

Open
NiwakaDev opened this issue May 6, 2023 · 1 comment
Open

Support RustString's + operator #224

NiwakaDev opened this issue May 6, 2023 · 1 comment

Comments

@NiwakaDev
Copy link
Collaborator

NiwakaDev commented May 6, 2023

Something like:

#[swift_bridge::bridge]
mod ffi {
   extern "Rust" {
      fn create_string() -> String;
   }
}
//Swift
let value = create_string() + create_string()

Right now, we need to call toString from each create_string() and then can use String's + operator, like so:

//Swift
let value = create_string().toString() + create_string().toString()

But, I guess that it is inefficient to call toString corresponding to each create_string.

@NiwakaDev NiwakaDev changed the title Support RustString's + operator function Support RustString's + operator May 6, 2023
@chinedufn
Copy link
Owner

Whether or not we should support RustString + RustString comes down to whether or not we expect people to understand that this will cause an allocation.

I think that it's fair to expect folks to understand that adding two strings allocates, since that's what happens when you add strings in Rust.

So, this sounds good to me.


I think we'd want to support RustString + RustStringRef and have that use Rust to do the addition and return a RustString.

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

No branches or pull requests

2 participants