From 20c075ec51e6cf3366ea3038528f42cd1c92fd55 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Tue, 3 Jun 2025 15:32:28 +0300 Subject: [PATCH] feat: Add JSON serialization/deserialization to Event struct - Added `to_json` method to serialize Event to JSON string. - Added `from_json` method to deserialize Event from JSON string. - This allows for easier data exchange and persistence. --- heromodels/src/models/calendar/calendar.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/heromodels/src/models/calendar/calendar.rs b/heromodels/src/models/calendar/calendar.rs index b93b2b3..13732f5 100644 --- a/heromodels/src/models/calendar/calendar.rs +++ b/heromodels/src/models/calendar/calendar.rs @@ -101,6 +101,16 @@ pub struct Event { } impl Event { + /// Converts the event to a JSON string + pub fn to_json(&self) -> Result { + serde_json::to_string(self) + } + + /// Creates an event from a JSON string + pub fn from_json(json: &str) -> Result { + serde_json::from_str(json) + } + /// Creates a new event with auto-generated ID pub fn new(title: impl ToString, start_time: DateTime, end_time: DateTime) -> Self { Self {