Skip to main content

RequestResponse

Trait RequestResponse 

Source
pub trait RequestResponse<I, O>: Provider
where I: Send + 'static, O: Send + 'static,
{ // Required method fn execute<'life0, 'async_trait>( &'life0 self, input: I, ) -> Pin<Box<dyn Future<Output = Result<O, AppError>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; }
Expand description

Unary request → single response (HTTP POST, gRPC unary, DB query).

§Example

use rskit_errors::AppResult;
use rskit_provider::{Provider, RequestResponse};

struct Echo;

impl Provider for Echo {
    fn name(&self) -> &'static str {
        "echo"
    }
}

#[async_trait::async_trait]
impl RequestResponse<String, String> for Echo {
    async fn execute(&self, input: String) -> AppResult<String> {
        Ok(input.to_uppercase())
    }
}

let response = Echo.execute("hello".to_string()).await?;
assert_eq!(response, "HELLO");

Required Methods§

Source

fn execute<'life0, 'async_trait>( &'life0 self, input: I, ) -> Pin<Box<dyn Future<Output = Result<O, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Execute the request and return a single response.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl RequestResponse<EmbedRequest, EmbedResponse> for EmbeddingProvider

Source§

fn execute<'life0, 'async_trait>( &'life0 self, input: EmbedRequest, ) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, EmbeddingProvider: 'async_trait,

Source§

impl RequestResponse<EmbedRequest, EmbedResponse> for InMemoryProvider

Source§

fn execute<'life0, 'async_trait>( &'life0 self, input: EmbedRequest, ) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, InMemoryProvider: 'async_trait,

Source§

impl RequestResponse<PredictRequest, PredictResponse> for Echo

Source§

fn execute<'life0, 'async_trait>( &'life0 self, input: PredictRequest, ) -> Pin<Box<dyn Future<Output = Result<PredictResponse, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Echo: 'async_trait,

Source§

impl<I, O> RequestResponse<I, O> for DagTool<I, O>
where I: Send + 'static, O: Send + 'static,

Source§

fn execute<'life0, 'async_trait>( &'life0 self, input: I, ) -> Pin<Box<dyn Future<Output = Result<O, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, DagTool<I, O>: 'async_trait,

Source§

impl<P> RequestResponse<CompletionRequest, CompletionResponse> for LlmRequestResponse<P>
where P: Provider + 'static,

Source§

fn execute<'life0, 'async_trait>( &'life0 self, input: CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, LlmRequestResponse<P>: 'async_trait,

Implementors§

Source§

impl<S, I, O> RequestResponse<I, O> for TowerProvider<S, I, O>
where S: Service<I, Response = O, Error = AppError> + Send + Clone + 'static, <S as Service<I>>::Future: Send + 'static, I: Send + 'static, O: Send + 'static,