amb85

amb85

Calling Elixir Scripts from within Rust

I’ve been thinking about how I could use Elixir as a scripting language within a Rust application. I read an interesting discussion about Rustler, NIFs and Ports, but this doesn’t quite seem to meet the use case I envision.

What I really want is a Rust application with the Erlang BEAM and Elixir embedded (probably when the Rust application is compiled?). Rust should be the main entry point and would initiate execution of the Elixir scripts, with any necessary results/changes being propagated back to the Rust app. (I guess think of something like a game engine written in C++ with an embedded Lua scripting engine).

I can think of a couple options where Rust an Elixir portions are their own processes and use Ports to communicate. Or where the Rust app launches some mix task and uses NIFs to access other Rust functionality. Both of these approaches seem clunky.

Has anyone got any thoughts or suggestions on how I might approach achieving such a goal?

Most Liked

hauleth

hauleth

I have one simple question - WHY?

I mean BEAM wasn’t designed as a embedded scripting engine, so it isn’t easy accessible as one. You can though look at the Enigma which is BEAM implementation in Rust, so maybe you could integrate that.

TBH If you want embedded language in Rust then look into Lua(JIT), Ketos, or Dyon.

tme_317

tme_317

You could potentially compile your elixir code as escripts, then just launch them from the Rust app sending necessary data as command line arguments or from stdin and reading the result from stdout.

This has some downsides and may not work or be performant enough depending on what you are trying to accomplish but it could work for you. Usually I do the opposite and launch fast Rust apps all the time from my main Elixir long-running app.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement