StatsPresenter

Trait StatsPresenter 

Source
pub trait StatsPresenter<D: AppDataWrapper> {
    // Required methods
    fn is_ready(&self) -> Pin<Box<dyn Future<Output = Result<bool, Error>>>>;
    fn get_stats(&self) -> Pin<Box<dyn Future<Output = Result<D, Error>>>>;
}
Expand description

Trait to be implemented by AppData if service want to be included in stats handler

Example:

use actix_web::error::Error;
use serde::Serialize;
use serwus::server::stats::StatsPresenter;
use std::future::{Future, ready};
use std::pin::Pin;

#[derive(Serialize)]
pub struct AppStats {
   pub upstream_conn: bool,
   pub client_count: usize,
}

pub struct AppData {
   pub upstream_conn: Option<()>,
   pub clients: Vec<()>,
}

impl StatsPresenter<AppStats> for AppData {
   fn is_ready(&self) -> Pin<Box<dyn Future<Output=Result<bool, Error>>>> {
      Box::pin(ready(Ok(
         self.upstream_conn.is_some()
      )))
   }

   fn get_stats(&self) -> Pin<Box<dyn Future<Output=Result<AppStats, Error>>>> {
      Box::pin(ready(Ok(
         AppStats {
            upstream_conn: self.upstream_conn.is_some(),
            client_count: self.clients.len(),
         }
      )))
   }
}

Required Methods§

Source

fn is_ready(&self) -> Pin<Box<dyn Future<Output = Result<bool, Error>>>>

Source

fn get_stats(&self) -> Pin<Box<dyn Future<Output = Result<D, Error>>>>

Implementors§