Trait dynomite::Item
[−]
[src]
pub trait Item: Into<Attributes> + FromAttributes { fn key(&self) -> Attributes; }
A type which can be represented as a set of string keys and
AttributeValues
and may also be coersed from the same set of values
Examples
extern crate rusoto_dynamodb; extern crate dynomite; use std::collections::HashMap; use dynomite::{AttributeError, Item, Attribute, FromAttributes, Attributes}; use rusoto_dynamodb::AttributeValue; #[derive(PartialEq,Debug, Clone)] struct Person { id: String } impl Item for Person { fn key(&self) -> Attributes { let mut attrs = HashMap::new(); attrs.insert("id".into(), "123".to_string().into_attr()); attrs } } impl FromAttributes for Person { fn from_attrs( attrs: Attributes ) -> Result<Self, AttributeError> { Ok(Self { id: attrs.get("id") .and_then(|val| val.s.clone()) .ok_or(AttributeError::MissingField { name: "id".into() })? }) } } impl Into<Attributes> for Person { fn into(self: Self) -> Attributes { let mut attrs = HashMap::new(); attrs.insert("id".into(), "123".to_string().into_attr()); attrs } } fn main() { let person = Person { id: "123".into() }; let attrs: Attributes = person.clone().into(); assert_eq!(Ok(person), FromAttributes::from_attrs(attrs)) }
Required Methods
fn key(&self) -> Attributes
Returns the set of attributes which make up this item's primary key