rec_cell 0.1.0

Zero-cost borrow-checking of aliased references with cyclic construction
Documentation
  • Coverage
  • 100%
    16 out of 16 items documented4 out of 4 items with examples
  • Size
  • Source code size: 115.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.22 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ivan-shrimp/rec-cell
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ivan-shrimp

Crates.io Version docs.rs CI Status

Zero-cost borrow-checking of aliased references supporting cyclic construction.

Overview

Some collections, such as linked lists or trees, are most easily implemented with aliasing pointers. GhostCell is a proven alternative to runtime borrow checking, and the branding idea has been (re)implemented in several crates.

This crate provides RecCell and RecToken, corresponding to GhostCell and GhostToken, then extends the API by introducing cyclic construction:

impl<'t, T> RecCell<'t, T>> {
    pub fn new_cyclic<'a R>(
        uninit: &'a mut MaybeUninit<T>,
        token: RecToken<'t>,
        scope: impl FnOnce(&'a Self) -> (R, T),
    ) -> (R, RecToken<'t>);
}

This gives you a reference to the not-yet-constructed cell to construct your potentially cyclic cell. In exchange, it takes away the token entirely such that it is impossible to access the uninitialized cell within the scope. There are some subtleties to this; see the docs for more details.

Safety

There is yet to be a formal proof of the correctness of this mechanism. All tests currently pass Miri.

Some parts are bot-drafted and might be of dubious quality. I might eventually rewrite those parts by hand.

Part Status
Library code 100% human
Documentation 80% human: SliceCursor{,Mut} pending
Tests not in docs 0% human

Acknowledgements

This is heavily based on and inspired by the ghost-cell crate and similar implementations.

License

Licensed under either of

at your option.