Open wdv4758h opened 7 years ago
以下紀錄 Rust 與其他程式語言間的互動,主要可以分成兩項:
對於 Rust 使用 C 程式碼,基本上就是用 extern 並定義好對應的函式名稱和型別。 對於 C 使用 Rust 程式碼,基本上就是用 Rust 這邊要用 #[no_mangle] 避免函式名稱的 mangling,並且界面要是針對 C 的型別。
extern
#[no_mangle]
雖然我有嘗試寫過 Rust 提供給 C 和 Python 使用,但是覺得手寫起來不太方便,目前有些看起來可能可以幫上忙,但還沒嘗試。
Python 這邊希望可以像 Cython 一樣提供比較方便的方式在 Setup Script 中使用,以便在專案中加入部份的 Rust 程式碼或是連結特定的 library,不知道這樣是否會運作良好。
extern "C"
相關資源:
相關專案:
相關文章:
以下紀錄 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 manglingextern "C"
=> C ABI function with name manglingextern
=> Rust ABI function with name mangling相關資源:
相關專案:
相關文章: