-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Calling C++ from Rust | ||
|
||
Until this point, all Zngur features discussed was about using Rust code inside C++, but no C++/Rust interop tool is complete | ||
without supporting the C++ to Rust direction. In fact, this direction is arguably more important since in a C++/Rust project | ||
most of the existing code is in C++ and Rust code needs a way to use them in order to be useful. So Zngur also supports this | ||
direction. | ||
|
||
Zngur general idea is that Rust semantics is a subset of C++ semantics, so we should use Rust things in C++ and avoid bringing | ||
C++ things in Rust (See [Philosophy](../philosophy.md)). So, even in the C++ to Rust direction, Zngur operates only on Rust types. For | ||
example, Zngur allows you to call a C++ function that takes Rust types in inputs in Rust, but you can't call a function that takes | ||
a C++ object. Or you can write an `impl` block for a Rust type in C++ and call those methods in Rust, but you can't call C++ methods | ||
of a C++ object in Rust. | ||
|
||
So you can't call your C++ code directly in Rust, and you need to write a Rusty wrapper for your C++ code. This is often unavoidable | ||
even if the interop tool supports calling C++ directly if you have a meaningful amount of Rust code, since C++ value cannot be owned | ||
in Rust, and Rust is more expressive in API and function signatures (e.g. it has lifetimes) so such a wrapper is required anyway. Zngur | ||
tries to enable writing a Rusty wrapper for your C++ code as idiomatic as a normal Rust code, and all features in this section try | ||
to help in achieving this goal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Philosophy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters