//! A Tool declaration's identity and signature (`abi.md`, *Identity and
//! signatures*).
//!
//! A signature is the declaration's `Identity` and its `TypeSpec`
//! ([`crate::TypeSpec`]). An implementation fits a declaration when the
//! comparable forms of the two are the same bytes ([`crate::comparable`]).
use flow_types::{Identity, Type};
/// The key a parameter crosses the boundary by: its name, or `#at`, its
/// position, for one that binds no single name.
pub fn parameter_key(at: usize, name: Option<String>) -> String {
name.unwrap_or_else(|| format!("#{at}"))
}
/// A Tool declaration's signature, for a declaration returning `result`.
/// [`Type::Param`] counts `generic`.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Signature {
/// Each parameter's name and type, in declaration order.
pub params: Vec<(String, Type)>,
/// The declared result type, `R`: a call answers `Ok` with a value of it.
pub result: Type,
/// The type parameters' names, in declaration order.
pub generic: Vec<String>,
}
/// A Tool declaration, as the host binds it.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct ToolDecl {
/// Where it lives and its name.
pub identity: Identity,
/// Its signature.
pub signature: Signature,
}