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

Rust and other languages #69

Open
wdv4758h opened this issue Feb 14, 2017 · 0 comments
Open

Rust and other languages #69

wdv4758h opened this issue Feb 14, 2017 · 0 comments

Comments

@wdv4758h
Copy link
Owner

wdv4758h commented Feb 14, 2017

以下紀錄 Rust 與其他程式語言間的互動,主要可以分成兩項:

  • 在 Rust 內使用其他程式語言的程式碼
  • 在其他程式語言內使用 Rust 的程式碼

對於 Rust 使用 C 程式碼,基本上就是用 extern 並定義好對應的函式名稱和型別。
對於 C 使用 Rust 程式碼,基本上就是用 Rust 這邊要用 #[no_mangle] 避免函式名稱的 mangling,並且界面要是針對 C 的型別。

雖然我有嘗試寫過 Rust 提供給 C 和 Python 使用,但是覺得手寫起來不太方便,目前有些看起來可能可以幫上忙,但還沒嘗試。

Python 這邊希望可以像 Cython 一樣提供比較方便的方式在 Setup Script 中使用,以便在專案中加入部份的 Rust 程式碼或是連結特定的 library,不知道這樣是否會運作良好。

  • #[no_mangle] + extern "C" => C ABI function without name mangling
  • #[no_mangle] + extern => Rust ABI function without name mangling
  • extern "C" => C ABI function with name mangling
  • extern => Rust ABI function with name mangling

相關資源:

相關專案:

相關文章:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant