Skip to content

Exposing enif_schedule_nif safely #107

Open
@jorendorff

Description

@jorendorff

enif_schedule_nif comes with a contract, much like enif_raise_exception. It's hard to support safely.

But we already support enif_raise_exception (see https://github.com/hansihe/rustler/blob/master/src/codegen_runtime.rs#L44 ). We could support enif_schedule_nif in the same way. Don't let the user call it directly, but let them return a special Rust value that means "call enif_schedule_nif safely for me".

There is one problem that we would need to solve, though. Currently, all NIFs have the return type NifResult<NifTerm<'a>>, allowing just two possibilities:

  • Ok(term): "return this term"
  • Err(exc): "raise this exception"

Now we want to add a third option, "schedule this nif". But we can't just change the return type, because that would break all existing code. I guess the way to do this is with a trait. Come to think of it, we should allow a wide variety of return types anyway, not just NifResult<NifTerm<'a>>; for example, anything that implements NifEncode should be just as good as a NifTerm, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions