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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use rusoto_dynamodb::{PutItemError, PutItemInput};
use crate::{Attributes, DynamoDb, DynamoError, Table};
pub trait Put<D>: Table {
type Builder;
fn put(self, client: D) -> Self::Builder;
}
impl<D, T: Table + Into<Attributes>> Put<D> for T {
type Builder = Expr<D>;
fn put(self, client: D) -> Self::Builder {
let input = PutItemInput {
table_name: T::table_name(),
item: self.into(),
..PutItemInput::default()
};
Expr::new(client, input)
}
}
pub struct Expr<D> {
client: D,
input: PutItemInput,
}
impl<D> Expr<D> {
pub const fn new(client: D, input: PutItemInput) -> Self {
Self { client, input }
}
}
impl<D> Expr<D>
where
D: DynamoDb + Send,
for<'a> &'a D: Send,
{
pub async fn execute(self) -> Result<(), DynamoError<PutItemError>> {
let Self { client, input } = self;
client.put_item(input).await?;
Ok(())
}
}