@@ -141,9 +141,10 @@ impl Storage for OpenDALMemoryStorage {
141141}
142142
143143/// Factory for OpenDAL Memory storage
144- #[ derive( Debug ) ]
144+ #[ derive( Debug , Serialize , Deserialize ) ]
145145pub struct OpenDALMemoryStorageFactory ;
146146
147+ #[ typetag:: serde]
147148impl StorageFactory for OpenDALMemoryStorageFactory {
148149 fn build (
149150 & self ,
@@ -176,4 +177,52 @@ mod tests {
176177 // Verify the type is correct
177178 assert ! ( format!( "{:?}" , deserialized) . contains( "OpenDALMemoryStorage" ) ) ;
178179 }
180+
181+ #[ test]
182+ fn test_memory_factory_serialization ( ) {
183+ use crate :: io:: StorageFactory ;
184+
185+ // Create a factory instance
186+ let factory: Box < dyn StorageFactory > = Box :: new ( OpenDALMemoryStorageFactory ) ;
187+
188+ // Serialize the factory
189+ let serialized = serde_json:: to_string ( & factory) . unwrap ( ) ;
190+
191+ // Deserialize the factory
192+ let deserialized: Box < dyn StorageFactory > = serde_json:: from_str ( & serialized) . unwrap ( ) ;
193+
194+ // Verify the type is correct
195+ assert ! ( format!( "{:?}" , deserialized) . contains( "OpenDALMemoryStorageFactory" ) ) ;
196+ }
197+
198+ #[ test]
199+ fn test_memory_factory_to_storage_serialization ( ) {
200+ use crate :: io:: { Extensions , StorageFactory } ;
201+
202+ // Create a factory and build storage
203+ let factory = OpenDALMemoryStorageFactory ;
204+ let storage = factory
205+ . build ( HashMap :: new ( ) , Extensions :: default ( ) )
206+ . unwrap ( ) ;
207+
208+ // Serialize the storage
209+ let storage_json = serde_json:: to_string ( & storage) . unwrap ( ) ;
210+
211+ // Deserialize the storage
212+ let deserialized_storage: Box < dyn Storage > = serde_json:: from_str ( & storage_json) . unwrap ( ) ;
213+
214+ // Verify storage type
215+ assert ! ( format!( "{:?}" , deserialized_storage) . contains( "OpenDALMemoryStorage" ) ) ;
216+
217+ // Serialize the factory
218+ let factory_boxed: Box < dyn StorageFactory > = Box :: new ( factory) ;
219+ let factory_json = serde_json:: to_string ( & factory_boxed) . unwrap ( ) ;
220+
221+ // Deserialize the factory
222+ let deserialized_factory: Box < dyn StorageFactory > =
223+ serde_json:: from_str ( & factory_json) . unwrap ( ) ;
224+
225+ // Verify factory type
226+ assert ! ( format!( "{:?}" , deserialized_factory) . contains( "OpenDALMemoryStorageFactory" ) ) ;
227+ }
179228}
0 commit comments