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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
pub mod protocol; pub mod types; pub use crate::common::types::error::OrientError; #[derive(Debug)] pub enum DatabaseType { Memory, PLocal, } impl DatabaseType { pub fn as_str(&self) -> &str { match self { DatabaseType::Memory => "memory", DatabaseType::PLocal => "plocal", } } } pub type OrientResult<T> = Result<T, OrientError>; #[derive(Clone, Debug)] pub struct ConnectionOptions { pub(crate) host: String, pub(crate) port: u16, pub(crate) pool_size: u32, } impl Default for ConnectionOptions { fn default() -> ConnectionOptions { ConnectionOptions { host: String::from("localhost"), port: 2424, pool_size: 10, } } } impl ConnectionOptions { pub fn builder() -> ConnectionOptionsBuilder { ConnectionOptionsBuilder(ConnectionOptions::default()) } } impl Into<ConnectionOptions> for (&str, u16) { fn into(self) -> ConnectionOptions { ConnectionOptions { host: String::from(self.0), port: self.1, ..Default::default() } } } impl Into<ConnectionOptions> for (String, u16) { fn into(self) -> ConnectionOptions { ConnectionOptions { host: self.0, port: self.1, ..Default::default() } } } impl Into<ConnectionOptions> for &str { fn into(self) -> ConnectionOptions { ConnectionOptions { host: String::from(self), ..Default::default() } } } pub struct ConnectionOptionsBuilder(ConnectionOptions); impl ConnectionOptionsBuilder { pub fn host<T>(mut self, host: T) -> Self where T: Into<String>, { self.0.host = host.into(); self } pub fn port(mut self, port: u16) -> Self { self.0.port = port; self } pub fn pool_size(mut self, pool_size: u32) -> Self { self.0.pool_size = pool_size; self } pub fn build(self) -> ConnectionOptions { self.0 } }