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 tableFeatures: 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 ownabi.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.
- math
math - 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
@importsheader (// @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 aGraphthe 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 (
tin the TUI); tiles split right or below like the workspace. The plugin sends it with theresulthost method (View::to_jsonin the SDK).ResultView::from_pluginis what a host does with it: parse, check and cut it to the limits below; how it is drawn is the host’s own, withResultView::as_table,ResultView::as_chart,ResultView::text_lines, andsparklineto start from (drawing images, e.g. withweirdnet-render, is the host’s too).
Structs§
- Built
- A built plugin.
- Env
- Where code spaces are built and cached. The application chooses both directories.
- Loaded
native-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-pluginSDK, ABI 2. - WEIRDNET_
SDK_ FILES - The
weirdnet-pluginSDK this crate carries (sdk/, the same files as theweirdnet-plugincrate).
Functions§
- approved
- Approved as it is:
approved_hashis the trust hash of this language and source (a library that can’t be read is never approved). - build
native-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
pluginsource is copied in under its trust hash.loggets 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
cargoon 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(andpy.rsfor Python) for a source. - lib_rs
- The generated crate’s
lib.rs. - load
native-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.tomlof a generated crate. - plugin_
file - The library a
pluginsource names (its path;~/is the home directory). - run
native-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).