dynamodb_expression/condition/and.rs
1use core::fmt;
2
3use crate::condition::Condition;
4
5/// Represents a [DynamoDB logical `AND`][1] condition.
6///
7/// See also: [`Condition::and`]
8///
9/// ```
10/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
11/// use dynamodb_expression::Path;
12/// # use pretty_assertions::assert_eq;
13///
14/// let a = "a".parse::<Path>()?;
15/// let b = "b".parse::<Path>()?;
16/// let c = "c".parse::<Path>()?;
17/// let d = "d".parse::<Path>()?;
18///
19/// let condition = a.greater_than(b).and(c.less_than(d));
20/// assert_eq!("a > b AND c < d", condition.to_string());
21/// #
22/// # Ok(())
23/// # }
24/// ```
25///
26/// [1]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.LogicalEvaluations
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct And {
29 pub(crate) left: Box<Condition>,
30 pub(crate) right: Box<Condition>,
31}
32
33impl fmt::Display for And {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 self.left.fmt(f)?;
36 f.write_str(" AND ")?;
37 self.right.fmt(f)
38 }
39}
40
41#[cfg(test)]
42mod test {
43 use pretty_assertions::assert_eq;
44
45 use crate::{condition::And, Path};
46
47 #[test]
48 fn and() {
49 let a = "a".parse::<Path>().unwrap();
50 let b = "b".parse::<Path>().unwrap();
51 let c = "c".parse::<Path>().unwrap();
52 let d = "d".parse::<Path>().unwrap();
53
54 let condition = And {
55 left: a.greater_than(b).into(),
56 right: c.less_than(d).into(),
57 };
58 assert_eq!("a > b AND c < d", condition.to_string());
59 }
60}