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§
Sourcefn contract_id(&self) -> &str
fn contract_id(&self) -> &str
Get a unique identifier for this contract
Sourcefn operations(&self) -> Vec<ContractOperation>
fn operations(&self) -> Vec<ContractOperation>
Get all operations/methods/topics defined in this contract
Sourcefn get_operation(&self, operation_id: &str) -> Option<&ContractOperation>
fn get_operation(&self, operation_id: &str) -> Option<&ContractOperation>
Get a specific operation by identifier
Sourcefn 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 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
Sourcefn 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 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
Sourcefn get_schema(&self, operation_id: &str) -> Option<Value>
fn get_schema(&self, operation_id: &str) -> Option<Value>
Get schema information for an operation
Returns a JSON-serializable representation of the schema
Sourcefn to_json(&self) -> Result<Value, ContractError>
fn to_json(&self) -> Result<Value, ContractError>
Serialize the contract to a JSON representation