]> git.proxmox.com Git - proxmox.git/commitdiff
client: impl HttpApiClient for refs, Arcs and Rcs
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 9 Aug 2023 13:29:00 +0000 (15:29 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 9 Aug 2023 13:29:38 +0000 (15:29 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-client/src/lib.rs

index f8fa273e9e9aae2fb5be13d9136c7cf84fbbd004..12b8857b216c803ee3d86732ee0b50347ce6d098 100644 (file)
@@ -21,7 +21,7 @@ pub use client::{Client, TlsOptions};
 
 /// HTTP client backend trait. This should be implemented for a HTTP client capable of making
 /// *authenticated* API requests to a proxmox HTTP API.
-pub trait HttpApiClient: Send + Sync {
+pub trait HttpApiClient {
     /// An API call should return a status code and the raw body.
     type ResponseFuture<'a>: Future<Output = Result<HttpApiResponse, Error>> + 'a
     where
@@ -160,3 +160,108 @@ impl<T> RawApiResponse<T> {
         })
     }
 }
+
+impl<'c, C> HttpApiClient for &'c C
+where
+    C: HttpApiClient,
+{
+    type ResponseFuture<'a> = C::ResponseFuture<'a>
+    where
+        Self: 'a;
+
+    fn get<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::get(self, path_and_query)
+    }
+
+    fn post<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize,
+    {
+        C::post(self, path_and_query, params)
+    }
+
+    fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize,
+    {
+        C::put(self, path_and_query, params)
+    }
+
+    fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::put_without_body(self, path_and_query)
+    }
+
+    fn delete<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::delete(self, path_and_query)
+    }
+}
+
+impl<C> HttpApiClient for std::sync::Arc<C>
+where
+    C: HttpApiClient,
+{
+    type ResponseFuture<'a> = C::ResponseFuture<'a>
+    where
+        Self: 'a;
+
+    fn get<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::get(self, path_and_query)
+    }
+
+    fn post<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize,
+    {
+        C::post(self, path_and_query, params)
+    }
+
+    fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize,
+    {
+        C::put(self, path_and_query, params)
+    }
+
+    fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::put_without_body(self, path_and_query)
+    }
+
+    fn delete<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::delete(self, path_and_query)
+    }
+}
+
+impl<C> HttpApiClient for std::rc::Rc<C>
+where
+    C: HttpApiClient,
+{
+    type ResponseFuture<'a> = C::ResponseFuture<'a>
+    where
+        Self: 'a;
+
+    fn get<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::get(self, path_and_query)
+    }
+
+    fn post<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize,
+    {
+        C::post(self, path_and_query, params)
+    }
+
+    fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize,
+    {
+        C::put(self, path_and_query, params)
+    }
+
+    fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::put_without_body(self, path_and_query)
+    }
+
+    fn delete<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        C::delete(self, path_and_query)
+    }
+}