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# decorator | This module | Create | Update | Delete | Each |
|---|---|---|---|---|---|
LinksUniquenessValidator | UniquenessValidator | ● | |||
LinksUniquenessResolver | UniquenessResolver | ● | |||
LinksCascadeUniquenessAndUsagesResolver | CascadeUniquenessAndUsagesResolver | ● | ● | ||
LinksUsagesValidator | UsagesValidator | ● | ● | ||
LinksCascadeUsagesResolver | CascadeUsagesResolver | ● | |||
LinksInnerReferenceExistenceValidator | InnerReferenceExistenceValidator | ● | ● | ● | |
LinksItselfConstantToSelfReferenceResolver | ItselfConstantToSelfReferenceResolver | ● | ● | ||
LinksNullConstantToSelfReferenceResolver | NullConstantToSelfReferenceResolver | ● | ● | ||
LinksNonExistentDependenciesCreator | NonExistentDependenciesCreator | ● | |||
LinksNonExistentDeletionResolver | NonExistentDeletionResolver | ● | |||
NonNullContentsLinkDeletionResolver | NonNullContentsLinkDeletionResolver | ● | |||
LoggingDecorator | LoggingDecorator | ● | ● | ● | |
NoExceptionsDecorator | NoExceptionsDecorator | ● | ● | ● | ● |
UInt64LinksTransactionsLayer | TransactionsDecorator | ● | ● | ● |
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:
UniquenessResolverreports the surviving link to the handler, socreate_linkreturns a valid address instead of the address of the link it just deleted.CascadeUsagesResolvertracks the links it has already visited, so a reference cycle terminates instead of overflowing the stack.MergeUsagesre-points sources and targets correctly; the C# version writes null targets because of aparamsconstructor mix-up.EnsureCreatedactually calls the creator in its loop; the C# loop never terminates.InnerReferenceExistenceValidator::try_each_linksexists becauseLinks::each_linkshas no error channel.NoExceptionsDecoratormapsErr(_)toFlow::Break, the closest thing Rust’sFlowhas to C#’sErrorconstant. It does not catch panics.LoggingDecoratorsurfaces the first I/O error from the log writer instead of discarding it.
Modules§
- transactions
- Transactions with reversible writes and optional durable recovery.
Structs§
- Cascade
Resolve - Resolve the conflict and cascade through everything that depends on it.
- Cascade
Uniqueness AndUsages Resolver - Like
UniquenessResolver, but first re-points every link that referenced the redundant link at the surviving one. - Cascade
Usages Resolver - Deletes everything that references a link before deleting the link itself.
- Checked
Mutation - A safe view that validates the requested address, then calls the
[
UncheckedMutation] andReleaseprimitives. - Checked
Release - A safe release-only view of a memory store.
- File
Transition Log - A versioned, checksummed append-only file journal.
- Inner
Reference Existence Validator - Rejects an operation that names an internal reference which is not stored.
- Itself
Constant ToSelf Reference Resolver - Turns the
itselfconstant into a reference to the link being written. - Logging
Decorator - Logs every create, update and delete to a writer, in the format C#
LoggingDecoratoruses. - Memory
Transition Log - An in-memory journal for transactions that do not require crash recovery.
- NoExceptions
Decorator - Swallows every error a mutation returns, reporting it as [
Flow::Break]. - NonExistent
Deletion Resolver - Ignores deletion of a missing link without calling the inner store or the handler.
- NonExistent
Dependencies Creator - Creates the links an update depends on before performing the update.
- NonNull
Contents Link Deletion Resolver - Resets a link to
(null, null)before deleting it. Already reset links skip the update. Compose overCheckedReleaseto make resetting an explicit choice above the store’s minimal release primitive. - Null
Constant ToSelf Reference Resolver - Turns the
nullconstant 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.
- Transactions
Decorator - Adds transactions to any raw [
Doublets] store. - Transition
- A reversible mutation, including both link states.
- Uniqueness
Resolver - Redirects an update that would produce a duplicate to the link that already exists, then deletes the now-redundant link.
- Uniqueness
Validator - Rejects an update that would make two links share the same
(source, target)pair. - Usages
Validator - Rejects updates and deletions of a link that other links still reference.
- Validate
- Reject the conflicting operation with an error.
Enums§
- Journal
Entry - A durable recovery record.
- Transition
Kind - The mutation represented by a
Transition.
Traits§
- Decorators
Ext - Composes decorators around a store.
- Transition
Log - Storage for ordered transaction records.
- Uniqueness
Policy - Selects how a store reacts when an update would produce a duplicate
(source, target)pair. - Usages
Policy - Selects how a store reacts when an operation touches a link that other links still reference.
Type Aliases§
- Automatic
Uniqueness AndUsages Resolution - The stack C#
ILinksExtensions.DecorateWithAutomaticUniquenessAndUsagesResolutionbuilds, spelled as a type.