Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created September 30, 2021 14:57
Show Gist options
  • Save ntakouris/b61f5355e81d010c859cfaf75551dc2d to your computer and use it in GitHub Desktop.
Save ntakouris/b61f5355e81d010c859cfaf75551dc2d to your computer and use it in GitHub Desktop.
// 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