surrealdb/api/method/
import.rs1use crate::api::conn::Method;
2use crate::api::conn::Param;
3use crate::api::conn::Router;
4use crate::api::Connection;
5use crate::api::Error;
6use crate::api::ExtraFeatures;
7use crate::api::Result;
8use std::future::Future;
9use std::future::IntoFuture;
10use std::path::PathBuf;
11use std::pin::Pin;
12
13#[derive(Debug)]
15#[must_use = "futures do nothing unless you `.await` or poll them"]
16pub struct Import<'r, C: Connection> {
17 pub(super) router: Result<&'r Router<C>>,
18 pub(super) file: PathBuf,
19}
20
21impl<'r, Client> IntoFuture for Import<'r, Client>
22where
23 Client: Connection,
24{
25 type Output = Result<()>;
26 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send + Sync + 'r>>;
27
28 fn into_future(self) -> Self::IntoFuture {
29 Box::pin(async {
30 let router = self.router?;
31 if !router.features.contains(&ExtraFeatures::Backup) {
32 return Err(Error::BackupsNotSupported.into());
33 }
34 let mut conn = Client::new(Method::Import);
35 conn.execute_unit(router, Param::file(self.file)).await
36 })
37 }
38}