1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::embedded::EmbeddedConfig;
use crate::{ChannelHandle, ConversationHandle, SdkError};
use super::{RemoteConfig, SdkChannelHandle, SdkConversationHandle};
/// Deployment-mode configuration used by the SDK builders.
#[derive(Clone, Debug)]
pub enum SdkConfig {
/// Direct in-process deployment with no server address or sockets.
Embedded(EmbeddedConfig),
/// Remote deployment using the SDK-internal wire protocol transport.
Remote(RemoteConfig),
}
impl SdkConfig {
/// Creates embedded deployment configuration.
#[must_use]
pub const fn embedded(config: EmbeddedConfig) -> Self {
Self::Embedded(config)
}
/// Creates remote deployment configuration.
#[must_use]
pub const fn remote(config: RemoteConfig) -> Self {
Self::Remote(config)
}
/// Builds a channel handle selected only by this configuration.
///
/// # Errors
///
/// Returns [`SdkError`] if the selected mode cannot be initialized.
pub fn channel_handle(&self) -> Result<SdkChannelHandle, SdkError> {
SdkChannelHandle::new(self)
}
/// Builds a conversation handle selected only by this configuration.
///
/// # Errors
///
/// Returns [`SdkError`] if the selected mode cannot be initialized.
pub fn conversation_handle(&self) -> Result<SdkConversationHandle, SdkError> {
SdkConversationHandle::new(self)
}
}
/// Builds a channel handle selected by [`SdkConfig`].
///
/// # Errors
///
/// Returns [`SdkError`] if the selected mode cannot be initialized.
pub fn build_channel_handle(config: &SdkConfig) -> Result<impl ChannelHandle, SdkError> {
config.channel_handle()
}
/// Builds a conversation handle selected by [`SdkConfig`].
///
/// # Errors
///
/// Returns [`SdkError`] if the selected mode cannot be initialized.
pub fn build_conversation_handle(config: &SdkConfig) -> Result<impl ConversationHandle, SdkError> {
config.conversation_handle()
}