Expand description
Wrappers around shared, interior-mutable cell pairs.
NautilusTrader engines store many components as Rc<RefCell<T>> for shared ownership with
interior mutability. Spelling that type at every boundary is verbose and risks accidentally
holding a strong reference where a weak one is required, leading to reference cycles.
SharedCell<T> and WeakCell<T> are zero-cost newtypes that name the intent and forward
the common operations (new, borrow, borrow_mut, with, with_mut, downgrade,
upgrade). They are #[repr(transparent)] and share the memory layout of the wrapped Rc /
Weak.
§Choosing between SharedCell and WeakCell
- Use
SharedCell<T>when the holder owns or co-owns the value, like a plainRc<RefCell<T>>. - Use
WeakCell<T>for back-references that would otherwise form a cycle. The back-pointer does not keep the value alive; every access must firstupgrade()to a strongSharedCell. This pattern breaks circular ownership: for anExchangethat owns anExecutionClientwhich references the exchange, the exchange holds aSharedCellto the client and the client holds aWeakCellback to the exchange.
Structs§
- Shared
Cell - Strong, shared ownership of
Twith interior mutability. - Weak
Cell - Weak counterpart to
SharedCell.