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