pub trait IntoAttributeValue {
// Required method
fn into_attribute_value(self) -> AttributeValue;
}Expand description
Converts a Rust value into a DynamoDB AttributeValue.
This trait is the bridge between Rust types and the DynamoDB wire format.
It is implemented for all common scalar types, collections, and the
AsSet and AsNumber<T> newtypes:
| Rust type | DynamoDB type |
|---|---|
String, &str, &String | S |
bool | BOOL |
| Integer and float primitives | N |
Vec<u8>, [&[u8]] | B |
Vec<T>, [&[T]] (where T is a scalar) | L |
HashSet<String>, BTreeSet<String> | SS |
HashSet<N>, BTreeSet<N> (numeric) | NS |
HashSet<Vec<u8>>, BTreeSet<Vec<u8>> | BS |
AsSet<String> | SS |
AsSet<N> (numeric) | NS |
AsSet<Vec<u8>> | BS |
AsNumber<T> | N |
AttributeValue | identity |
Implement this trait for your own domain types to use them directly in
expression builders (e.g. Update::set("field", my_value)).
§Examples
use dynamodb_facade::{AttributeValue, IntoAttributeValue};
// Strings become AttributeValue::S
let av = "alice@example.com".into_attribute_value();
assert_eq!(av, AttributeValue::S("alice@example.com".to_owned()));
// Numbers become AttributeValue::N
let av = 42.into_attribute_value();
assert_eq!(av, AttributeValue::N("42".to_owned()));
// Custom domain type
struct UserId(String);
impl IntoAttributeValue for UserId {
fn into_attribute_value(self) -> AttributeValue {
self.0.into_attribute_value()
}
}
let av = UserId("user-1".to_owned()).into_attribute_value();
assert_eq!(av, AttributeValue::S("user-1".to_owned()));Required Methods§
Sourcefn into_attribute_value(self) -> AttributeValue
fn into_attribute_value(self) -> AttributeValue
Converts self into a DynamoDB AttributeValue.