Implements traits introduced in the previous diffs for basic types and marks legacy methods as deprecated.
Depends on D8789
Differential D8790
[services-lib] Implement DDB Attr conversions, deprecate old methods bartek on Aug 10 2023, 3:44 PM. Authored by Tags None Referenced Files
Details Implements traits introduced in the previous diffs for basic types and marks legacy methods as deprecated. Depends on D8789 Tested later in the stack
Diff Detail
Event TimelineComment Actions Potential ideas: (both of them are kinda iffy so up to you!)
trait NumberFromAttr: FromStr<Err = ParseIntError> {} impl NumberFromAttr for u8 {} // ... impl NumberFromAttr for i64 {} impl<T: NumberFromAttr> TryFromAttribute for T { fn try_from_attr( attribute_name: impl Into<String>, attribute: Option<AttributeValue>, ) -> Result<Self, DBItemError> { match &attribute { Some(AttributeValue::N(numeric_str)) => { parse_integer(attribute_name, numeric_str) } Some(_) => Err(DBItemError::new( attribute_name.into(), Value::AttributeValue(attribute), DBItemAttributeError::IncorrectType, )), None => Err(DBItemError::new( attribute_name.into(), Value::AttributeValue(attribute), DBItemAttributeError::Missing, )), } } }
Comment Actions Thanks for these ideas! For sure we need to do a better number support, but I'd like to design this carefully. I'll create a follow-up task for these EDIT: https://linear.app/comm/issue/ENG-4658/improve-database-type-conversions-for-numbers
|