You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rfcs/0002_storage_trait.md
+77-13Lines changed: 77 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -198,6 +198,74 @@ Features:
198
198
- Case-insensitive scheme lookup
199
199
- Thread-safe and cloneable
200
200
201
+
### Serialization with typetag
202
+
203
+
To enable serialization of `Storage` and `StorageFactory` trait objects, we use the `typetag` crate. This allows dynamic trait objects to be serialized and deserialized, which is essential for:
204
+
205
+
- Persisting storage configurations
206
+
- Sending storage instances across process boundaries
207
+
- Supporting custom storage implementations in distributed systems
208
+
209
+
The traits are annotated with `#[typetag::serde]`:
210
+
211
+
```rust
212
+
#[async_trait]
213
+
#[typetag::serde(tag ="type")]
214
+
pubtraitStorage:Debug+Send+Sync {
215
+
// ... trait methods
216
+
}
217
+
218
+
#[typetag::serde(tag ="type")]
219
+
pubtraitStorageFactory:Debug+Send+Sync {
220
+
fnbuild(
221
+
&self,
222
+
props:HashMap<String, String>,
223
+
extensions:Extensions,
224
+
) ->Result<Arc<dynStorage>>;
225
+
}
226
+
```
227
+
228
+
Each implementation must also use the `#[typetag::serde]` attribute:
229
+
230
+
```rust
231
+
#[derive(Debug, Clone, Serialize, Deserialize)]
232
+
pubstructOpenDALS3Storage {
233
+
config:Arc<S3Config>,
234
+
}
235
+
236
+
#[async_trait]
237
+
#[typetag::serde]
238
+
implStorageforOpenDALS3Storage {
239
+
// ... implementation
240
+
}
241
+
242
+
#[derive(Debug, Serialize, Deserialize)]
243
+
pubstructOpenDALS3StorageFactory;
244
+
245
+
#[typetag::serde]
246
+
implStorageFactoryforOpenDALS3StorageFactory {
247
+
// ... implementation
248
+
}
249
+
```
250
+
251
+
Benefits:
252
+
253
+
-**Type-safe serialization** - Each implementation is tagged with its type name
254
+
-**Extensibility** - Custom implementations can be serialized without modifying core code
255
+
-**Cross-language support** - Serialized format is JSON-compatible
256
+
-**Replaces FileIOBuilder/Extensions** - Serializable storage implementations eliminate the need for separate builder patterns
0 commit comments