Skip to main content

surrealdb/api/method/
unset.rs

1use std::borrow::Cow;
2use std::future::IntoFuture;
3
4use crate::Surreal;
5use crate::api::conn::Command;
6use crate::api::method::BoxFuture;
7use crate::api::{Connection, Result};
8use crate::method::OnceLockExt;
9
10/// An unset future
11#[derive(Debug)]
12#[must_use = "futures do nothing unless you `.await` or poll them"]
13pub struct Unset<'r, C: Connection> {
14	pub(super) client: Cow<'r, Surreal<C>>,
15	pub(super) key: String,
16}
17
18impl<C> Unset<'_, C>
19where
20	C: Connection,
21{
22	/// Converts to an owned type which can easily be moved to a different
23	/// thread
24	pub fn into_owned(self) -> Unset<'static, C> {
25		Unset {
26			client: Cow::Owned(self.client.into_owned()),
27			..self
28		}
29	}
30}
31
32impl<'r, Client> IntoFuture for Unset<'r, Client>
33where
34	Client: Connection,
35{
36	type Output = Result<()>;
37	type IntoFuture = BoxFuture<'r, Self::Output>;
38
39	fn into_future(self) -> Self::IntoFuture {
40		Box::pin(async move {
41			let router = self.client.inner.router.extract()?;
42			router
43				.execute_unit(Command::Unset {
44					key: self.key,
45				})
46				.await
47		})
48	}
49}