rcfe_core/options/kv.rs
1use crate::error::Error;
2use tonic::transport::Channel;
3
4/// Options for KVClient
5#[derive(Debug, Clone)]
6pub struct KVOptions {
7 channel: Channel,
8}
9
10/// Builder for KVOptions
11#[derive(Debug, Clone)]
12pub struct KVOptionsBuilder {
13 channel: Option<Channel>,
14}
15
16impl KVOptions {
17 pub fn channel(self) -> Channel {
18 self.channel
19 }
20
21 /// Creates a builder for KVOptions
22 /// # Examples
23 /// ```rust
24 /// use rcfe_core::options::kv::{KVOptions, KVOptionsBuilder};
25 /// use tonic::transport::Channel;
26 /// let channel = Channel::from_static("http://localhost:2379");
27 /// let kv_options = KVOptions::builder()
28 /// .channel(channel)
29 /// .build()
30 /// .unwrap();
31 /// ```
32 pub fn builder() -> KVOptionsBuilder {
33 KVOptionsBuilder { channel: None }
34 }
35}
36
37impl KVOptionsBuilder {
38 pub fn channel(mut self, channel: Channel) -> Self {
39 self.channel = Some(channel);
40 self
41 }
42
43 /// Builds the KVOptions
44 /// # Errors
45 /// Returns an Error if the channel is not specified
46 /// # Examples
47 /// ```rust
48 /// use rcfe_core::options::kv::{KVOptions, KVOptionsBuilder};
49 /// use tonic::transport::Channel;
50 /// let channel = Channel::from_static("http://localhost:2379");
51 /// let kv_options = KVOptions::builder()
52 /// .channel(channel)
53 /// .build()
54 /// .unwrap();
55 /// ```
56 pub fn build(self) -> Result<KVOptions, Error> {
57 let channel = self.channel.ok_or(Error::IllegalArgument(String::from(
58 "channel not specified",
59 )))?;
60 Ok(KVOptions { channel })
61 }
62}