Skip to main content

Module decorators

Module decorators 

Expand description

The upstream doublets decorator layer, re-exported so downstream crates can stack decorators onto a DoubletsStorage through DoubletsStorage::map_store without depending on doublets directly (and without risking a version mismatch). Decorators that add policy and transactions to any Doublets store.

This module is a port of the decorator layer of Platform.Data.Doublets. Each C# decorator has a counterpart here with the same logic, but composition is static: a decorator is a generic struct that owns the store it wraps, every forwarding method is #[inline], and the policy markers are zero-sized. A chosen stack is one concrete type, so the optimiser can fuse the whole stack into a single create / update / delete / each with no per-layer call.

§Building a stack

DecoratorsExt takes the store by value and returns the concrete composed type:

use doublets::{decorators::{DecoratorsExt, Resolve}, mem, unit, Doublets};

let mut store = unit::Store::<usize, _>::new(mem::Global::new())?
    .with_uniqueness(Resolve)
    .with_usages_validation();

let a = store.create_point()?;
let b = store.create_point()?;
assert_eq!(store.create_link(a, b)?, store.create_link(a, b)?);

§The decorators

C# decoratorThis moduleCreateUpdateDeleteEach
LinksUniquenessValidatorUniquenessValidator●
LinksUniquenessResolverUniquenessResolver●
LinksCascadeUniquenessAndUsagesResolverCascadeUniquenessAndUsagesResolver●●
LinksUsagesValidatorUsagesValidator●●
LinksCascadeUsagesResolverCascadeUsagesResolver●
LinksInnerReferenceExistenceValidatorInnerReferenceExistenceValidator●●●
LinksItselfConstantToSelfReferenceResolverItselfConstantToSelfReferenceResolver●●
LinksNullConstantToSelfReferenceResolverNullConstantToSelfReferenceResolver●●
LinksNonExistentDependenciesCreatorNonExistentDependenciesCreator●
LinksNonExistentDeletionResolverNonExistentDeletionResolver●
NonNullContentsLinkDeletionResolverNonNullContentsLinkDeletionResolver●
LoggingDecoratorLoggingDecorator●●●
NoExceptionsDecoratorNoExceptionsDecorator●●●●
UInt64LinksTransactionsLayerTransactionsDecorator●●●

Unlike the stateless policy wrappers, transactions keep a journal and graph snapshots. See transactions for their durability, ordering and cost.

§Ordering

C# propagates a _facade reference down the stack so that a decorator’s recursive calls — a cascading delete, a usage merge — re-enter at the top of the stack. A statically composed stack has no such back-reference: a decorator only knows the layers below it, so recursive calls re-enter at the layer that made them.

Put a decorator whose behaviour the cascade must observe below the decorator that cascades. The automatic uniqueness and usages resolution stack keeps C#’s order, with CascadeUsagesResolver below NonNullContentsLinkDeletionResolver. To preserve its callbacks without a facade back-reference, the cascade explicitly resets each usage to (null, null) before recursing into its usages, then deletes it after those usages are gone. The outer reset layer handles the originally requested link.

§Deviations from C#

Each is documented on the item it affects; in summary:

Modules§

transactions
Transactions with reversible writes and optional durable recovery.

Structs§

CascadeResolve
Resolve the conflict and cascade through everything that depends on it.
CascadeUniquenessAndUsagesResolver
Like UniquenessResolver, but first re-points every link that referenced the redundant link at the surviving one.
CascadeUsagesResolver
Deletes everything that references a link before deleting the link itself.
CheckedMutation
A safe view that validates the requested address, then calls the [UncheckedMutation] and Release primitives.
CheckedRelease
A safe release-only view of a memory store.
FileTransitionLog
A versioned, checksummed append-only file journal.
InnerReferenceExistenceValidator
Rejects an operation that names an internal reference which is not stored.
ItselfConstantToSelfReferenceResolver
Turns the itself constant into a reference to the link being written.
LoggingDecorator
Logs every create, update and delete to a writer, in the format C# LoggingDecorator uses.
MemoryTransitionLog
An in-memory journal for transactions that do not require crash recovery.
NoExceptionsDecorator
Swallows every error a mutation returns, reporting it as [Flow::Break].
NonExistentDeletionResolver
Ignores deletion of a missing link without calling the inner store or the handler.
NonExistentDependenciesCreator
Creates the links an update depends on before performing the update.
NonNullContentsLinkDeletionResolver
Resets a link to (null, null) before deleting it. Already reset links skip the update. Compose over CheckedRelease to make resetting an explicit choice above the store’s minimal release primitive.
NullConstantToSelfReferenceResolver
Turns the null constant into a reference to the link being written, and makes a bare create produce a self-referential point.
Resolve
Resolve the conflict by reusing the link that already exists.
Transaction
An exclusively borrowed transaction; unfinished handles roll back on drop.
TransactionsDecorator
Adds transactions to any raw [Doublets] store.
Transition
A reversible mutation, including both link states.
UniquenessResolver
Redirects an update that would produce a duplicate to the link that already exists, then deletes the now-redundant link.
UniquenessValidator
Rejects an update that would make two links share the same (source, target) pair.
UsagesValidator
Rejects updates and deletions of a link that other links still reference.
Validate
Reject the conflicting operation with an error.

Enums§

JournalEntry
A durable recovery record.
TransitionKind
The mutation represented by a Transition.

Traits§

DecoratorsExt
Composes decorators around a store.
TransitionLog
Storage for ordered transaction records.
UniquenessPolicy
Selects how a store reacts when an update would produce a duplicate (source, target) pair.
UsagesPolicy
Selects how a store reacts when an operation touches a link that other links still reference.

Type Aliases§

AutomaticUniquenessAndUsagesResolution
The stack C# ILinksExtensions.DecorateWithAutomaticUniquenessAndUsagesResolution builds, spelled as a type.