surrealdb/api/method/
set.rs

1use crate::api::conn::Method;
2use crate::api::conn::Param;
3use crate::api::conn::Router;
4use crate::api::Connection;
5use crate::api::Result;
6use crate::sql::Value;
7use std::future::Future;
8use std::future::IntoFuture;
9use std::pin::Pin;
10
11/// A set future
12#[derive(Debug)]
13#[must_use = "futures do nothing unless you `.await` or poll them"]
14pub struct Set<'r, C: Connection> {
15	pub(super) router: Result<&'r Router<C>>,
16	pub(super) key: String,
17	pub(super) value: Result<Value>,
18}
19
20impl<'r, Client> IntoFuture for Set<'r, Client>
21where
22	Client: Connection,
23{
24	type Output = Result<()>;
25	type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send + Sync + 'r>>;
26
27	fn into_future(self) -> Self::IntoFuture {
28		Box::pin(async move {
29			let mut conn = Client::new(Method::Set);
30			conn.execute_unit(self.router?, Param::new(vec![self.key.into(), self.value?])).await
31		})
32	}
33}