pub trait Codec {
type Wire;
// Required methods
fn version(&self) -> ProtocolVersion;
fn capabilities(&self) -> FeatureProfile;
fn lift(&self, wire: &Self::Wire) -> ToolResult;
fn lower(
&self,
value: ToolResult,
policy: DegradePolicy,
report: &mut TranslationReport,
) -> Result<Self::Wire, LowerError>;
}Expand description
Required Associated Types§
Sourcetype Wire
type Wire
The generated wire type for this revision.
Named per implementation rather than fixed, because the revisions do not
agree on their shapes: CallToolResult.content is
Vec<CallToolResultContentChoice> at 2024-11-05 and Vec<ContentBlock>
from 2025-06-18, and only structuredContent distinguishes the
revisions that can carry it. A single wire type would have to be the
least common denominator, which is a type that cannot express anything
— the mistake the IR exists to avoid.
Required Methods§
Sourcefn version(&self) -> ProtocolVersion
fn version(&self) -> ProtocolVersion
The revision this codec speaks.
Sourcefn capabilities(&self) -> FeatureProfile
fn capabilities(&self) -> FeatureProfile
What this revision can express, as a negotiated profile.
Used by the gate, so it must be the real profile for a peer speaking this revision — the intersection of what both sides advertise, not what the revision permits in the abstract. A codec that answers with the revision’s maximum would let a value through that the actual peer cannot read.
Sourcefn lift(&self, wire: &Self::Wire) -> ToolResult
fn lift(&self, wire: &Self::Wire) -> ToolResult
Wire to IR.
Infallible by design: a message the peer sent always has an IR form. Use
UnknownContent for a block this
build does not recognise, and Extensions for fields
it does not
name, so nothing is lost in the crossing.
Sourcefn lower(
&self,
value: ToolResult,
policy: DegradePolicy,
report: &mut TranslationReport,
) -> Result<Self::Wire, LowerError>
fn lower( &self, value: ToolResult, policy: DegradePolicy, report: &mut TranslationReport, ) -> Result<Self::Wire, LowerError>
IR to wire.
§Errors
LowerError::FeatureUnavailable when the value needs something this
revision cannot express and the policy authorises no rule for it. Any
rule the policy does authorise is applied and recorded in report.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".