surrealdb/api/opt/endpoint/
rocksdb.rs

1use crate::api::engine::local::Db;
2#[allow(deprecated)]
3use crate::api::engine::local::File;
4use crate::api::engine::local::RocksDb;
5use crate::api::opt::Config;
6use crate::api::opt::Endpoint;
7use crate::api::opt::IntoEndpoint;
8use crate::api::Result;
9use std::path::Path;
10use std::path::PathBuf;
11use url::Url;
12
13macro_rules! endpoints {
14	($($name:ty),*) => {
15		$(
16			impl IntoEndpoint<RocksDb> for $name {
17				type Client = Db;
18
19				fn into_endpoint(self) -> Result<Endpoint> {
20					let protocol = "rocksdb://";
21					let url = Url::parse(protocol)
22					    .unwrap_or_else(|_| unreachable!("`{protocol}` should be static and valid"));
23					let mut endpoint = Endpoint::new(url);
24					endpoint.path = super::path_to_string(protocol, self);
25					Ok(endpoint)
26				}
27			}
28
29			impl IntoEndpoint<RocksDb> for ($name, Config) {
30				type Client = Db;
31
32				fn into_endpoint(self) -> Result<Endpoint> {
33					let mut endpoint = IntoEndpoint::<RocksDb>::into_endpoint(self.0)?;
34					endpoint.config = self.1;
35					Ok(endpoint)
36				}
37			}
38
39			#[allow(deprecated)]
40			impl IntoEndpoint<File> for $name {
41				type Client = Db;
42
43				fn into_endpoint(self) -> Result<Endpoint> {
44					let protocol = "file://";
45					let url = Url::parse(protocol)
46					    .unwrap_or_else(|_| unreachable!("`{protocol}` should be static and valid"));
47					let mut endpoint = Endpoint::new(url);
48					endpoint.path = super::path_to_string(protocol, self);
49					Ok(endpoint)
50				}
51			}
52
53			#[allow(deprecated)]
54			impl IntoEndpoint<File> for ($name, Config) {
55				type Client = Db;
56
57				fn into_endpoint(self) -> Result<Endpoint> {
58					let mut endpoint = IntoEndpoint::<File>::into_endpoint(self.0)?;
59					endpoint.config = self.1;
60					Ok(endpoint)
61				}
62			}
63		)*
64	}
65}
66
67endpoints!(&str, &String, String, &Path, PathBuf);