Skip to main content

ProtocolContract

Trait ProtocolContract 

Source
pub trait ProtocolContract: Send + Sync {
    // Required methods
    fn protocol(&self) -> Protocol;
    fn contract_id(&self) -> &str;
    fn version(&self) -> &str;
    fn operations(&self) -> Vec<ContractOperation>;
    fn get_operation(&self, operation_id: &str) -> Option<&ContractOperation>;
    fn diff<'life0, 'life1, 'async_trait>(
        &'life0 self,
        other: &'life1 dyn ProtocolContract,
    ) -> Pin<Box<dyn Future<Output = Result<ContractDiffResult, ContractError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn validate<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        operation_id: &'life1 str,
        request: &'life2 ContractRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ValidationResult, ContractError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn get_schema(&self, operation_id: &str) -> Option<Value>;
    fn to_json(&self) -> Result<Value, ContractError>;
}
Expand description

Protocol-agnostic contract definition

This trait allows different protocol implementations (HTTP, gRPC, WebSocket, etc.) to provide a unified interface for contract drift detection.

Required Methods§

Source

fn protocol(&self) -> Protocol

Get the protocol type this contract represents

Source

fn contract_id(&self) -> &str

Get a unique identifier for this contract

Source

fn version(&self) -> &str

Get the contract version

Source

fn operations(&self) -> Vec<ContractOperation>

Get all operations/methods/topics defined in this contract

Source

fn get_operation(&self, operation_id: &str) -> Option<&ContractOperation>

Get a specific operation by identifier

Source

fn diff<'life0, 'life1, 'async_trait>( &'life0 self, other: &'life1 dyn ProtocolContract, ) -> Pin<Box<dyn Future<Output = Result<ContractDiffResult, ContractError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Compare this contract with another contract of the same protocol

Returns a ContractDiffResult describing the differences

Source

fn validate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, operation_id: &'life1 str, request: &'life2 ContractRequest, ) -> Pin<Box<dyn Future<Output = Result<ValidationResult, ContractError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Validate a request/message against this contract

Returns validation errors if the request doesn’t match the contract

Source

fn get_schema(&self, operation_id: &str) -> Option<Value>

Get schema information for an operation

Returns a JSON-serializable representation of the schema

Source

fn to_json(&self) -> Result<Value, ContractError>

Serialize the contract to a JSON representation

Implementors§