aion-rs 0.10.0

Transport-agnostic Aion workflow engine with durability, replay, timers, and supervision.
Documentation
//! Built-in and engine NIF registration helpers.

use beamr::atom::AtomTable;
use beamr::native::{BifRegistryImpl, NativeRegistrationError};

use crate::error::EngineError;

use super::super::nif::Mfa;
use super::super::nif_state::EngineNifState;
use super::runtime_error_from_display;

pub(super) fn nif_registration_error(mfa: &Mfa, error: NativeRegistrationError) -> EngineError {
    match error {
        NativeRegistrationError::DuplicateMfa { .. } => EngineError::NifRegistration {
            reason: format!("native function already registered for {}", mfa.display()),
        },
    }
}

pub(super) fn register_all_bifs(
    registry: &BifRegistryImpl,
    atom_table: &AtomTable,
    nif_state: &EngineNifState,
) -> Result<(), EngineError> {
    use beamr::native::{
        bifs::register_gate1_bifs, gate3_bifs::register_gate3_bifs,
        gleam_ffi::register_gleam_ffi_bifs, otp_stubs::init_otp_atoms,
        otp_stubs::register_otp_stubs, stdlib_stubs::register_stdlib_stubs,
    };

    register_gate1_bifs(registry, atom_table).map_err(runtime_error_from_display)?;
    super::spawn_bifs::register_process_bifs(registry, atom_table)
        .map_err(runtime_error_from_display)?;
    register_gate3_bifs(registry, atom_table).map_err(runtime_error_from_display)?;
    super::spawn_bifs::replace_gate3_fun_spawn_bifs(registry, atom_table, nif_state)?;
    register_stdlib_stubs(registry, atom_table).map_err(runtime_error_from_display)?;
    register_gleam_ffi_bifs(registry, atom_table).map_err(runtime_error_from_display)?;
    init_otp_atoms(atom_table);
    register_otp_stubs(registry, atom_table).map_err(runtime_error_from_display)?;
    Ok(())
}