lmcode-rust reference
API reference for the dslvm Rust crate, Registry and Program methods, lmcode_std_v3 REST/CLI interfaces, and runtime error codes.
Host SDK API surface
| API | Type / Return | Description |
|---|---|---|
| Registry::new() | Registry | Construct a Registry pre-populated with all 226 lmcode_std_v3 signatures |
| Registry::without_std() | Registry | Construct an empty Registry without standard library functions |
| Registry::context(name, type_name) | Result<(), Error> | Declare a named context variable of a schema object type |
| Registry::function(name, params, ret, cb) | Result<(), Error> | Register a typed host function overload |
| Registry::function_with_dry(name, params, ret, cb, dry) | Result<(), Error> | Register a host function with an explicit DrySlot preview callback |
| Registry::method(owner, name, params, ret, cb) | Result<(), Error> | Register a typed host method overload on owner type |
| Registry::signatures() | Vec<String> | Return all registered canonical signatures in sorted order |
| Registry::schema_summary() | String | Format human-readable --lmcode-schema summary text |
| Program::load(bytecode, schema, ®) | Result<Program, Error> | Verify DSLB v6 bytecode against exact schema bytes and bind imports |
| Program::entries() | &[Entry] | Return source-ordered R49 rule entry descriptors (name, annotation, iface, params, returns) |
| Program::run(&mut ctx, ®) | Result<(), Error> | Execute the main bytecode body |
| Program::call(entry_idx, &mut ctx, ®, args) | Result<Value, Error> | Execute a single R49 rule entry by index |
| register_rest(&mut reg, RestOptions) | Result<RestController, Error> | Configure and return the REST/CLI controller for rest_serve and rest_cli |
| RestController::run(&prog, ®, &mut ctx) | Result<(), Error> | Run the program body and serve HTTP/1.1 over configured streams if rest_serve was called |
| RestController::dispatch(&prog, ®, &mut ctx, &req) | Result<RestResponse, Error> | Dispatch one in-memory HTTP request through the router |
| InvocationResults::from_command(files) | Result<InvocationResults, Error> | Initialize per-part result sinks and dry-mode flag from LMCODE_INVOCATION_FILE |
Standard REST and CLI interfaces (lmcode_std_v3)
The default lmcode_std_v3 catalog provides 226 canonical signatures and 10 standard interfaces on RestExchange for HTTP/1.1 stdio endpoints and stateless CLI commands.
| Interface | Canonical declaration | Behavior |
|---|---|---|
| RestGet | interface RestGet(exchange: RestExchange) -> void | HTTP GET endpoint bound by path annotation such as @"/users/:id" |
| RestPost | interface RestPost(exchange: RestExchange) -> void | HTTP POST endpoint bound by path annotation such as @"/users" |
| RestPut | interface RestPut(exchange: RestExchange) -> void | HTTP PUT endpoint bound by path annotation such as @"/users/:id" |
| RestDelete | interface RestDelete(exchange: RestExchange) -> void | HTTP DELETE endpoint bound by path annotation such as @"/users/:id" |
| RestPatch | interface RestPatch(exchange: RestExchange) -> void | HTTP PATCH endpoint bound by path annotation such as @"/users/:id" |
| RestHead | interface RestHead(exchange: RestExchange) -> void | HTTP HEAD endpoint bound by path annotation |
| RestOptions | interface RestOptions(exchange: RestExchange) -> void | HTTP OPTIONS endpoint bound by path annotation |
| RestHandler | interface RestHandler(exchange: RestExchange) -> void | Method-prefixed (@"POST /users") or rest_route(method, path, annotation) handler |
| CliCommand | interface CliCommand(exchange: RestExchange) -> void | Stateless CLI subcommand entry dispatched by rest_cli(args) |
| CliOption | interface CliOption(exchange: RestExchange) -> void | Stateless CLI flag or option entry dispatched before CliCommand by rest_cli(args) |
Standard REST and CLI functions and methods
| Name | Canonical signature | Description |
|---|---|---|
| rest_config | fn rest_config(string, string) -> void | Set controller configuration keys such as prefix, max_body_bytes, or session before rest_serve() |
| rest_route | fn rest_route(string, string, string) -> void | Bind an HTTP method and path template (:param, :rest..., {param}, {rest...}) to a RestHandler annotation |
| rest_serve | fn rest_serve() -> void | Validate registered routes and request HTTP/1.1 stdio serving after the program body finishes |
| rest_stop | fn rest_stop() -> void | Stop stdio HTTP/1.1 serving after the active response finishes flushing |
| rest_cli | fn rest_cli(StrList) -> string | Dispatch a single stateless CLI argv vector across CliOption, CliCommand, or REST routes and return the response body |
| RestExchange.method | method RestExchange.method() -> string | Return the uppercase HTTP method verb for the active request |
| RestExchange.path | method RestExchange.path() -> string | Return the percent-decoded request path without the query string |
| RestExchange.query | method RestExchange.query(string) -> string | Return the first value of a query key or empty string when absent |
| RestExchange.has_query | method RestExchange.has_query(string) -> bool | Return true when the query key is present in the request target |
| RestExchange.param | method RestExchange.param(string) -> string | Return a matched path parameter from :param or :rest... (or {param} / {rest...}) |
| RestExchange.header | method RestExchange.header(string) -> string | Return case-insensitive header value (repeated headers joined by comma-space) |
| RestExchange.has_header | method RestExchange.has_header(string) -> bool | Return true when the header is present on the request |
| RestExchange.body | method RestExchange.body() -> string | Return raw request body bytes |
| RestExchange.status | method RestExchange.status(int) -> void | Set HTTP response status code in range 200..599 |
| RestExchange.set_header | method RestExchange.set_header(string, string) -> void | Set or replace a response header outside managed framing headers |
| RestExchange.send | method RestExchange.send(string) -> void | Replace response body with raw bytes |
| RestExchange.json | method RestExchange.json(string) -> void | Replace response body and set Content-Type to application/json |
| RestExchange.get | method RestExchange.get(string) -> string | Read server-wide shared string state key or empty string when absent |
| RestExchange.set | method RestExchange.set(string, string) -> void | Write server-wide shared string state key |
| RestExchange.increment | method RestExchange.increment(string) -> int | Atomically increment a named integer counter starting at 1 |
Structured error codes and exit statuses
| Error code | Phase | Exit status | Trigger condition |
|---|---|---|---|
| LOAD_BAD_BYTECODE | load | 3 | Malformed DSLB v6 header, bad magic or version, truncated section, invalid opcode, or stack depth violation |
| LOAD_BAD_SCHEMA | load | 3 | Host schema JSON fails dsl.schema 2 validation or declares an invalid result contract |
| LOAD_SCHEMA_MISMATCH | load | 3 | 32-byte SHA-256 schema hash in DSLB v6 header does not match exact host schema bytes |
| LOAD_UNBOUND | load | 3 | Bytecode imports a context, function, or method signature not registered in the host Registry |
| RUN_ERROR | run | 3 | VM division or remainder by zero, or loop-free operand stack underflow |
| RUN_HOST | run | 3 | Host callback failure, invalid encoding, expired collection handle, or REST route validation failure |
| APP_FAIL | app | 4 | Post-run application domain validation failure or output stream write failure |