Skip to main content

Crate weirdnet_code_spaces

Crate weirdnet_code_spaces 

Source
Expand description

§weirdnet-code-spaces

Code spaces: small programs (math formulas, Polars expressions, Rust, typed Python, or a library built elsewhere) compiled into plugins against the weirdnet-plugin SDK, cached by content, loaded after an ABI check and approved by a trust hash.

What stays with the application: where code spaces are stored, who may approve them, the host methods a plugin calls (its data) and how a result view is drawn (view parses, checks and converts it). Everything here is parameterized by a Profile (the SDK, symbol names, hash domains and the names messages use); WEIRDNET is the default.

ⓘ
use weirdnet_code_spaces::{self as cs, Env, Lang, WEIRDNET};
let env = Env::new("/tmp/app/code", "/tmp/app/code/target");
let src = "fast = sma(close, 10)";
let built = cs::build(&WEIRDNET, &env, Lang::Math, src, &mut |line| eprintln!("{line}"))?;
let plugin = cs::load(&WEIRDNET, &built.path)?; // then call plugin.run with a host table

Features: math (default), polars, python (each adds its language; Python needs no libpython), native-plugins (default: running cargo and loading libraries, so desktop only). Images of results are not drawn here (see weirdnet-render).

Re-exports§

pub use error::Result;
pub use error::SpacesError;
pub use host::Host;
pub use lang::Lang;

Modules§

abi
The plugin C ABI (version 2 for WEIRDNET): the SDK’s own abi.rs. Version 1 has the same layout, so a host table built from these types serves either. The Weirdnet plugin C ABI, version 2. Shared verbatim by hosts and plugins.
error
The crate’s error type.
host
The host side of the plugin ABI: the table a plugin’s run gets, over an application’s Host. Requests and replies are text (JSON by convention); what the methods are and what they read and write is the application’s.
lang
What a code space is written in.
mathmath
Math code spaces: one formula per line, compiled to Rust over columns.
spaces
Spaces: a main code space plus members it calls and other spaces it imports, declared in an @imports header (// @imports a, b, space:other). This module has the parts that don’t need the application’s storage: reading and rewriting the header, the line-up hash an owner approves, and the cycle and depth check over a Graph the application provides.
view
The result of a run: a view that follows the content view rules. A table shows as a list tile and a chart as a chart tile, and either can switch to the other (t in the TUI); tiles split right or below like the workspace. The plugin sends it with the result host method (View::to_json in the SDK). ResultView::from_plugin is what a host does with it: parse, check and cut it to the limits below; how it is drawn is the host’s own, with ResultView::as_table, ResultView::as_chart, ResultView::text_lines, and sparkline to start from (drawing images, e.g. with weirdnet-render, is the host’s too).

Structs§

Built
A built plugin.
Env
Where code spaces are built and cached. The application chooses both directories.
Loadednative-plugins
A loaded plugin: its run function (call it with a host table) and its info JSON.
Profile
Everything that names the application or its SDK. Hashes, generated code, symbol names and messages all come from here, so an application keeps its formats by passing its own.

Constants§

WEIRDNET
The default profile: the weirdnet-plugin SDK, ABI 2.
WEIRDNET_SDK_FILES
The weirdnet-plugin SDK this crate carries (sdk/, the same files as the weirdnet-plugin crate).

Functions§

approved
Approved as it is: approved_hash is the trust hash of this language and source (a library that can’t be read is never approved).
buildnative-plugins
Build (or find in the cache) the plugin of a source. Cached libraries are content addressed and replaced by rename, never rewritten, so a loaded one stays valid. A plugin source is copied in under its trust hash. log gets cargo’s output lines.
build_key
The cache key of a build: ABI, SDK, codegen, language, platform, dependencies, source.
cargo
The cargo to build with: the profile’s variable or cargo on the PATH, checked by running it.
check
Check a source without building: the language’s own checks (a prebuilt plugin is copied into the cache and loaded, never loaded in place).
dependency
The extra dependency line a language’s generated crate needs.
generate
Write the crate of a source into dir (a build directory under the code root).
generate_user
The generated crate’s user.rs (and py.rs for Python) for a source.
lib_rs
The generated crate’s lib.rs.
loadnative-plugins
Load a plugin (once per process and profile; libraries stay loaded) after checking it exports the profile’s symbols and ABI version.
manifest
The Cargo.toml of a generated crate.
plugin_file
The library a plugin source names (its path; ~/ is the home directory).
runnative-plugins
Run a loaded plugin with host (a host table of the profile’s ABI version). Returns the plugin’s code (abi::RUN_OK, RUN_ERROR, RUN_PANIC, or what else it returned).
sdk_hash
Hash of the profile’s SDK files.
trust_hash_of
What an owner approves: the language and source (or the library’s bytes), under the profile’s trust domain.
write_sdk
Write the profile’s SDK crate into dir (files already there and equal are left alone).