@@ -34,7 +34,7 @@ pub struct Table {
34
34
///
35
35
/// Implementors of this trait need to make sure that their type is unique with respect to
36
36
/// their owning ingredient as the allocation strategy relies on this.
37
- pub ( crate ) unsafe trait Slot : Any + Send + Sync {
37
+ pub unsafe trait Slot : Any + Send + Sync {
38
38
/// Access the [`MemoTable`][] for this slot.
39
39
///
40
40
/// # Safety condition
@@ -220,17 +220,42 @@ impl Table {
220
220
PageIndex :: new ( self . pages . push ( Page :: new :: < T > ( ingredient, memo_types) ) )
221
221
}
222
222
223
- /// Get the memo table associated with `id`
223
+ /// Get the memo table associated with `id` for the concrete type `T`.
224
224
///
225
- /// # Safety condition
225
+ /// # Safety
226
226
///
227
- /// The parameter `current_revision` MUST be the current revision
228
- /// of the owner of database owning this table.
229
- pub ( crate ) unsafe fn memos (
227
+ /// The parameter `current_revision` must be the current revision of the database
228
+ /// owning this table.
229
+ ///
230
+ /// # Panics
231
+ ///
232
+ /// If `page` is out of bounds or the type `T` is incorrect.
233
+ pub unsafe fn memos < T : Slot > (
230
234
& self ,
231
235
id : Id ,
232
236
current_revision : Revision ,
233
237
) -> MemoTableWithTypes < ' _ > {
238
+ let ( page, slot) = split_id ( id) ;
239
+ let page = self . pages [ page. 0 ] . assert_type :: < T > ( ) ;
240
+ let slot = & page. data ( ) [ slot. 0 ] ;
241
+
242
+ // SAFETY: The caller is required to pass the `current_revision`.
243
+ let memos = unsafe { slot. memos ( current_revision) } ;
244
+
245
+ // SAFETY: The `Page` keeps the correct memo types.
246
+ unsafe { page. 0 . memo_types . attach_memos ( memos) }
247
+ }
248
+
249
+ /// Get the memo table associated with `id`.
250
+ ///
251
+ /// Unlike `Table::memos`, this does not require a concrete type, and instead uses dynamic
252
+ /// dispatch.
253
+ ///
254
+ /// # Safety
255
+ ///
256
+ /// The parameter `current_revision` must be the current revision of the owner of database
257
+ /// owning this table.
258
+ pub unsafe fn dyn_memos ( & self , id : Id , current_revision : Revision ) -> MemoTableWithTypes < ' _ > {
234
259
let ( page, slot) = split_id ( id) ;
235
260
let page = & self . pages [ page. 0 ] ;
236
261
// SAFETY: We supply a proper slot pointer and the caller is required to pass the `current_revision`.
@@ -373,6 +398,7 @@ impl Page {
373
398
slot. 0 < len,
374
399
"out of bounds access `{slot:?}` (maximum slot `{len}`)"
375
400
) ;
401
+
376
402
// SAFETY: We have checked that the resulting pointer will be within bounds.
377
403
unsafe {
378
404
self . data
0 commit comments