Skip to main content

Module decorators

Module decorators 

Source
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). Zero-cost decorators that add policy 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
NonNullContentsLinkDeletionResolverNonNullContentsLinkDeletionResolver
LoggingDecoratorLoggingDecorator
NoExceptionsDecoratorNoExceptionsDecorator

§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.

For a stack whose outermost layer is the one doing the recursion the two are the same, which is the case for every stack C# itself builds. Otherwise, put a decorator whose behaviour the cascade must observe below the decorator that cascades.

§Deviations from C#

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

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.
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.
NoExceptionsDecorator
Swallows every error a mutation returns, reporting it as Flow::Break.
NonExistentDependenciesCreator
Creates the links an update depends on before performing the update.
NonNullContentsLinkDeletionResolver
Resets a link to (null, null) before deleting it, so the store’s indexes are updated before the link disappears.
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.
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.

Traits§

DecoratorsExt
Composes decorators around a store.
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.