redup-bootstrap-client 0.3.0

Фабрика клиентов gRPC и клиенты инфраструктурных контрактов.
Documentation
//! Клиент `redup.bootstrap.v1.Info`.

use redup_bootstrap_grpc::CallContext;
use tonic::Request;
use tonic::transport::Channel;

use super::clients;
use crate::error::ClientError;
use crate::factory::{Calls, Settings};
use redup_bootstrap_grpc::contracts::redup::bootstrap::v1::InstanceInfo;
use redup_bootstrap_grpc::contracts::redup::bootstrap::v1::info_client::InfoClient as Generated;

/// Путь метода сведений.
const EXPLAIN: &str = "/redup.bootstrap.v1.Info/Explain";

/// Клиент сведений об инстансе.
pub struct InfoClient {
    calls: Calls,
    plain: Generated<Channel>,
    _compressed: Option<Generated<Channel>>,
    _settings: std::sync::Arc<Settings>,
}

impl InfoClient {
    pub(crate) fn new(calls: Calls, channel: Channel) -> Self {
        let (plain, compressed, settings) = clients!(Generated<Channel>, calls, channel);
        Self {
            calls,
            plain,
            _compressed: compressed,
            _settings: settings,
        }
    }

    /// Состояние инстанса со всеми модулями.
    ///
    /// # Ошибки
    ///
    /// Сосед недоступен — `UNAVAILABLE`.
    pub async fn explain(&mut self, context: &CallContext) -> Result<InstanceInfo, ClientError> {
        let calls = self.calls.clone();
        let (request, timeout, trace) = calls.prepare(Request::new(()), context, false);
        let response = calls
            .unary(
                EXPLAIN,
                context,
                timeout,
                trace,
                self.plain.explain(request),
            )
            .await?;
        Ok(response.into_inner())
    }
}