gestalt-sdk 0.0.1-alpha.19

Rust SDK scaffolding and generated protocol bindings for Gestalt executable providers
Documentation
// Code generated by sdkgen. DO NOT EDIT.

//! Generated native types and clients for test.proto.

use crate::codec::test::{from_wire_hello_world_response, to_wire_hello_world_request};
use crate::generated::v1;
use crate::rpc_support::GestaltError;

/// HelloWorldRequest carries no input fields. It exists to exercise the
/// provider-kind-specific request/response path.
///
/// Native message type for `gestalt.provider.v1.HelloWorldRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HelloWorldRequest {}

/// HelloWorldResponse returns the fixed test-provider message.
///
/// Native message type for `gestalt.provider.v1.HelloWorldResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HelloWorldResponse {
    /// The `message` field.
    pub message: String,
}

/// Test models a minimal provider-kind-specific protocol used to verify new
/// provider kind registration and lifecycle wiring.
///
/// Client for the `gestalt.provider.v1.Test` service.
pub struct Test {
    inner: v1::test_client::TestClient<tonic::transport::Channel>,
    timeout: Option<std::time::Duration>,
}

impl Test {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::test_client::TestClient::new(channel),
            timeout: None,
        }
    }

    /// Sets a deadline applied to every unary call; calls that run past it
    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    /// Calls `gestalt.provider.v1.Test.HelloWorld`.
    pub async fn hello_world(
        &mut self,
        request: HelloWorldRequest,
    ) -> Result<String, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = from_wire_hello_world_response(
            self.inner.hello_world(tonic_request).await?.into_inner(),
        );
        Ok(response.message)
    }

    /// Calls `gestalt.provider.v1.Test.HelloWorld` with the full request and response messages.
    pub async fn hello_world_raw(
        &mut self,
        request: HelloWorldRequest,
    ) -> Result<HelloWorldResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_hello_world_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.hello_world(tonic_request).await?;
        Ok(from_wire_hello_world_response(response.into_inner()))
    }
}