Skip to content

Add interactive string interop example with ownership and user flow - #40

Merged
teor2345 merged 2 commits into
rustfoundation:mainfrom
shashu8660:add-example2
Jun 19, 2026
Merged

Add interactive string interop example with ownership and user flow#40
teor2345 merged 2 commits into
rustfoundation:mainfrom
shashu8660:add-example2

Conversation

@shashu8660

Copy link
Copy Markdown
Contributor

This PR adds an interactive string interoperability example between Rust and C++.

The example demonstrates:

  • Passing strings from C++ to Rust using const char*
  • Returning strings from Rust to C++ using CString
  • Ownership transfer across the FFI boundary (Move, Forget, Own)
  • Safe memory management and explicit deallocation
  • Interactive user input flow

The example includes:

  • Rust library exposing FFI functions
  • C++ program handling user input and interaction
  • run.sh script for building and running the example

This aligns with the string interop problem https://github.com/rustfoundation/interop-initiative/blob/main/problem-space/0002-string-interop.md & demonstrates safe handling of string ownership and memory across language boundaries

@teor2345

Copy link
Copy Markdown
Collaborator

Hi, I've already looked at your PR #30, we're just going to focus on one PR per person for now. After that PR is finished, we can decide what to do with this one.

@teor2345
teor2345 marked this pull request as draft March 30, 2026 01:28
@teor2345
teor2345 marked this pull request as ready for review June 15, 2026 12:44

@teor2345 teor2345 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good example, but let's shorten or remove the documentation file, and name it README.md

@@ -0,0 +1,153 @@
- Problem Name: string-interop-interact

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file isn't a problem statement, it is a description of the example.

We don't need something this long to describe an example, please summarise what the example does. It is also ok to delete this file and just write a short README.md

@teor2345

Copy link
Copy Markdown
Collaborator

You'll also have to resolve conflicts, I think rebasing or squashing the PR should do it.

@shashu8660 shashu8660 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the readme.md

teor2345
teor2345 previously approved these changes Jun 17, 2026

@teor2345 teor2345 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Let's merge if it passes CI.

@shashu8660
shashu8660 dismissed teor2345’s stale review June 17, 2026 07:09

The merge-base changed after approval.

@teor2345

Copy link
Copy Markdown
Collaborator

You'll also have to resolve conflicts, I think rebasing or squashing the PR should do it.

Please squash the PR.

Some commits contain files in the examples/rust-cpp-basic-interop directory, which already exists in the main branch. Those commits will disappear when you squash.

I can help with this if you need it?

@shashu8660

shashu8660 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

I done it , do I need to do any other changes

@teor2345

Copy link
Copy Markdown
Collaborator

Looks like maybe you accidentally deleted a bunch of changes you just made, rather than squashing them?

The code and docs you had in the previous commits were fine, we just need to combine all the commits into a single commit.

@shashu8660
shashu8660 force-pushed the add-example2 branch 2 times, most recently from 748a407 to a849604 Compare June 19, 2026 06:27
@shashu8660

Copy link
Copy Markdown
Contributor Author

Is there anything else do I need to change or any update ?

@teor2345

Copy link
Copy Markdown
Collaborator

When you tried to squash, you deleted some files from other examples, and reversed some changes in your previous commits. Don't do that.

Instead, go back to your previous branch, and squash the commits together using git rebase --interactive, and replace "pick" with "squash" in the list.

address review feedback

Restore rust-cpp-basic-interop example
@shashu8660

Copy link
Copy Markdown
Contributor Author

Thank you for pointing out the mistake I was making @teor2345 ,
It was a new topic for me in git which I have never used before so

@teor2345 teor2345 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I've deleted the .gitignore file because there's already one in the repository base directory.

Let's merge!

@teor2345
teor2345 enabled auto-merge June 19, 2026 12:44
@teor2345
teor2345 disabled auto-merge June 19, 2026 17:31
@teor2345

Copy link
Copy Markdown
Collaborator

New changes require approval from someone other than teor2345 because they were the last pusher.

It's just a redundant file deletion, so I'm going to override this and merge,

@teor2345
teor2345 merged commit 6612007 into rustfoundation:main Jun 19, 2026
7 checks passed
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