Function serde_dynamo::from_item
source · [−]pub fn from_item<'a, Tin, Tout>(item: HashMap<String, Tin>) -> Result<Tout> where
Tin: AttributeValue,
Tout: Deserialize<'a>,
Expand description
Interpret an Item – a hashmap from String
to AttributeValue
– as an instance of type T
.
TODO
#[derive(Serialize, Deserialize)]
pub struct User {
id: String,
name: String,
age: u8,
};
// Get documents from DynamoDB
let input = ScanInput {
table_name: "users".to_string(),
..ScanInput::default()
};
let result = client.scan(input).await?;
// And deserialize them as strongly-typed data structures
for item in result.items.unwrap() {
let user: User = from_item(item)?;
println!("{} is {}", user.name, user.age);
}