dynamodb_expression/value/set/
num_set.rs1use core::fmt;
2use std::collections::BTreeSet;
3
4use aws_sdk_dynamodb::types::AttributeValue;
5
6use crate::Num;
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub struct NumSet(BTreeSet<Num>);
13
14impl NumSet {
15 pub fn new<T>(set: T) -> Self
19 where
20 T: Into<NumSet>,
21 {
22 set.into()
23 }
24
25 pub(super) fn into_attribute_value(self) -> AttributeValue {
30 AttributeValue::Ns(self.0.into_iter().map(Into::into).collect())
31 }
32}
33
34impl<T> FromIterator<T> for NumSet
35where
36 T: Into<Num>,
37{
38 fn from_iter<I>(iter: I) -> Self
39 where
40 I: IntoIterator<Item = T>,
41 {
42 Self(iter.into_iter().map(Into::into).collect())
43 }
44}
45
46impl<I, T> From<I> for NumSet
47where
48 I: IntoIterator<Item = T>,
49 T: Into<Num>,
50{
51 fn from(values: I) -> Self {
52 Self::from_iter(values)
53 }
54}
55
56impl fmt::Display for NumSet {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 f.debug_list().entries(self.0.iter().map(DebugNum)).finish()
59 }
60}
61
62struct DebugNum<'a>(&'a Num);
63
64impl<'a> fmt::Debug for DebugNum<'a> {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 f.write_str(&self.0.n)
67 }
68}