nyquest_interface/blocking/
any.rs1use std::fmt;
11use std::{any::Any, io};
12
13use super::backend::BlockingResponse;
14use super::Request;
15use crate::client::ClientOptions;
16use crate::Result;
17
18pub trait AnyBlockingBackend: Send + Sync + 'static {
22 fn create_blocking_client(&self, options: ClientOptions) -> Result<Box<dyn AnyBlockingClient>>;
24}
25
26pub trait AnyBlockingClient: Any + Send + Sync + 'static {
30 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
32 fn clone_boxed(&self) -> Box<dyn AnyBlockingClient>;
34 fn request(&self, req: Request) -> crate::Result<Box<dyn AnyBlockingResponse>>;
36}
37
38pub trait AnyBlockingResponse: io::Read + Any + Send + Sync + 'static {
43 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
45 fn status(&self) -> u16;
47 fn content_length(&self) -> Option<u64>;
49 fn get_header(&self, header: &str) -> crate::Result<Vec<String>>;
51 fn text(&mut self) -> crate::Result<String>;
53 fn bytes(&mut self) -> crate::Result<Vec<u8>>;
55}
56
57impl<B> AnyBlockingBackend for B
61where
62 B: super::backend::BlockingBackend,
63{
64 fn create_blocking_client(&self, options: ClientOptions) -> Result<Box<dyn AnyBlockingClient>> {
65 Ok(Box::new(self.create_blocking_client(options)?))
66 }
67}
68
69impl<R> AnyBlockingResponse for R
70where
71 R: BlockingResponse,
72{
73 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74 BlockingResponse::describe(self, f)
75 }
76
77 fn status(&self) -> u16 {
78 BlockingResponse::status(self)
79 }
80
81 fn content_length(&self) -> Option<u64> {
82 BlockingResponse::content_length(self)
83 }
84
85 fn get_header(&self, header: &str) -> crate::Result<Vec<String>> {
86 BlockingResponse::get_header(self, header)
87 }
88
89 fn text(&mut self) -> crate::Result<String> {
90 BlockingResponse::text(self)
91 }
92
93 fn bytes(&mut self) -> crate::Result<Vec<u8>> {
94 BlockingResponse::bytes(self)
95 }
96}
97
98impl<B> AnyBlockingClient for B
99where
100 B: super::backend::BlockingClient,
101{
102 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103 super::backend::BlockingClient::describe(self, f)
104 }
105 fn clone_boxed(&self) -> Box<dyn AnyBlockingClient> {
106 Box::new(self.clone())
107 }
108 fn request(&self, req: Request) -> crate::Result<Box<dyn AnyBlockingResponse>> {
109 Ok(Box::new(self.request(req)?))
110 }
111}