Skip to content

Commit 9ba849c

Browse files
authored
Merge pull request softprops#134 from Veetaha/feat/impl-attr-for-into-from-attrs
Implement Attribute for FromAttributes + IntoAttributes
2 parents 8ee63d2 + 3c998ac commit 9ba849c

File tree

2 files changed

+4
-57
lines changed

2 files changed

+4
-57
lines changed

dynomite-derive/src/lib.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,30 +289,10 @@ fn make_dynomite_attributes(
289289
// impl ::dynomite::IntoAttributes for Name
290290
// impl From<Name> for ::dynomite::Attributes
291291
let to_attribute_map = get_to_attribute_map_trait(name, &item_fields);
292-
// impl Attribute for Name (these are essentially just a map)
293-
let attribute = quote!(::dynomite::Attribute);
294-
let impl_attribute = quote! {
295-
impl #attribute for #name {
296-
fn into_attr(self: Self) -> ::dynomite::AttributeValue {
297-
::dynomite::AttributeValue {
298-
m: Some(self.into()),
299-
..::dynomite::AttributeValue::default()
300-
}
301-
}
302-
fn from_attr(value: ::dynomite::AttributeValue) -> std::result::Result<Self, ::dynomite::AttributeError> {
303-
use ::dynomite::FromAttributes;
304-
value
305-
.m
306-
.ok_or(::dynomite::AttributeError::InvalidType)
307-
.and_then(Self::from_attrs)
308-
}
309-
}
310-
};
311292

312293
Ok(quote! {
313294
#from_attribute_map
314295
#to_attribute_map
315-
#impl_attribute
316296
})
317297
}
318298

dynomite/src/lib.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ pub type Attributes = HashMap<String, AttributeValue>;
390390
/// #[dynomite(default)]
391391
/// summary: Option<String>
392392
/// }
393-
pub trait Item: Into<Attributes> + FromAttributes {
393+
pub trait Item: IntoAttributes + FromAttributes {
394394
/// Returns the set of attributes which make up this item's primary key
395395
///
396396
/// This is often used in item look ups
@@ -514,11 +514,11 @@ impl<A: Attribute> IntoAttributes for BTreeMap<String, A> {
514514
}
515515
}
516516

517-
/// A Map type for Items, represented as the `M` AttributeValue type
518-
impl<T: Item> Attribute for T {
517+
/// A Map type for all hash-map-like values, represented as the `M` AttributeValue type
518+
impl<T: IntoAttributes + FromAttributes> Attribute for T {
519519
fn into_attr(self: Self) -> AttributeValue {
520520
AttributeValue {
521-
m: Some(self.into()),
521+
m: Some(self.into_attrs()),
522522
..AttributeValue::default()
523523
}
524524
}
@@ -530,39 +530,6 @@ impl<T: Item> Attribute for T {
530530
}
531531
}
532532

533-
/// A Map type for Items for HashMaps, represented as the `M` AttributeValue type
534-
#[allow(clippy::implicit_hasher)]
535-
impl<A: Attribute> Attribute for HashMap<String, A> {
536-
fn into_attr(self: Self) -> AttributeValue {
537-
AttributeValue {
538-
m: Some(self.into_iter().map(|(k, v)| (k, v.into_attr())).collect()),
539-
..AttributeValue::default()
540-
}
541-
}
542-
fn from_attr(value: AttributeValue) -> Result<Self, AttributeError> {
543-
value
544-
.m
545-
.ok_or(AttributeError::InvalidType)
546-
.and_then(Self::from_attrs) // because FromAttributes is impl by all HashMap<String, A>
547-
}
548-
}
549-
550-
/// A Map type for `Items` for `BTreeMaps`, represented as the `M` AttributeValue type
551-
impl<A: Attribute> Attribute for BTreeMap<String, A> {
552-
fn into_attr(self: Self) -> AttributeValue {
553-
AttributeValue {
554-
m: Some(self.into_iter().map(|(k, v)| (k, v.into_attr())).collect()),
555-
..AttributeValue::default()
556-
}
557-
}
558-
fn from_attr(value: AttributeValue) -> Result<Self, AttributeError> {
559-
value
560-
.m
561-
.ok_or(AttributeError::InvalidType)
562-
.and_then(Self::from_attrs) // because FromAttributes is impl by all BTreeMap<String, A>
563-
}
564-
}
565-
566533
/// A `String` type for `Uuids`, represented by the `S` AttributeValue type
567534
#[cfg(feature = "uuid")]
568535
impl Attribute for Uuid {

0 commit comments

Comments
 (0)