Skip to main content

redup_bootstrap_client/clients/
info.rs

1//! Клиент `redup.bootstrap.v1.Info`.
2
3use redup_bootstrap_grpc::CallContext;
4use tonic::Request;
5use tonic::transport::Channel;
6
7use super::clients;
8use crate::error::ClientError;
9use crate::factory::{Calls, Settings};
10use redup_bootstrap_grpc::contracts::redup::bootstrap::v1::InstanceInfo;
11use redup_bootstrap_grpc::contracts::redup::bootstrap::v1::info_client::InfoClient as Generated;
12
13/// Путь метода сведений.
14const EXPLAIN: &str = "/redup.bootstrap.v1.Info/Explain";
15
16/// Клиент сведений об инстансе.
17pub struct InfoClient {
18    calls: Calls,
19    plain: Generated<Channel>,
20    _compressed: Option<Generated<Channel>>,
21    _settings: std::sync::Arc<Settings>,
22}
23
24impl InfoClient {
25    pub(crate) fn new(calls: Calls, channel: Channel) -> Self {
26        let (plain, compressed, settings) = clients!(Generated<Channel>, calls, channel);
27        Self {
28            calls,
29            plain,
30            _compressed: compressed,
31            _settings: settings,
32        }
33    }
34
35    /// Состояние инстанса со всеми модулями.
36    ///
37    /// # Ошибки
38    ///
39    /// Сосед недоступен — `UNAVAILABLE`.
40    pub async fn explain(&mut self, context: &CallContext) -> Result<InstanceInfo, ClientError> {
41        let calls = self.calls.clone();
42        let (request, timeout, trace) = calls.prepare(Request::new(()), context, false);
43        let response = calls
44            .unary(
45                EXPLAIN,
46                context,
47                timeout,
48                trace,
49                self.plain.explain(request),
50            )
51            .await?;
52        Ok(response.into_inner())
53    }
54}