feature: Add config for query/transaction timeout and notifications (#2340)
This commit is contained in:
parent
278e27db87
commit
c25b85669b
15 changed files with 478 additions and 46 deletions
|
@ -98,6 +98,15 @@ use crate::api::err::Error;
|
||||||
feature = "kv-indxdb",
|
feature = "kv-indxdb",
|
||||||
))]
|
))]
|
||||||
use crate::api::opt::auth::Root;
|
use crate::api::opt::auth::Root;
|
||||||
|
#[cfg(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
))]
|
||||||
|
use crate::api::opt::Config;
|
||||||
use crate::api::opt::Endpoint;
|
use crate::api::opt::Endpoint;
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
feature = "kv-mem",
|
feature = "kv-mem",
|
||||||
|
@ -131,7 +140,7 @@ impl IntoEndpoint for &str {
|
||||||
};
|
};
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(url).map_err(|_| Error::InvalidUrl(self.to_owned()))?,
|
endpoint: Url::parse(url).map_err(|_| Error::InvalidUrl(self.to_owned()))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -205,8 +214,40 @@ where
|
||||||
T: Into<String>,
|
T: Into<String>,
|
||||||
{
|
{
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let mut endpoint = IntoEndpoint::into_endpoint(self.0.into())?;
|
let (address, _) = self;
|
||||||
endpoint.strict = true;
|
let mut endpoint = IntoEndpoint::into_endpoint(address.into())?;
|
||||||
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
))]
|
||||||
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
)))
|
||||||
|
)]
|
||||||
|
impl<T> IntoEndpoint for (T, Config)
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (address, config) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::into_endpoint(address.into())?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,7 +307,36 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (address, _, root) = self;
|
let (address, _, root) = self;
|
||||||
let mut endpoint = IntoEndpoint::into_endpoint((address, root))?;
|
let mut endpoint = IntoEndpoint::into_endpoint((address, root))?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
))]
|
||||||
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
)))
|
||||||
|
)]
|
||||||
|
impl<T> IntoEndpoint for (T, Config, Root<'_>)
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (address, config, root) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::into_endpoint((address, root))?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +372,43 @@ where
|
||||||
let (address, _, config) = self;
|
let (address, _, config) = self;
|
||||||
let mut endpoint = address.into().into_endpoint()?;
|
let mut endpoint = address.into().into_endpoint()?;
|
||||||
endpoint.tls_config = Some(Tls::Native(config));
|
endpoint.tls_config = Some(Tls::Native(config));
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
),
|
||||||
|
feature = "native-tls",
|
||||||
|
))]
|
||||||
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
),
|
||||||
|
feature = "native-tls",
|
||||||
|
)))
|
||||||
|
)]
|
||||||
|
impl<T> IntoEndpoint for (T, Config, native_tls::TlsConnector)
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (address, opt_config, config) = self;
|
||||||
|
let mut endpoint = address.into().into_endpoint()?;
|
||||||
|
endpoint.tls_config = Some(Tls::Native(config));
|
||||||
|
endpoint.config = opt_config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,7 +481,45 @@ where
|
||||||
let (address, _, config) = self;
|
let (address, _, config) = self;
|
||||||
let mut endpoint = address.into().into_endpoint()?;
|
let mut endpoint = address.into().into_endpoint()?;
|
||||||
endpoint.tls_config = Some(Tls::Rust(config));
|
endpoint.tls_config = Some(Tls::Rust(config));
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
),
|
||||||
|
feature = "rustls",
|
||||||
|
))]
|
||||||
|
#[cfg_attr(
|
||||||
|
docsrs,
|
||||||
|
doc(cfg(all(
|
||||||
|
any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
),
|
||||||
|
feature = "rustls",
|
||||||
|
)))
|
||||||
|
)]
|
||||||
|
impl<T> IntoEndpoint for (T, Config, rustls::ClientConfig)
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (address, opt_config, config) = self;
|
||||||
|
let mut endpoint = address.into().into_endpoint()?;
|
||||||
|
endpoint.tls_config = Some(Tls::Rust(config));
|
||||||
|
endpoint.config = opt_config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,15 @@ pub(crate) fn router(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let kvs = kvs.with_strict_mode(address.strict);
|
let kvs = kvs
|
||||||
|
.with_strict_mode(address.config.strict)
|
||||||
|
.with_query_timeout(address.config.query_timeout)
|
||||||
|
.with_transaction_timeout(address.config.transaction_timeout);
|
||||||
|
|
||||||
|
let kvs = match address.config.notifications {
|
||||||
|
true => kvs.with_notifications(),
|
||||||
|
false => kvs,
|
||||||
|
};
|
||||||
|
|
||||||
let mut vars = BTreeMap::new();
|
let mut vars = BTreeMap::new();
|
||||||
let mut stream = route_rx.into_stream();
|
let mut stream = route_rx.into_stream();
|
||||||
|
|
|
@ -102,7 +102,15 @@ pub(crate) fn router(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let kvs = kvs.with_strict_mode(address.strict);
|
let kvs = kvs
|
||||||
|
.with_strict_mode(address.config.strict)
|
||||||
|
.with_query_timeout(address.config.query_timeout)
|
||||||
|
.with_transaction_timeout(address.config.transaction_timeout);
|
||||||
|
|
||||||
|
let kvs = match address.config.notifications {
|
||||||
|
true => kvs.with_notifications(),
|
||||||
|
false => kvs,
|
||||||
|
};
|
||||||
|
|
||||||
let mut vars = BTreeMap::new();
|
let mut vars = BTreeMap::new();
|
||||||
let mut stream = route_rx.into_stream();
|
let mut stream = route_rx.into_stream();
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl IntoEndpoint<Test> for () {
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse("test://")?,
|
endpoint: Url::parse("test://")?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
|
79
lib/src/api/opt/config.rs
Normal file
79
lib/src/api/opt/config.rs
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
/// Configuration for server connection, including: strictness, notifications, query_timeout, transaction_timeout
|
||||||
|
#[cfg(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
))]
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Config {
|
||||||
|
pub(crate) strict: bool,
|
||||||
|
pub(crate) notifications: bool,
|
||||||
|
pub(crate) query_timeout: Option<Duration>,
|
||||||
|
pub(crate) transaction_timeout: Option<Duration>,
|
||||||
|
}
|
||||||
|
#[cfg(not(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
)))]
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Config();
|
||||||
|
|
||||||
|
#[cfg(any(
|
||||||
|
feature = "kv-mem",
|
||||||
|
feature = "kv-tikv",
|
||||||
|
feature = "kv-rocksdb",
|
||||||
|
feature = "kv-speedb",
|
||||||
|
feature = "kv-fdb",
|
||||||
|
feature = "kv-indxdb",
|
||||||
|
))]
|
||||||
|
impl Config {
|
||||||
|
///Create a default config that can be modified to configure a connection
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
///Set the strict value of the config to the supplied value
|
||||||
|
pub fn set_strict(mut self, strict: bool) -> Self {
|
||||||
|
self.strict = strict;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
///Set the config to use strict mode
|
||||||
|
pub fn strict(mut self) -> Self {
|
||||||
|
self.strict = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
///Set the notifications value of the config to the supplied value
|
||||||
|
pub fn set_notifications(mut self, notifications: bool) -> Self {
|
||||||
|
self.notifications = notifications;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
///Set the config to use notifications
|
||||||
|
pub fn notifications(mut self) -> Self {
|
||||||
|
self.notifications = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
///Set the query timeout of the config
|
||||||
|
pub fn query_timeout(mut self, timeout: impl Into<Option<Duration>>) -> Self {
|
||||||
|
self.query_timeout = timeout.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
///Set the transaction timeout of the config
|
||||||
|
pub fn transaction_timeout(mut self, timeout: impl Into<Option<Duration>>) -> Self {
|
||||||
|
self.transaction_timeout = timeout.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ use crate::api::engine::local::Db;
|
||||||
use crate::api::engine::local::FDb;
|
use crate::api::engine::local::FDb;
|
||||||
use crate::api::err::Error;
|
use crate::api::err::Error;
|
||||||
use crate::api::opt::auth::Root;
|
use crate::api::opt::auth::Root;
|
||||||
|
use crate::api::opt::Config;
|
||||||
use crate::api::opt::Endpoint;
|
use crate::api::opt::Endpoint;
|
||||||
use crate::api::opt::IntoEndpoint;
|
use crate::api::opt::IntoEndpoint;
|
||||||
use crate::api::opt::Strict;
|
use crate::api::opt::Strict;
|
||||||
|
@ -17,7 +18,7 @@ impl IntoEndpoint<FDb> for &str {
|
||||||
let url = format!("fdb://{self}");
|
let url = format!("fdb://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -45,7 +46,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _) = self;
|
let (path, _) = self;
|
||||||
let mut endpoint = IntoEndpoint::<FDb>::into_endpoint(path.as_ref())?;
|
let mut endpoint = IntoEndpoint::<FDb>::into_endpoint(path.as_ref())?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<FDb> for (T, Config)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<FDb>::into_endpoint(path.as_ref())?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +90,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _, root) = self;
|
let (path, _, root) = self;
|
||||||
let mut endpoint = IntoEndpoint::<FDb>::into_endpoint((path, root))?;
|
let mut endpoint = IntoEndpoint::<FDb>::into_endpoint((path, root))?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<FDb> for (T, Config, Root<'_>)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config, root) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<FDb>::into_endpoint((path, root))?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl IntoEndpoint<Http> for &str {
|
||||||
let url = format!("http://{self}");
|
let url = format!("http://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -35,7 +35,7 @@ impl IntoEndpoint<Http> for SocketAddr {
|
||||||
let url = format!("http://{self}");
|
let url = format!("http://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -52,7 +52,7 @@ impl IntoEndpoint<Http> for String {
|
||||||
let url = format!("http://{self}");
|
let url = format!("http://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -69,7 +69,7 @@ impl IntoEndpoint<Https> for &str {
|
||||||
let url = format!("https://{self}");
|
let url = format!("https://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -86,7 +86,7 @@ impl IntoEndpoint<Https> for SocketAddr {
|
||||||
let url = format!("https://{self}");
|
let url = format!("https://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -103,7 +103,7 @@ impl IntoEndpoint<Https> for String {
|
||||||
let url = format!("https://{self}");
|
let url = format!("https://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::api::engine::local::Db;
|
||||||
use crate::api::engine::local::IndxDb;
|
use crate::api::engine::local::IndxDb;
|
||||||
use crate::api::err::Error;
|
use crate::api::err::Error;
|
||||||
use crate::api::opt::auth::Root;
|
use crate::api::opt::auth::Root;
|
||||||
|
use crate::api::opt::Config;
|
||||||
use crate::api::opt::Endpoint;
|
use crate::api::opt::Endpoint;
|
||||||
use crate::api::opt::IntoEndpoint;
|
use crate::api::opt::IntoEndpoint;
|
||||||
use crate::api::opt::Strict;
|
use crate::api::opt::Strict;
|
||||||
|
@ -16,7 +17,7 @@ impl IntoEndpoint<IndxDb> for &str {
|
||||||
let url = format!("indxdb://{self}");
|
let url = format!("indxdb://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -30,8 +31,20 @@ impl IntoEndpoint<IndxDb> for (&str, Strict) {
|
||||||
type Client = Db;
|
type Client = Db;
|
||||||
|
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let mut endpoint = IntoEndpoint::<IndxDb>::into_endpoint(self.0)?;
|
let (address, _) = self;
|
||||||
endpoint.strict = true;
|
let mut endpoint = IntoEndpoint::<IndxDb>::into_endpoint(address)?;
|
||||||
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoEndpoint<IndxDb> for (&str, Config) {
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (address, config) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<IndxDb>::into_endpoint(address)?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +68,18 @@ impl IntoEndpoint<IndxDb> for (&str, Strict, Root<'_>) {
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (name, _, root) = self;
|
let (name, _, root) = self;
|
||||||
let mut endpoint = IntoEndpoint::<IndxDb>::into_endpoint((name, root))?;
|
let mut endpoint = IntoEndpoint::<IndxDb>::into_endpoint((name, root))?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoEndpoint<IndxDb> for (&str, Config, Root<'_>) {
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (name, config, root) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<IndxDb>::into_endpoint((name, root))?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::api::opt::IntoEndpoint;
|
||||||
use crate::api::opt::Strict;
|
use crate::api::opt::Strict;
|
||||||
use crate::api::Result;
|
use crate::api::Result;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
|
use crate::opt::Config;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
impl IntoEndpoint<Mem> for () {
|
impl IntoEndpoint<Mem> for () {
|
||||||
|
@ -14,7 +15,7 @@ impl IntoEndpoint<Mem> for () {
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse("mem://").unwrap(),
|
endpoint: Url::parse("mem://").unwrap(),
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -29,7 +30,17 @@ impl IntoEndpoint<Mem> for Strict {
|
||||||
|
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let mut endpoint = IntoEndpoint::<Mem>::into_endpoint(())?;
|
let mut endpoint = IntoEndpoint::<Mem>::into_endpoint(())?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoEndpoint<Mem> for Config {
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let mut endpoint = IntoEndpoint::<Mem>::into_endpoint(())?;
|
||||||
|
endpoint.config = self;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +63,18 @@ impl IntoEndpoint<Mem> for (Strict, Root<'_>) {
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (_, root) = self;
|
let (_, root) = self;
|
||||||
let mut endpoint = IntoEndpoint::<Mem>::into_endpoint(root)?;
|
let mut endpoint = IntoEndpoint::<Mem>::into_endpoint(root)?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoEndpoint<Mem> for (Config, Root<'_>) {
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (config, root) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<Mem>::into_endpoint(root)?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,15 @@ use crate::api::Result;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
use super::Config;
|
||||||
|
|
||||||
/// A server address used to connect to the server
|
/// A server address used to connect to the server
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[allow(dead_code)] // used by the embedded and remote connections
|
#[allow(dead_code)] // used by the embedded and remote connections
|
||||||
pub struct Endpoint {
|
pub struct Endpoint {
|
||||||
pub(crate) endpoint: Url,
|
pub(crate) endpoint: Url,
|
||||||
#[allow(dead_code)] // used by the embedded database
|
#[allow(dead_code)] // used by the embedded database
|
||||||
pub(crate) strict: bool,
|
pub(crate) config: Config,
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
pub(crate) tls_config: Option<super::Tls>,
|
pub(crate) tls_config: Option<super::Tls>,
|
||||||
// Only used by the local engines
|
// Only used by the local engines
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::api::engine::local::File;
|
||||||
use crate::api::engine::local::RocksDb;
|
use crate::api::engine::local::RocksDb;
|
||||||
use crate::api::err::Error;
|
use crate::api::err::Error;
|
||||||
use crate::api::opt::auth::Root;
|
use crate::api::opt::auth::Root;
|
||||||
|
use crate::api::opt::Config;
|
||||||
use crate::api::opt::Endpoint;
|
use crate::api::opt::Endpoint;
|
||||||
use crate::api::opt::IntoEndpoint;
|
use crate::api::opt::IntoEndpoint;
|
||||||
use crate::api::opt::Strict;
|
use crate::api::opt::Strict;
|
||||||
|
@ -18,7 +19,7 @@ impl IntoEndpoint<RocksDb> for &str {
|
||||||
let url = format!("rocksdb://{self}");
|
let url = format!("rocksdb://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -46,7 +47,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _) = self;
|
let (path, _) = self;
|
||||||
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint(path.as_ref())?;
|
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint(path.as_ref())?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<RocksDb> for (T, Config)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint(path.as_ref())?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +91,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _, root) = self;
|
let (path, _, root) = self;
|
||||||
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint((path.as_ref(), root))?;
|
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint((path.as_ref(), root))?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<RocksDb> for (T, Config, Root<'_>)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config, root) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint((path.as_ref(), root))?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +117,7 @@ impl IntoEndpoint<File> for &str {
|
||||||
let url = format!("file://{self}");
|
let url = format!("file://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -116,7 +145,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _) = self;
|
let (path, _) = self;
|
||||||
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint(path.as_ref())?;
|
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint(path.as_ref())?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<File> for (T, Config)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint(path.as_ref())?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,7 +189,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _, root) = self;
|
let (path, _, root) = self;
|
||||||
let mut endpoint = IntoEndpoint::<File>::into_endpoint((path.as_ref(), root))?;
|
let mut endpoint = IntoEndpoint::<File>::into_endpoint((path.as_ref(), root))?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<File> for (T, Config, Root<'_>)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config, root) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<File>::into_endpoint((path.as_ref(), root))?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::api::engine::local::Db;
|
use crate::api::engine::local::Db;
|
||||||
use crate::api::engine::local::SpeeDb;
|
use crate::api::engine::local::SpeeDb;
|
||||||
use crate::api::err::Error;
|
use crate::api::err::Error;
|
||||||
|
use crate::api::opt::Config;
|
||||||
use crate::api::opt::Endpoint;
|
use crate::api::opt::Endpoint;
|
||||||
use crate::api::opt::IntoEndpoint;
|
use crate::api::opt::IntoEndpoint;
|
||||||
use crate::api::opt::Strict;
|
use crate::api::opt::Strict;
|
||||||
|
@ -17,7 +18,7 @@ impl IntoEndpoint<SpeeDb> for &str {
|
||||||
let url = format!("speedb://{self}");
|
let url = format!("speedb://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -45,7 +46,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _) = self;
|
let (path, _) = self;
|
||||||
let mut endpoint = IntoEndpoint::<SpeeDb>::into_endpoint(path.as_ref())?;
|
let mut endpoint = IntoEndpoint::<SpeeDb>::into_endpoint(path.as_ref())?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<SpeeDb> for (T, Config)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<SpeeDb>::into_endpoint(path.as_ref())?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +90,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (path, _, root) = self;
|
let (path, _, root) = self;
|
||||||
let mut endpoint = IntoEndpoint::<SpeeDb>::into_endpoint((path.as_ref(), root))?;
|
let mut endpoint = IntoEndpoint::<SpeeDb>::into_endpoint((path.as_ref(), root))?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<SpeeDb> for (T, Config, Root<'_>)
|
||||||
|
where
|
||||||
|
T: AsRef<Path>,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (path, config, root) = self;
|
||||||
|
let mut endpoint = IntoEndpoint::<SpeeDb>::into_endpoint((path.as_ref(), root))?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::api::engine::local::Db;
|
||||||
use crate::api::engine::local::TiKv;
|
use crate::api::engine::local::TiKv;
|
||||||
use crate::api::err::Error;
|
use crate::api::err::Error;
|
||||||
use crate::api::opt::auth::Root;
|
use crate::api::opt::auth::Root;
|
||||||
|
use crate::api::opt::Config;
|
||||||
use crate::api::opt::Endpoint;
|
use crate::api::opt::Endpoint;
|
||||||
use crate::api::opt::IntoEndpoint;
|
use crate::api::opt::IntoEndpoint;
|
||||||
use crate::api::opt::Strict;
|
use crate::api::opt::Strict;
|
||||||
|
@ -18,7 +19,7 @@ impl IntoEndpoint<TiKv> for &str {
|
||||||
let url = format!("tikv://{self}");
|
let url = format!("tikv://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -35,7 +36,7 @@ impl IntoEndpoint<TiKv> for SocketAddr {
|
||||||
let url = format!("tikv://{self}");
|
let url = format!("tikv://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -52,7 +53,7 @@ impl IntoEndpoint<TiKv> for String {
|
||||||
let url = format!("tikv://{self}");
|
let url = format!("tikv://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -71,7 +72,20 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (address, _) = self;
|
let (address, _) = self;
|
||||||
let mut endpoint = address.into_endpoint()?;
|
let mut endpoint = address.into_endpoint()?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T> IntoEndpoint<TiKv> for (T, Config)
|
||||||
|
where
|
||||||
|
T: IntoEndpoint<TiKv> + Display,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (address, config) = self;
|
||||||
|
let mut endpoint = address.into_endpoint()?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +115,21 @@ where
|
||||||
fn into_endpoint(self) -> Result<Endpoint> {
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
let (address, _, root) = self;
|
let (address, _, root) = self;
|
||||||
let mut endpoint = (address, root).into_endpoint()?;
|
let mut endpoint = (address, root).into_endpoint()?;
|
||||||
endpoint.strict = true;
|
endpoint.config.strict = true;
|
||||||
|
Ok(endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoEndpoint<TiKv> for (T, Config, Root<'_>)
|
||||||
|
where
|
||||||
|
T: IntoEndpoint<TiKv> + Display,
|
||||||
|
{
|
||||||
|
type Client = Db;
|
||||||
|
|
||||||
|
fn into_endpoint(self) -> Result<Endpoint> {
|
||||||
|
let (address, config, root) = self;
|
||||||
|
let mut endpoint = (address, root).into_endpoint()?;
|
||||||
|
endpoint.config = config;
|
||||||
Ok(endpoint)
|
Ok(endpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl IntoEndpoint<Ws> for &str {
|
||||||
let url = format!("ws://{self}");
|
let url = format!("ws://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -35,7 +35,7 @@ impl IntoEndpoint<Ws> for SocketAddr {
|
||||||
let url = format!("ws://{self}");
|
let url = format!("ws://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -52,7 +52,7 @@ impl IntoEndpoint<Ws> for String {
|
||||||
let url = format!("ws://{self}");
|
let url = format!("ws://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -69,7 +69,7 @@ impl IntoEndpoint<Wss> for &str {
|
||||||
let url = format!("wss://{self}");
|
let url = format!("wss://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -86,7 +86,7 @@ impl IntoEndpoint<Wss> for SocketAddr {
|
||||||
let url = format!("wss://{self}");
|
let url = format!("wss://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
@ -103,7 +103,7 @@ impl IntoEndpoint<Wss> for String {
|
||||||
let url = format!("wss://{self}");
|
let url = format!("wss://{self}");
|
||||||
Ok(Endpoint {
|
Ok(Endpoint {
|
||||||
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
endpoint: Url::parse(&url).map_err(|_| Error::InvalidUrl(url))?,
|
||||||
strict: false,
|
config: Default::default(),
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
tls_config: None,
|
tls_config: None,
|
||||||
auth: Level::No,
|
auth: Level::No,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod endpoint;
|
mod endpoint;
|
||||||
mod query;
|
mod query;
|
||||||
mod resource;
|
mod resource;
|
||||||
|
@ -20,6 +21,7 @@ use serde_json::json;
|
||||||
use serde_json::Map;
|
use serde_json::Map;
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
|
pub use config::*;
|
||||||
pub use endpoint::*;
|
pub use endpoint::*;
|
||||||
pub use query::*;
|
pub use query::*;
|
||||||
pub use resource::*;
|
pub use resource::*;
|
||||||
|
|
Loading…
Reference in a new issue