Skip to content

Crate Module Map

Fresh 🌱

A navigation map of the neon crate's public modules - what each one holds and when you reach for it. Use this to find the right module; the guides on this site explain how to use the pieces in practice.

This is an orientation map, not the full API

For exhaustive, signature-level reference (every struct, trait, and method), consult the generated rustdoc API documentation for the neon crate. This page exists to point you at the right module quickly.

The modules

ModuleHoldsReach for it when you...
preludeThe common imports (Context, Handle, Js* types, JsResult, NeonResult).Start any file: use neon::prelude::*;.
contextContext trait, FunctionContext, ModuleContext, Cx, TaskContext, and friends.Need value constructors, arguments, exports, or the runtime handle (cx).
typesThe Js* value types: JsNumber, JsString, JsObject, JsArray, JsFunction, JsPromise, JsBox, JsTypedArray, plus the extract submodule.Work with any JavaScript value from Rust.
objectThe Object trait and object property access.Get and set properties on objects and arrays.
handleHandle and related root/handle machinery.Hold and pass references to JS values.
resultJsResult, NeonResult, the ResultExt trait (or_throw), and throw types.Return values, propagate errors, or throw exceptions.
eventChannel, and event-scheduling types.Schedule JS work from another thread (async, callbacks).
threadThread-local storage helpers for the JS environment.Stash per-thread state tied to the runtime.
reflectReflection helpers.Do lower-level reflective operations.
metaBuild/version metadata constants for the crate.Inspect Neon's own version/feature metadata.
sysThe low-level, unsafe Node-API FFI surface.(Advanced) Drop below the safe API to raw N-API. Rarely needed.

How the modules relate

flowchart TD
    PRELUDE[prelude: import everything] --> CONTEXT[context: cx, the runtime handle]
    CONTEXT --> TYPES[types: JsNumber, JsString, JsObject, ...]
    CONTEXT --> RESULT[result: JsResult, throw, or_throw]
    TYPES --> OBJECT[object: get / set properties]
    TYPES --> HANDLE[handle: Handle / Root]
    CONTEXT --> EVENT[event: Channel for async]
    EVENT --> THREAD[thread: per-thread state]
    CONTEXT -.advanced.-> SYS[sys: raw Node-API FFI]
    style PRELUDE fill:#10b981,color:#fff
    style CONTEXT fill:#6366f1,color:#fff
    style SYS fill:#f59e0b,color:#fff

Where to go for usage

You want to...Start at
Build JS valuesPrimitive Types, Objects, Arrays
Export and read functionsFunctions, Export Functions SOP
Call back into JSCalling JavaScript from Rust
Run async / threaded workAsync Tasks, Promises & Channels
Throw and handle errorsError Handling
Embed native dataBoxed Native Data (JsBox)
Work with binary dataBuffers & Typed Arrays

Almost everything routes through context

The context module gives you cx, and cx is how you reach the rest. If you are unsure which module a method lives on, check context and types first - see the Context Methods cheat sheet.