Talks
Elixir and the Outside World
- Ports
- erl_interface
- C Nodes
- Port Drivers
- Native Implemented Functions (NIFs)
NIFs
- Called just like any other Erlang/Elixir code
- NIFs live in a dynamically loaded library (.so or .dll)
- NIFs replace Erlang/Elixir functions of the same name/arity at module load time
Functionality
- Read and write Erlang terms
- Binaries
- Resource objects
- Threads and concurrency
Example
Resource Objects
- Resource objects are a safe way to return pointers to native data structures from a NIF
- It can be stored and passed between processes on the same node
- the only real end usage is to pass it back as an argument to a NIF
- A resource object is not deallocated until the last handle term is garbage collected by the VM
Rescheduling
- The Erlang NIF API provides a way for a NIF to reschedule itself directly with
enif_schedule_nif
- When combined with
rustler::schedule::consume_timeslice
it allows all the chunking to be done directly in the NIF (No supported yet)
Threaded NIFs
- Spawn a separate OS thread to do the work
- Send the result as a message to the calling process
Dirty NIFs
- Allows you to call a NIF without worrying about blocking a normal scheduler
- By default you will have the same number of dirty schedulers as normal schedulers
Elixir with Rust #rust rustler
serde_rustler JSON Example