flow_abi/signature.rs
1//! A Tool declaration's identity and signature (`abi.md`, *Identity and
2//! signatures*).
3//!
4//! A signature is the declaration's `Identity` and its `TypeSpec`
5//! ([`crate::TypeSpec`]). An implementation fits a declaration when the
6//! comparable forms of the two are the same bytes ([`crate::comparable`]).
7
8use flow_types::{Identity, Type};
9
10/// The key a parameter crosses the boundary by: its name, or `#at`, its
11/// position, for one that binds no single name.
12pub fn parameter_key(at: usize, name: Option<String>) -> String {
13 name.unwrap_or_else(|| format!("#{at}"))
14}
15
16/// A Tool declaration's signature, for a declaration returning `result`.
17/// [`Type::Param`] counts `generic`.
18#[derive(Clone, PartialEq, Eq, Debug)]
19pub struct Signature {
20 /// Each parameter's name and type, in declaration order.
21 pub params: Vec<(String, Type)>,
22 /// The declared result type, `R`: a call answers `Ok` with a value of it.
23 pub result: Type,
24 /// The type parameters' names, in declaration order.
25 pub generic: Vec<String>,
26}
27
28/// A Tool declaration, as the host binds it.
29#[derive(Clone, PartialEq, Eq, Debug)]
30pub struct ToolDecl {
31 /// Where it lives and its name.
32 pub identity: Identity,
33 /// Its signature.
34 pub signature: Signature,
35}