Expand description
The Rust toolkit for Tool implementations (docs/runtime/spec/abi.md,
Toolkits).
§Ordinary Rust functions
Annotate public functions with tool and derive Flow for boundary
records and enums. A direct .rs import selects a module in its Cargo library;
the flow-toolkit CLI prepares its generated launcher. Function bodies remain
directly callable by Rust tests. An optional lifecycle initializer returns a
Resource whose asynchronous or synchronous cleanup runs after calls drain
at normal shutdown; an injected Context retrieves the shared resource and
writes call-correlated operational logs through Context::log. Native build and metadata extraction happen during
explicit preparation; metadata-only reads never compile or invoke bodies.
§Types
| Flow | Rust |
|---|---|
Int | Int, exact at any size |
Decimal | Decimal, exact, never binary floating point |
Bool, Text, Unit, Never | bool, String, (), Infallible |
Bytes | Bytes |
Duration, Instant | Duration, Instant: exact seconds |
List<T>, Set<T>, Dict<K, V> | Vec<T>, BTreeSet<T>, BTreeMap<K, V> |
Option<T>, tuples | Option<T>, tuples |
json.Value | JsonValue, with Flow’s equality and order |
| a record, an enum | a struct, an enum |
a @tool type | #[derive(Flow)] #[flow(opaque)] String newtype |
| a Tool’s type parameter | Value, admitted through ContextCodec |
a parameter-dependent Set or Dict | ContextSet, ContextDict |
Generic calls carry validated schemas and type descriptions. The automatic bridge instantiates generic Rust functions with typed erased values and applies contextual codecs through their native containers, records and enum payloads. Ordinary monomorphic values keep their native Rust representation.
Narrowing an Int to a fixed width is the author’s own checked
conversion.
§Answers
A call whose arguments do not decode is answered NotRun, as is one
naming a declaration this implementation does not serve; a method that
panics is answered Unknown (abi.md, Toolkits). A cancel sets the
call’s Context::cancelled; it proves nothing, and a reply sent after
it is harmless. Calls run concurrently, one thread each.
Re-exports§
pub use data::Bytes;pub use data::ContextCodec;pub use data::ContextDict;pub use data::ContextSet;pub use data::Data;pub use data::JsonValue;pub use data::PayloadView;pub use data::parse_json;
Modules§
- data
- Values converted under the value encoding (
abi.md, The value encoding and Decoding):Datafor every Rust type a Flow data type maps to, and the pieces generated records and enums are written with.
Structs§
- Context
- What a method knows about the call it answers.
- Decimal
- An exact decimal number.
- Decode
Error - Why decoding refused. The
pathandproblemfields arejson.DecodeError’s shape (stdlib.md);kindpreserves host refusal metadata. A new Tool reply that fails decoding isBadReplywith this explanation (abi.md, Decoding). - Duration
- A length of time, ordered by length.
- Instant
- A point in time, ordered chronologically.
- Int
- An integer, with no bound.
- Resource
- A process resource retained across calls and explicitly closed at normal shutdown.
- Validated
Types - An immutable concrete call graph after complete validation.
- Value
- A generic Tool value admitted through a validated concrete call codec. The index distinguishes independent native type parameters at the automatic bridge.
Enums§
- Decode
Error Kind - Why decoding refused, independently of its human-readable explanation.
- Json
- A JSON value.
- Problem
- Why a call did not produce its success value.
Traits§
- Flow
Type - A native boundary value with contextual conversion for generic calls.
Native scalars, containers and
#[derive(Flow)]supply implementations.
Attribute Macros§
- lifecycle
- Registers one optional process resource initializer without an authored launcher.
- tool
- Exports an ordinary function through a generated typed Tool adapter.
Derive Macros§
- Flow
- Derives exact Flow encoding and declaration metadata for records and enums.