Crate kinode_process_lib

Source
Expand description

Kinode process standard library for Rust compiled to Wasm Must be used in context of bindings generated by kinode.wit.

This library provides a set of functions for interacting with the kinode kernel interface, which is a WIT file. The types generated by this file are available in processes via the wit_bindgen macro, if a process needs to use them directly. However, the most convenient way to do most things will be via this library.

We define wrappers over the wit bindings to make them easier to use. This library encourages the use of IPC body and metadata types serialized and deserialized to JSON, which is not optimal for performance, but useful for applications that want to maximize composability and introspectability. For blobs, we recommend bincode to serialize and deserialize to bytes.

Re-exports§

pub use types::address::Address;
pub use types::capability::Capability;
pub use types::lazy_load_blob::LazyLoadBlob;
pub use types::package_id::PackageId;
pub use types::process_id::ProcessId;
pub use crate::kinode::process::standard::*;

Modules§

eth
Interact with the eth provider module.
homepage
Interact with the system homepage.
http
Interact with the HTTP server and client modules. Contains types from the http crate to use as well.
kernel_types
The types that the kernel itself uses – warning – these will be incompatible with WIT types in some cases, leading to annoying errors. Use only to interact with the kernel or runtime in certain ways.
kimap
Interact with kimap, the onchain namespace
kinode
kv
Interact with the key_value module
net
Interact with the networking module For configuration, debugging, and creating signatures with networking key.
scripting
A set of types and macros for writing “script” processes.
sqlite
Interact with the sqlite module
timer
Interact with the timer runtime module.
vfs
Interact with the virtual filesystem

Macros§

Spawn
The Spawn!() macro is defined here as a no-op. However, in practice, kit build will rewrite it during pre-processing.
call_init
Implement the wit-bindgen specific code that the kernel uses to hook into a process. Write an init(our: Address) function and call it with this.
kiprintln
Uses the print_to_terminal function from the WIT interface on maximally-verbose mode, i.e., this print will always show up in the terminal. To control the verbosity, use the print_to_terminal function directly.
println
Override the println! macro to print to the terminal. Uses the print_to_terminal function from the WIT interface on maximally-verbose mode, i.e., this print will always show up in the terminal. To control the verbosity, use the print_to_terminal function directly.
process_println
Uses the print_to_terminal function from the WIT interface on maximally-verbose mode, i.e., this print will always show up in the terminal. To control the verbosity, use the print_to_terminal function directly.
script
A macro for writing a “script” process. Using this will create the initial entry point for your process, including the standard init function which is called by the system, and a set of calls that:
validate_spawn_args
widget
A macro for writing a process that serves a widget and completes. This process should be identified in your package manifest.json with on_exit set to None.

Structs§

Request
Request builder. Use Request::new() or Request::to() to start a request, then build it, then call Request::send() on it to fire.
Response
Response builder. Use Response::new() to start a Response, then build it, then call Response::send() on it to fire.
SendError

Enums§

AddressParseError
Error type for parsing an Address from a string.
Message
The basic Message type. A Message is either a crate::Request or a crate::Response. Best practices when handling a Message:
OnExit
ProcessIdParseError
SendErrorKind

Functions§

_wit_message_to_message
_wit_send_error_to_send_error
await_message
Await the next message sent to this process. The runtime will handle the queueing of incoming messages, and calling this function will provide the next one. Interwoven with incoming messages are errors from the network. If your process attempts to send a message to another node, that message may bounce back with a SendError. Those should be handled here.
await_next_message_body
Get the next message body from the message queue, or propagate the error.
can_message
See if we have the Capability to message a certain process. Note if you have not saved the Capability, you will not be able to message the other process.
get_capability
Get a Capability in our store
get_typed_blob
Fetch the blob of the most recent message we’ve received. Returns None if that message had no blob. If it does have one, attempt to deserialize it from bytes with the provided function.
get_typed_state
Fetch the persisted state blob associated with this process. This blob is saved using the set_state() function. Returns None if this process has no saved state. If it does, attempt to deserialize it from bytes with the provided function.
make_blob
Create a blob with no MIME type and a generic type, plus a serializer function that turns that type into bytes.
spawn
Spawn a new process. This function is a wrapper around the standard spawn() function provided in kinode::process::standard (which is generated by the WIT file).