Skip to main content

Crate rca_sharing

Crate rca_sharing 

Source
Expand description

Shares values between owners without a Store or an async runtime.

Use Shared when several owners need to update one value. Give a SharedReader to callers that only need to read it. For independent callers that open the same resource by key, use SharedKeyCache. Applications that already use RCA can import these types from rca.

§Examples

use rca_sharing::{Shared, SharedAccessError};

let count = Shared::new(0);
let display = count.reader()?;
count.update(|value| *value += 1, || {})?;
assert_eq!(display.read(|value| *value)?, 1);

§Access and publication

Shared and its clones share one binding. Readers and projections keep the value that the binding selected at the time of capture. Independent bindings can refer to the same value after Shared::rebind. Later changes to either binding do not affect the other. These handles own data, not Store membership or output authority. Retaining them cannot revive a retired scope.

Access through a shared handle or projection is synchronous and non-blocking. No mutex guard or borrow of the value can escape an access callback. Overlapping access (including synchronous reentry) returns Busy; a panicking access callback poisons that value reference. Readers with interior-mutable values retain the capabilities inherent in &T; a reader grants no &mut T and cannot rebind a writer. A cache can replace an individual reader through SharedKeyCache::load_reader.

Mutation callbacks operate in place: returning Err retains earlier writes and the original typed cause. Every normally returning mutation invokes its explicit publication callback after unlocking, even on Err or an unchanged value. A panic does not publish. Publication may reenter and panic without poisoning the value. Publication means invoking the caller’s callback; acceptance by an external destination remains the caller’s responsibility. An in-memory handle does not register observers, compare values, spawn tasks, or persist changes. A SharedKeyCache uses its key’s subscription to receive updates from a provider.

Partial projections deliberately have no last-value cache. Reads and writes return Absent while the selected optional, case, or key is missing. They never recreate that payload. If it reappears in the same reference, the projection sees the current payload; this is data membership, not Store scope authority.

§Ordering and lock boundaries

A cohort access first captures its reference under the cohort mutex, releases that mutex, then tries the value mutex. A concurrent rebind after capture does not retarget the operation. Rebinding captures the target reference first and linearises at the receiving cohort’s pointer swap; it never locks a value. A mutation’s retained result becomes readable when its value lock is released. Serialised commits do not imply ordered publication callbacks across threads: another mutation may commit before an earlier callback reads the latest value. Capture an owned snapshot in the mutation result when exact snapshots matter.

Error precedence is cohort capture, value lock, projection presence, then user mutation result. Rebinding checks target capture before receiver access. Busy and Poisoned reflect Mutex::try_lock; no waiting or poison recovery occurs. Failed access/absence skips both mutation and publication. Library-displaced references and returned results/errors are dropped outside library locks. Read/path/mutation callbacks and any destructors they themselves execute run under the value lock: keep them short and synchronous. Publication runs with no library lock held. Auto-traits follow stored ownership, without unsafe promotion or blanket value Clone, Debug, Send, or Sync requirements.

Structs§

Shared
Gives multiple owners read and write access to the same value.
SharedAccessError
Reports unavailable synchronous access without exposing a lock guard.
SharedKeyCache
Lets callers find the same live shared value by key.
SharedKeyDefault
Attaches a repeatable default without changing the base key’s identity.
SharedKeyError
Preserves a cache, value-access or original typed provider failure.
SharedKeyIdentity
Identifies a resource and its codec configuration within one cache namespace.
SharedMutationError
Preserves an access failure or a typed cause after retained mutation.
SharedProjection
Mutates a partial field while retaining its originally captured reference.
SharedPublication
Briefly retains one captured reference and its reload coordinator.
SharedReadProjection
Reads a partial field of a captured owned reference.
SharedReader
Gives read-only access to one shared value.
SharedSubscriber
Delivers owned values through a weak captured reference.

Enums§

SharedLoadContext
Distinguishes a borrowed construction seed from an explicit storage load.
SharedSubscribeContext
Identifies subscription intent without retaining a duplicate seed value.

Traits§

SharedKey
Adds explicit saving capability to a typed readable resource.
SharedReaderKey
Supplies typed loading and an owned subscription for a stable resource.