[−][src]Function kasa_exporter::exporter::service
pub fn service<T>(
client: Arc<Client<T>>
) -> impl Fn(Request<Body>) -> Box<dyn Future<Item = Response<Body>, Error = Error> + Send> where
T: Connect + Sync + 'static,
Implements an exporter for a given client.
Examples
use std::net; use std::sync::Arc; use futures::future; use futures::future::Future; use futures::stream; use futures::stream::Stream; use tokio; use hyper; fn main() { let http_client = hyper::Client::builder() .build::<_, hyper::Body>(hyper_tls::HttpsConnector::new(1).unwrap()); tokio::run( kasa_exporter::kasa::Client::new( http_client, "ebpf_exporter".to_string(), "foo@bar.com".to_string(), "123".to_string(), ) .map_err(|e| eprintln!("kasa authentication error: {}", e)) .and_then(move |client| { let client = Arc::new(client); hyper::Server::bind(&"[::1]:12345".parse().unwrap()) .serve(move || hyper::service::service_fn(kasa_exporter::exporter::service(Arc::clone(&client)))) .map_err(|e| eprintln!("server error: {}", e)) }), ); }