rca-sharing 0.1.0

Share values and read-only projections between Rust components without a Store or runtime
Documentation
  • Coverage
  • 100%
    48 out of 48 items documented3 out of 27 items with examples
  • Size
  • Source code size: 118.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.0 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • jacobcxdev/rust-composable-architecture
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jacobcxdev

rca-sharing

Use Shared<T> when several owners need to read and update one value. Give a SharedReader<T> to a component that only needs &T. The reader does not grant &mut T. If T supports interior mutability, the component can still change it through &T. Neither type needs an RCA Store or an async runtime.

use rca_sharing::{Shared, SharedAccessError};

fn main() -> Result<(), SharedAccessError> {
    let count = Shared::new(0);
    let display = count.reader()?;
    count.update(|value| *value += 1, || {})?;
    assert_eq!(display.read(|value| *value)?, 1);
    Ok(())
}

A reader sees updates to its captured value. If the writer switches to another value, the reader does not follow it. Use SharedKeyCache when independent callers need to open the same live value by key.

See the shared state guide and the API reference.