# Calling Elixir in Rust?

**URL:** <https://forum.elixirforum.com/t/calling-elixir-in-rust/40121>\
**Category:** Questions\
**Tags:** rust, rustler\
**Created:** [May 31, 2021, 3:20am UTC](https://forum.elixirforum.com/t/calling-elixir-in-rust/40121 "2021-05-31T03:20:29Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![akash-akya](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/akash-akya/32/18688_2.png) [@akash-akya](https://forum.elixirforum.com/u/akash-akya)\
**Post date:** [May 31, 2021, 8:50am UTC](https://forum.elixirforum.com/t/calling-elixir-in-rust/40121/6 "2021-05-31T08:50:29Z")

</div>

Hi @tessi, thanks for taking time to write this approach. I also played around same idea in the past (in C though).

Just want to highlight the risks involved if someone is considering

- since mutex does not compose well, its easy to end-up with deadlocks. Especially if the callback is not internal function but something given by the _user_ of the library (consider a callback calling another NIF).
- its tricky to handle errors, “let-it-crash” does not work well with this, since we have to unblock the thread no matter what happens to the callback.
- forces process at erlang/elixir side and thread at NIF side. And most likely we need thread pooling at NIF side
- needless to say its not very efficient if you are calling callback often - due to all the context-switching & synchronizations involved.

I think there were few more but not able to recall at the moment.

Another reference: [[erlang-questions] Calling Erlang functions from NIFs](https://erlang.org/pipermail/erlang-questions/2018-January/094626.html)

---

_[View the full topic](https://forum.elixirforum.com/t/calling-elixir-in-rust/40121)._
