Created
September 30, 2021 14:57
-
-
Save ntakouris/b61f5355e81d010c859cfaf75551dc2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// alternatively, return a mutable DataResource | |
// and map the id and other metadata afterwards | |
let resource = match event.value { | |
// simple | |
EventValue::String(x) => DataResource{ id: event.id, value: DataResourcePayload::String(x)}, | |
EventValue::Float(x) => DataResource{ id: event.id, value: DataResourcePayload::Float(x)}, | |
EventValue::Int(x) => DataResource{ id: event.id, value: DataResourcePayload::Int(x)}, | |
EventValue::Bool(x) => DataResource{ id: event.id, value: DataResourcePayload::Bool(x)}, | |
// special care with incremental additions | |
EventValue::CaptionedImage(x) => { | |
// <save to some blob storage> | |
let ref_id = Uuid::new_v4().to_string(); | |
DataResource { | |
id: event.id, | |
value: DataResourcePayload::CaptionedImage( | |
CaptionedImagePayload { caption: x.caption, blob_storage_ref_id: ref_id } | |
) | |
} | |
} | |
}; | |
match db.save(resource) { | |
Ok(_) => Result::Ok(()), | |
Err(x) => Result::Err(x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment