use std::fmt::Debug;
use std::sync::Arc;
use nyquest_interface::{blocking::AnyBlockingClient, register::BACKEND};
use super::{response::Response, Request};
use crate::client::ClientBuilder;
#[derive(Clone)]
pub struct BlockingClient {
pub(super) client: Arc<dyn AnyBlockingClient>,
}
impl ClientBuilder {
pub fn build_blocking(self) -> crate::Result<BlockingClient> {
Ok(BlockingClient {
client: BACKEND
.get()
.expect("No backend registered. Please find a backend crate (e.g. nyquest-preset) and call the `register` method at program startup.")
.create_blocking_client(self.options)?,
})
}
}
impl BlockingClient {
pub fn request(&self, req: Request) -> crate::Result<Response> {
let res = self.client.request(req.inner)?;
Ok(res.into())
}
}
impl Debug for BlockingClient {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.client.describe(f)
}
}