rcfe_core/options/
client.rs

1/// Client options for configuring the RCFE client.
2/// # Fields
3/// * `endpoints` - A vector of endpoint strings for connecting to the RCFE server.
4#[derive(Debug, Clone)]
5pub struct ClientOptions {
6    endpoints: Vec<String>,
7}
8
9/// Builder for ClientOptions.
10#[derive(Default, Debug)]
11pub struct ClientOptionsBuilder {
12    endpoints: Vec<String>,
13}
14
15impl ClientOptions {
16    /// Returns the list of endpoints.
17    /// # Returns
18    /// * `&Vec<String>` - A reference to the vector of endpoint strings.
19    /// # Example
20    /// ```rust
21    /// let options = ClientOptions::builder()
22    ///     .endpoints(vec!["http://localhost:2379", "http://localhost:2380"])
23    ///     .build();
24    /// let endpoints = options.endpoints();
25    /// ```
26    pub fn endpoints(&self) -> &Vec<String> {
27        &self.endpoints
28    }
29
30    /// Creates a new ClientOptionsBuilder.
31    /// # Returns
32    /// * `ClientOptionsBuilder` - A new instance of ClientOptionsBuilder.
33    /// # Example
34    /// ```rust
35    /// let builder = ClientOptions::builder();
36    /// ```
37    pub fn builder() -> ClientOptionsBuilder {
38        ClientOptionsBuilder::default()
39    }
40}
41
42impl ClientOptionsBuilder {
43    /// Sets the endpoints for the client.
44    /// # Arguments
45    /// * `endpoints` - An iterable collection of endpoint strings.
46    /// # Returns
47    /// * `Self` - The updated ClientOptionsBuilder.
48    /// # Example
49    /// ```rust
50    /// let builder = ClientOptions::builder()
51    ///     .endpoints(vec!["http://localhost:2379", "http://localhost:2380"]);
52    /// ```
53    pub fn endpoints<I, S>(mut self, endpoints: I) -> Self
54    where
55        I: IntoIterator<Item = S>,
56        S: Into<String>,
57    {
58        let endpoints: Vec<String> = endpoints.into_iter().map(|s| s.into()).collect();
59        {
60            self.endpoints = endpoints;
61            self
62        }
63    }
64
65    /// Builds the ClientOptions.
66    /// # Returns
67    /// * `ClientOptions` - The constructed ClientOptions instance.
68    /// # Example
69    /// ```rust
70    /// let options = ClientOptions::builder()
71    ///     .endpoints(vec!["http://localhost:2379", "http://localhost:2380"])
72    ///     .build();
73    /// ```
74    pub fn build(self) -> ClientOptions {
75        ClientOptions {
76            endpoints: self.endpoints,
77        }
78    }
79}