2022-12-30 08:23:19 +00:00
|
|
|
use crate::api::conn::Method;
|
|
|
|
use crate::api::conn::Param;
|
2024-07-19 10:09:54 +00:00
|
|
|
use crate::api::method::BoxFuture;
|
2022-12-30 08:23:19 +00:00
|
|
|
use crate::api::Connection;
|
|
|
|
use crate::api::Result;
|
2023-12-01 15:25:28 +00:00
|
|
|
use crate::method::OnceLockExt;
|
|
|
|
use crate::Surreal;
|
|
|
|
use std::borrow::Cow;
|
2022-12-30 08:23:19 +00:00
|
|
|
use std::future::IntoFuture;
|
|
|
|
|
|
|
|
/// An unset future
|
|
|
|
#[derive(Debug)]
|
2023-04-19 08:26:22 +00:00
|
|
|
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
2022-12-30 08:23:19 +00:00
|
|
|
pub struct Unset<'r, C: Connection> {
|
2023-12-01 15:25:28 +00:00
|
|
|
pub(super) client: Cow<'r, Surreal<C>>,
|
2022-12-30 08:23:19 +00:00
|
|
|
pub(super) key: String,
|
|
|
|
}
|
|
|
|
|
2023-12-01 15:25:28 +00:00
|
|
|
impl<C> Unset<'_, C>
|
|
|
|
where
|
|
|
|
C: Connection,
|
|
|
|
{
|
|
|
|
/// Converts to an owned type which can easily be moved to a different thread
|
|
|
|
pub fn into_owned(self) -> Unset<'static, C> {
|
|
|
|
Unset {
|
|
|
|
client: Cow::Owned(self.client.into_owned()),
|
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 08:23:19 +00:00
|
|
|
impl<'r, Client> IntoFuture for Unset<'r, Client>
|
|
|
|
where
|
|
|
|
Client: Connection,
|
|
|
|
{
|
|
|
|
type Output = Result<()>;
|
2024-07-18 13:33:22 +00:00
|
|
|
type IntoFuture = BoxFuture<'r, Self::Output>;
|
2022-12-30 08:23:19 +00:00
|
|
|
|
|
|
|
fn into_future(self) -> Self::IntoFuture {
|
|
|
|
Box::pin(async move {
|
2024-07-18 13:33:22 +00:00
|
|
|
let router = self.client.router.extract()?;
|
|
|
|
router.execute_unit(Method::Unset, Param::new(vec![self.key.into()])).await
|
2022-12-30 08:23:19 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|