pub trait PlatformAdapter: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn parse_stdin(&self, raw: &str) -> Result<HookEvent, String>;
fn format_output(&self, result: HookResult) -> String;
// Provided method
fn classify_error(&self, err: &Error) -> ErrorClass { ... }
}Expand description
Contract every platform adapter implements. The trait is object-safe
on purpose so get_platform_adapter can return a Box<dyn PlatformAdapter> and the dispatch site doesn’t need to know the
concrete type at compile time. That makes adding a new client (say
Cursor) a pure module-level addition — no changes to the CLI dispatch
loop beyond the get_platform_adapter match arm.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable identifier used in logs + telemetry. Must match the string
get_platform_adapter dispatches on so adapter.name() == requested_name round-trips.
Sourcefn parse_stdin(&self, raw: &str) -> Result<HookEvent, String>
fn parse_stdin(&self, raw: &str) -> Result<HookEvent, String>
Parse a single hook invocation’s stdin payload into our canonical
HookEvent. Adapters SHOULD be permissive about unknown fields
(clients evolve faster than we can ship adapter updates) and
strict only about the tiny subset they actually need.
On unrecognised / unsupported events, return Err with a human-
readable reason. The CLI logs the error and no-ops — hooks must
never block the user workflow, even on malformed input.
Sourcefn format_output(&self, result: HookResult) -> String
fn format_output(&self, result: HookResult) -> String
Format a HookResult as the exact JSON the client expects on
stdout. Returns a complete, newline-free string; the caller
prints it + a trailing newline. Formatting is infallible because
HookResult is a fixed shape we control.
Provided Methods§
Sourcefn classify_error(&self, err: &Error) -> ErrorClass
fn classify_error(&self, err: &Error) -> ErrorClass
Bucket an error produced by the hook’s core work so the CLI can
pick an exit code (see main.rs Hook::Run). Default walks the
anyhow error chain for transport-ish hints (io kinds, reqwest
connect/timeout, HTTP 5xx) vs client-ish hints (HTTP 4xx, serde
parse failures). Adapters can override when their transport layer
carries richer context than the default sniffer can see.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".