orientdb_client/common/
mod.rs1pub mod protocol;
2pub mod types;
3
4pub use crate::common::types::error::OrientError;
5
6#[derive(Debug)]
7pub enum DatabaseType {
8 Memory,
9 PLocal,
10}
11
12impl DatabaseType {
13 pub fn as_str(&self) -> &str {
14 match self {
15 DatabaseType::Memory => "memory",
16 DatabaseType::PLocal => "plocal",
17 }
18 }
19}
20
21pub type OrientResult<T> = Result<T, OrientError>;
22
23#[derive(Clone, Debug)]
24pub struct ConnectionOptions {
25 pub(crate) host: String,
26 pub(crate) port: u16,
27 pub(crate) pool_size: u32,
28}
29
30impl Default for ConnectionOptions {
31 fn default() -> ConnectionOptions {
32 ConnectionOptions {
33 host: String::from("localhost"),
34 port: 2424,
35 pool_size: 10,
36 }
37 }
38}
39
40impl ConnectionOptions {
41 pub fn builder() -> ConnectionOptionsBuilder {
42 ConnectionOptionsBuilder(ConnectionOptions::default())
43 }
44}
45
46impl Into<ConnectionOptions> for (&str, u16) {
47 fn into(self) -> ConnectionOptions {
48 ConnectionOptions {
49 host: String::from(self.0),
50 port: self.1,
51 ..Default::default()
52 }
53 }
54}
55
56impl Into<ConnectionOptions> for (String, u16) {
57 fn into(self) -> ConnectionOptions {
58 ConnectionOptions {
59 host: self.0,
60 port: self.1,
61 ..Default::default()
62 }
63 }
64}
65
66impl Into<ConnectionOptions> for &str {
67 fn into(self) -> ConnectionOptions {
68 ConnectionOptions {
69 host: String::from(self),
70 ..Default::default()
71 }
72 }
73}
74
75pub struct ConnectionOptionsBuilder(ConnectionOptions);
76
77impl ConnectionOptionsBuilder {
78 pub fn host<T>(mut self, host: T) -> Self
79 where
80 T: Into<String>,
81 {
82 self.0.host = host.into();
83 self
84 }
85
86 pub fn port(mut self, port: u16) -> Self {
87 self.0.port = port;
88 self
89 }
90
91 pub fn pool_size(mut self, pool_size: u32) -> Self {
92 self.0.pool_size = pool_size;
93 self
94 }
95
96 pub fn build(self) -> ConnectionOptions {
97 self.0
98 }
99}