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# 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 | ● | |||
NonNullContentsLinkDeletionResolver | NonNullContentsLinkDeletionResolver | ● | |||
LoggingDecorator | LoggingDecorator | ● | ● | ● | |
NoExceptionsDecorator | NoExceptionsDecorator | ● | ● | ● | ● |
§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:
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.
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.
- 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. - NoExceptions
Decorator - Swallows every error a mutation returns, reporting it as
Flow::Break. - 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, so the store’s indexes are updated before the link disappears. - 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.
- 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.
Traits§
- Decorators
Ext - Composes decorators around a store.
- 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.