nyquest_interface/blocking/
any.rs1use std::any::Any;
11use std::fmt;
12use std::sync::Arc;
13
14use super::backend::BlockingResponse;
15use super::Request;
16use crate::client::ClientOptions;
17use crate::Result;
18
19pub trait AnyBlockingBackend: Send + Sync + 'static {
23 fn create_blocking_client(&self, options: ClientOptions) -> Result<Arc<dyn AnyBlockingClient>>;
25}
26
27pub trait AnyBlockingClient: Any + Send + Sync + 'static {
31 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
33 fn request(&self, req: Request) -> crate::Result<Box<dyn AnyBlockingResponse>>;
35}
36
37pub trait AnyBlockingResponse: super::MaybeRead + Any + Send + Sync + 'static {
42 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
44 fn status(&self) -> u16;
46 fn content_length(&self) -> Option<u64>;
48 fn get_header(&self, header: &str) -> crate::Result<Vec<String>>;
50 fn text(&mut self) -> crate::Result<String>;
52 fn bytes(&mut self) -> crate::Result<Vec<u8>>;
54}
55
56impl<B> AnyBlockingBackend for B
60where
61 B: super::backend::BlockingBackend,
62{
63 fn create_blocking_client(&self, options: ClientOptions) -> Result<Arc<dyn AnyBlockingClient>> {
64 Ok(Arc::new(self.create_blocking_client(options)?))
65 }
66}
67
68impl<R> AnyBlockingResponse for R
69where
70 R: BlockingResponse,
71{
72 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 BlockingResponse::describe(self, f)
74 }
75
76 fn status(&self) -> u16 {
77 BlockingResponse::status(self)
78 }
79
80 fn content_length(&self) -> Option<u64> {
81 BlockingResponse::content_length(self)
82 }
83
84 fn get_header(&self, header: &str) -> crate::Result<Vec<String>> {
85 BlockingResponse::get_header(self, header)
86 }
87
88 fn text(&mut self) -> crate::Result<String> {
89 BlockingResponse::text(self)
90 }
91
92 fn bytes(&mut self) -> crate::Result<Vec<u8>> {
93 BlockingResponse::bytes(self)
94 }
95}
96
97impl<B> AnyBlockingClient for B
98where
99 B: super::backend::BlockingClient,
100{
101 fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102 super::backend::BlockingClient::describe(self, f)
103 }
104 fn request(&self, req: Request) -> crate::Result<Box<dyn AnyBlockingResponse>> {
105 Ok(Box::new(self.request(req)?))
106 }
107}