rustis/client/
prepared_command.rs1use crate::{
2 Future,
3 client::Client,
4 resp::{Command, RespBuf, Response},
5};
6use std::marker::PhantomData;
7
8type CustomConverter<'a, R> = dyn Fn(RespBuf, Command, &'a Client) -> Future<'a, R> + Send + Sync;
9
10pub struct PreparedCommand<'a, E, R = ()>
13where
14 R: Response,
15{
16 phantom: PhantomData<R>,
18 pub executor: E,
21 pub command: Command,
23 pub custom_converter: Option<Box<CustomConverter<'a, R>>>,
25 pub retry_on_error: Option<bool>,
27}
28
29impl<'a, E, R> PreparedCommand<'a, E, R>
30where
31 R: Response,
32{
33 #[must_use]
35 pub fn new(executor: E, command: Command) -> Self {
36 PreparedCommand {
37 phantom: PhantomData,
38 executor,
39 command,
40 custom_converter: None,
41 retry_on_error: None,
42 }
43 }
44
45 pub fn custom_converter(mut self, custom_converter: Box<CustomConverter<'a, R>>) -> Self {
47 self.custom_converter = Some(custom_converter);
48 self
49 }
50
51 pub fn retry_on_error(mut self, retry_on_error: bool) -> Self {
55 self.retry_on_error = Some(retry_on_error);
56 self
57 }
58
59 pub fn command(&self) -> &Command {
61 &self.command
62 }
63}
64
65pub(crate) fn prepare_command<'a, E, R: Response>(
67 executor: E,
68 command: impl Into<Command>,
69) -> PreparedCommand<'a, E, R> {
70 PreparedCommand::new(executor, command.into())
71}