1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::resp::{Command, FromValue};
use std::marker::PhantomData;

pub struct PreparedCommand<'a, T, R>
where
    R: FromValue,
{
    pub phantom: PhantomData<R>,
    pub executor: &'a mut T,
    pub command: Command,
}

impl<'a, T, R> PreparedCommand<'a, T, R>
where
    R: FromValue,
{
    #[must_use]
    pub fn new(executor: &'a mut T, command: Command) -> Self {
        PreparedCommand {
            phantom: PhantomData,
            executor,
            command,
        }
    }

    pub fn command(&self) -> &Command {
        &self.command
    }
}

pub fn prepare_command<T, R: FromValue>(
    executor: &mut T,
    command: Command,
) -> PreparedCommand<T, R> {
    PreparedCommand::new(executor, command)
}