TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Managing mutable data in Elixir with Rust

131 点作者 clarkema大约 1 年前

8 条评论

mgdev大约 1 年前
Rustler is great. Though this gets me thinking about how you can maintain as many Elixir invariants and conventions as possible, even while escaping them under the covers. Being able to call FeGraph.set&#x2F;2 and have db actually be mutated violates Elixir&#x27;s common call patterns, even if it&#x27;s technically allowed.<p>For example: I wonder if it wouldn&#x27;t be more &quot;erlangy&quot;&#x2F;&quot;elixiry&quot; to model the mutable ops behind a genserver that you send messages to. In the Elixir world it&#x27;s perfectly normal to make GenServer.call&#x2F;3 and expect the target PID to change its internal state in a non-deterministic way. It&#x27;s one of the only APIs that explicitly blesses this. The ETS API is another.<p>Alternatively, you could have the ref store both a DB sequence and a ref ID (set to the last DB sequence), and compare them on operations. If you call FeGraph.set&#x2F;2 with the same db ref two times, you compare the ref ID to the sequence and panic if they aren&#x27;t equal. They always need to operate with the latest ref. Then at last the local semantics are maintained.<p>Maybe this is less relevant for the FeGraph example, since Elixir libs dealing with data are more willing to treat the DB as a mutable thing (ETS, Digraph). But the it&#x27;s not universal. Postgrex, for example, follows the DB-as-PID convention. Defaulting to an Elixiry pattern by default for Rustler implementation is probably a good practice.
评论 #39383722 未加载
评论 #39384295 未加载
NiklasBegley大约 1 年前
I also want to give a shout out to the Rustler folks for creating a great library! We use Rustler quite extensively at Doctave, and have written about our experiences with Rustler before [0] (though our architecture has advanced quite a bit since the article was written).<p>Integrating Elixir and Rust has been delightfully straightforward and is a great choice for calling into libraries not available in Elixir, or offloading CPU intensive tasks.<p>[0]: <a href="https:&#x2F;&#x2F;www.doctave.com&#x2F;blog&#x2F;2021&#x2F;08&#x2F;19&#x2F;using-rust-with-elixir-for-code-reuse-and-performance" rel="nofollow">https:&#x2F;&#x2F;www.doctave.com&#x2F;blog&#x2F;2021&#x2F;08&#x2F;19&#x2F;using-rust-with-elix...</a>
atonse大约 1 年前
Getting rustler up and running for us was very easy. Thank you to the team for making this excellent library.<p>We had some inconsistent build results (ours is an umbrella app) but apart from forcing a compilation and losing the ability to cache the rust builds, everything else has worked so well so we’re happy to get access to the massive rust ecosystem.
AlchemistCamp大约 1 年前
It’s exactly this use case that nudged me (primarily an Elixir dev) to start learning Rust a few years back.<p>Unfortunately, I haven’t had a project where I’ve needed to use Rustler yet, though.
doctor_phil大约 1 年前
Nice. I thought that Zig would be a nice language for writing NIFs - but of course Rust would be good too. Cool!
评论 #39383172 未加载
评论 #39382659 未加载
评论 #39382685 未加载
elbasti大约 1 年前
Cool writeup. A <i>little</i> ironic, since Erlang&#x27;s `digraphs` are also mutable!
评论 #39382496 未加载
hpeter大约 1 年前
This is super cool. I learn something new every day.
wredue大约 1 年前
Immutable data is not a “foundation of scalability and robustness”.
评论 #39383256 未加载
评论 #39383053 未加载