use bson::bson; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] struct IdentitySnapshot { id: i32, uuid: String, name: String, identity_type: Option, source: Option, status: String, tmdb_id: Option, tmdb_profile: Option, metadata: serde_json::Value, #[serde( with = "bson::serde_helpers::chrono_datetime_as_bson_datetime_optional", default )] created_at: Option>, face_count: i64, } #[derive(Debug, Clone, Serialize, Deserialize)] struct TargetIdentitySnapshot { id: i32, uuid: String, name: String, metadata_before: serde_json::Value, metadata_after: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] struct AliasEntry { name: String, locale: String, source: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] struct FacesTransferred { file_uuid: String, face_ids: Vec, trace_ids: Vec, count: i64, } #[derive(Debug, Clone, Serialize, Deserialize)] struct MergeParams { keep_history: bool, cleared_stranger_id: bool, performed_by_user: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] struct IdentityMergeHistory { #[serde(rename = "_id", skip_serializing_if = "Option::is_none")] id: Option, merge_id: String, source_identity: IdentitySnapshot, target_identity: TargetIdentitySnapshot, aliases_added_to_target: Vec, metadata_fields_added: Vec, faces_transferred: FacesTransferred, merge_params: MergeParams, #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")] merged_at: DateTime, #[serde(with = "bson::serde_helpers::chrono_datetime_as_bson_datetime")] undo_deadline: DateTime, undone: bool, #[serde( with = "bson::serde_helpers::chrono_datetime_as_bson_datetime_optional", skip_serializing_if = "Option::is_none" )] undone_at: Option>, undone_by: Option, undone_snapshot: Option, undo_expired: bool, } fn main() { let doc = bson!({ "merge_id": "test-id", "source_identity": { "id": bson::Bson::Int32(21), "uuid": "test-uuid", "name": "Test", "identity_type": "people", "source": "tmdb", "status": "confirmed", "tmdb_id": bson::Bson::Int32(123), "tmdb_profile": bson::Bson::Null, "metadata": {}, "created_at": bson::Bson::DateTime(bson::DateTime::from_millis(1714641951963)), "face_count": bson::Bson::Int64(0) }, "target_identity": { "id": bson::Bson::Int32(22), "uuid": "target-uuid", "name": "Target", "metadata_before": {}, "metadata_after": bson::Bson::Null }, "aliases_added_to_target": [], "metadata_fields_added": [], "faces_transferred": { "file_uuid": "", "face_ids": [], "trace_ids": [], "count": bson::Bson::Int64(0) }, "merge_params": { "keep_history": false, "cleared_stranger_id": true, "performed_by_user": "0" }, "merged_at": bson::Bson::DateTime(bson::DateTime::from_millis(1714641951963)), "undo_deadline": bson::Bson::DateTime(bson::DateTime::from_millis(1714641951963)), "undone": false, "undone_at": bson::Bson::Null, "undone_by": bson::Bson::Null, "undone_snapshot": bson::Bson::Null, "undo_expired": false }); let result: Result = bson::from_bson(doc); match result { Ok(h) => println!("Success! {:?}", h.merge_id), Err(e) => println!("Error: {}", e), } }