Skip to main content

cloud_hypervisor_client/apis/
configuration.rs

1/*
2 * Cloud Hypervisor API
3 *
4 * Local HTTP based API for managing and inspecting a cloud-hypervisor virtual machine.
5 *
6 * The version of the OpenAPI document: 0.3.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use hyper;
12use hyper_util::client::legacy::Client;
13use hyper_util::client::legacy::connect::Connect;
14use hyper_util::client::legacy::connect::HttpConnector;
15use hyper_util::rt::TokioExecutor;
16
17pub struct Configuration<C: Connect = HttpConnector>
18where
19    C: Clone + std::marker::Send + Sync + 'static,
20{
21    pub base_path: String,
22    pub user_agent: Option<String>,
23    pub client: Client<C, String>,
24}
25
26impl Configuration<HttpConnector> {
27    /// Construct a default [`Configuration`](Self) with a hyper client using a default
28    /// [`HttpConnector`](hyper_util::client::legacy::connect::HttpConnector).
29    ///
30    /// Use [`with_client`](Configuration<T>::with_client) to construct a Configuration with a
31    /// custom hyper client.
32    ///
33    /// # Example
34    ///
35    /// ```
36    /// # use cloud_hypervisor_client::apis::configuration::Configuration;
37    /// let api_config = Configuration::new();
38    /// ```
39    pub fn new() -> Configuration<HttpConnector> {
40        Configuration::default()
41    }
42}
43
44impl<C: Connect> Configuration<C>
45where
46    C: Clone + std::marker::Send + Sync,
47{
48    /// Construct a new Configuration with a custom hyper client.
49    ///
50    /// # Example
51    ///
52    /// ```
53    /// # use core::time::Duration;
54    /// # use cloud_hypervisor_client::apis::configuration::Configuration;
55    /// use hyper_util::client::legacy::Client;
56    /// use hyper_util::rt::TokioExecutor;
57    ///
58    /// let client = Client::builder(TokioExecutor::new())
59    ///   .pool_idle_timeout(Duration::from_secs(30))
60    ///   .build_http();
61    ///
62    /// let api_config = Configuration::with_client(client);
63    /// ```
64    pub fn with_client(client: Client<C, String>) -> Configuration<C> {
65        Configuration {
66            base_path: "http://localhost/api/v1".to_owned(),
67            user_agent: Some("cloud-hypervisor-client/0.3.0".to_owned()),
68            client,
69        }
70    }
71}
72
73impl Default for Configuration<HttpConnector> {
74    fn default() -> Self {
75        let client = Client::builder(TokioExecutor::new()).build_http();
76        Configuration::with_client(client)
77    }
78}