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
use core::fmt;

use crate::{
    path::Path,
    value::{self, ValueOrRef},
};

/// Represents a [`DELETE` statement for an update expression][1], for removing
/// one or more items from a value that is a [set][2].
///
/// See also: [`Path::delete`], [`Update`]
///
/// [1]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE
/// [2]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes.SetTypes
/// [`Update`]: crate::update::Update
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Delete {
    pub(crate) path: Path,
    pub(crate) subset: ValueOrRef,
}

impl Delete {
    /// Creates a [`Delete`] for the specified [`Path`] and items in that [set][1].
    ///
    /// See also: [`Path::delete`]
    ///
    /// [1]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes.SetTypes
    pub fn new<P, S>(path: P, subset: S) -> Self
    where
        P: Into<Path>,
        S: Into<value::Set>,
    {
        Self {
            path: path.into(),
            subset: subset.into().into(),
        }
    }
}

impl fmt::Display for Delete {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "DELETE {} {}", self.path, self.subset)
    }
}