Struct CascadeUniquenessAndUsagesResolver
pub struct CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T>,{ /* private fields */ }Expand description
Like UniquenessResolver, but first re-points every link that referenced the
redundant link at the surviving one.
Port of C# LinksCascadeUniquenessAndUsagesResolver.
§Requested address
Like UniquenessResolver, this decorator does not check that the link being
updated exists. Existence is a separate policy, so callers who guarantee valid
addresses pay for no extra lookup. When the old address is missing and the new
pair is already stored, the update reports the existing link and changes
nothing; when the pair is new, the update is forwarded to the inner layers.
To get [Error::NotExists] for a missing address, select that contract
explicitly. Compose InnerReferenceExistenceValidator outside the resolver,
so it runs before the pair lookup. It also checks the new endpoints. Or call
[Doublets::try_get_link] before the updates that need it. A validator placed
inside the resolver is never reached for an existing pair.
use doublets::{decorators::DecoratorsExt, unit, Doublets, Error};
use mem::Global;
let mut store = unit::Store::<u32, _>::new(Global::new())?
.with_automatic_uniqueness_and_usages_resolution()
.with_inner_reference_existence_validation();
store.create_point()?;
store.create_point()?;
let link = store.create_link(1, 2)?;
assert!(matches!(store.update(99, 3, 3), Err(Error::NotExists(99))));
assert!(matches!(store.update(99, 1, 2), Err(Error::NotExists(99))));
assert_eq!(store.search(1, 2), Some(link));
// Without the validator only the pair is resolved: link 99 is not checked.
let mut store = unit::Store::<u32, _>::new(Global::new())?
.with_automatic_uniqueness_and_usages_resolution();
store.create_point()?;
store.create_point()?;
store.create_link(1, 2)?;
// Per-call alternative: look the address up only where you need the error.
assert!(matches!(store.try_get_link(99), Err(Error::NotExists(99))));
assert_eq!(store.update(99, 1, 2)?, link);
assert_eq!(store.count(), 3);Implementations§
§impl<T, L> CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T>,
impl<T, L> CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T>,
pub const fn new(links: L) -> CascadeUniquenessAndUsagesResolver<T, L>
pub const fn new(links: L) -> CascadeUniquenessAndUsagesResolver<T, L>
Wraps links in a CascadeUniquenessAndUsagesResolver.
pub fn into_inner(self) -> L
pub fn into_inner(self) -> L
Unwraps the decorator and returns the wrapped store.
Trait Implementations§
§impl<T, L> Debug for CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T> + Debug,
impl<T, L> Debug for CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T> + Debug,
§impl<T, L> Doublets<T> for CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T>,
impl<T, L> Doublets<T> for CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T>,
§fn get_link(&self, index: T) -> Option<Link<T>>
fn get_link(&self, index: T) -> Option<Link<T>>
index, or None if it does not exist.§fn create_by_with<F>(
&mut self,
query: impl ToQuery<T>,
handler: F,
) -> Result<Flow, Error<T>>
fn create_by_with<F>( &mut self, query: impl ToQuery<T>, handler: F, ) -> Result<Flow, Error<T>>
query, calling handler on each created link.§fn create_by(&mut self, query: impl ToQuery<T>) -> Result<T, Error<T>>where
Self: Sized,
fn create_by(&mut self, query: impl ToQuery<T>) -> Result<T, Error<T>>where
Self: Sized,
query and returns its index.§fn create_with<F>(&mut self, handler: F) -> Result<Flow, Error<T>>
fn create_with<F>(&mut self, handler: F) -> Result<Flow, Error<T>>
handler with the before/after states.§fn create(&mut self) -> Result<T, Error<T>>where
Self: Sized,
fn create(&mut self) -> Result<T, Error<T>>where
Self: Sized,
§fn each_by<F>(&self, query: impl ToQuery<T>, handler: F) -> Flow
fn each_by<F>(&self, query: impl ToQuery<T>, handler: F) -> Flow
query, calling handler for each.§fn each<F>(&self, handler: F) -> Flow
fn each<F>(&self, handler: F) -> Flow
handler for each.§fn update_by_with<H>(
&mut self,
query: impl ToQuery<T>,
change: impl ToQuery<T>,
handler: H,
) -> Result<Flow, Error<T>>
fn update_by_with<H>( &mut self, query: impl ToQuery<T>, change: impl ToQuery<T>, handler: H, ) -> Result<Flow, Error<T>>
query to change, calling handler with before/after.§fn update_by(
&mut self,
query: impl ToQuery<T>,
change: impl ToQuery<T>,
) -> Result<T, Error<T>>where
Self: Sized,
fn update_by(
&mut self,
query: impl ToQuery<T>,
change: impl ToQuery<T>,
) -> Result<T, Error<T>>where
Self: Sized,
query to change and returns the updated link’s index.§fn update_with<F>(
&mut self,
index: T,
source: T,
target: T,
handler: F,
) -> Result<Flow, Error<T>>
fn update_with<F>( &mut self, index: T, source: T, target: T, handler: F, ) -> Result<Flow, Error<T>>
index to (index, source, target), calling handler.§fn update(&mut self, index: T, source: T, target: T) -> Result<T, Error<T>>where
Self: Sized,
fn update(&mut self, index: T, source: T, target: T) -> Result<T, Error<T>>where
Self: Sized,
index to (index, source, target) and returns the index.§fn delete_by_with<F>(
&mut self,
query: impl ToQuery<T>,
handler: F,
) -> Result<Flow, Error<T>>
fn delete_by_with<F>( &mut self, query: impl ToQuery<T>, handler: F, ) -> Result<Flow, Error<T>>
query, calling handler with before/after states.§fn delete_by(&mut self, query: impl ToQuery<T>) -> Result<T, Error<T>>where
Self: Sized,
fn delete_by(&mut self, query: impl ToQuery<T>) -> Result<T, Error<T>>where
Self: Sized,
query and returns the deleted link’s index.§fn delete_with<F>(&mut self, index: T, handler: F) -> Result<Flow, Error<T>>
fn delete_with<F>(&mut self, index: T, handler: F) -> Result<Flow, Error<T>>
index, calling handler with before/after states.§fn delete(&mut self, index: T) -> Result<T, Error<T>>where
Self: Sized,
fn delete(&mut self, index: T) -> Result<T, Error<T>>where
Self: Sized,
index and returns its former index.§fn try_get_link(&self, index: T) -> Result<Link<T>, Error<T>>
fn try_get_link(&self, index: T) -> Result<Link<T>, Error<T>>
index, or Err(Error::NotExists) if it does not exist.§fn delete_all(&mut self) -> Result<(), Error<T>>where
Self: Sized,
fn delete_all(&mut self) -> Result<(), Error<T>>where
Self: Sized,
§fn delete_query_with<F>(
&mut self,
query: impl ToQuery<T>,
handler: F,
) -> Result<(), Error<T>>
fn delete_query_with<F>( &mut self, query: impl ToQuery<T>, handler: F, ) -> Result<(), Error<T>>
query, calling handler for each deletion.
Duplicate matches are deleted once, in reverse order of their first occurrence.§fn delete_usages_with<F>(
&mut self,
index: T,
handler: F,
) -> Result<(), Error<T>>
fn delete_usages_with<F>( &mut self, index: T, handler: F, ) -> Result<(), Error<T>>
index as a source or target once,
calling handler for each deletion.§fn delete_usages(&mut self, index: T) -> Result<(), Error<T>>where
Self: Sized,
fn delete_usages(&mut self, index: T) -> Result<(), Error<T>>where
Self: Sized,
index as a source or target.§fn create_point(&mut self) -> Result<T, Error<T>>where
Self: Sized,
fn create_point(&mut self) -> Result<T, Error<T>>where
Self: Sized,
§fn create_link_with<F>(
&mut self,
source: T,
target: T,
handler: F,
) -> Result<Flow, Error<T>>
fn create_link_with<F>( &mut self, source: T, target: T, handler: F, ) -> Result<Flow, Error<T>>
§fn create_link(&mut self, source: T, target: T) -> Result<T, Error<T>>where
Self: Sized,
fn create_link(&mut self, source: T, target: T) -> Result<T, Error<T>>where
Self: Sized,
source to target and returns its index.§fn found(&self, query: impl ToQuery<T>) -> boolwhere
Self: Sized,
fn found(&self, query: impl ToQuery<T>) -> boolwhere
Self: Sized,
true if at least one link matches query.§fn find(&self, query: impl ToQuery<T>) -> Option<Link<T>>where
Self: Sized,
fn find(&self, query: impl ToQuery<T>) -> Option<Link<T>>where
Self: Sized,
query, or None.§fn search(&self, source: T, target: T) -> Option<T>where
Self: Sized,
fn search(&self, source: T, target: T) -> Option<T>where
Self: Sized,
source and target, or None.§fn search_or(&self, source: T, target: T, default: T) -> Twhere
Self: Sized,
fn search_or(&self, source: T, target: T, default: T) -> Twhere
Self: Sized,
use search instead
§fn single(&self, query: impl ToQuery<T>) -> Option<Link<T>>where
Self: Sized,
fn single(&self, query: impl ToQuery<T>) -> Option<Link<T>>where
Self: Sized,
query only if exactly one link matches; None otherwise.§fn get_or_create(&mut self, source: T, target: T) -> Result<T, Error<T>>where
Self: Sized,
fn get_or_create(&mut self, source: T, target: T) -> Result<T, Error<T>>where
Self: Sized,
(source, target) link, creating it if it does not exist.§fn count_usages(&self, index: T) -> Result<T, Error<T>>where
Self: Sized,
fn count_usages(&self, index: T) -> Result<T, Error<T>>where
Self: Sized,
index as a source or target.§fn usages(&self, index: T) -> Result<Vec<T>, Error<T>>where
Self: Sized,
fn usages(&self, index: T) -> Result<Vec<T>, Error<T>>where
Self: Sized,
index as a source or target.§fn exist(&self, link: T) -> boolwhere
Self: Sized,
fn exist(&self, link: T) -> boolwhere
Self: Sized,
true if the link at link exists (internal or external).§fn has_usages(&self, link: T) -> boolwhere
Self: Sized,
fn has_usages(&self, link: T) -> boolwhere
Self: Sized,
true if any other link references link as a source or target.§fn rebase_with<F>(&mut self, old: T, new: T, handler: F) -> Result<(), Error<T>>
fn rebase_with<F>(&mut self, old: T, new: T, handler: F) -> Result<(), Error<T>>
§fn rebase(&mut self, old: T, new: T) -> Result<T, Error<T>>where
Self: Sized,
fn rebase(&mut self, old: T, new: T) -> Result<T, Error<T>>where
Self: Sized,
old to new and returns new.§fn rebase_and_delete(&mut self, old: T, new: T) -> Result<T, Error<T>>where
Self: Sized,
fn rebase_and_delete(&mut self, old: T, new: T) -> Result<T, Error<T>>where
Self: Sized,
old to new, then deletes old. Returns new.§impl<T, L> Links<T> for CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T>,
impl<T, L> Links<T> for CascadeUniquenessAndUsagesResolver<T, L>where
T: LinkReference,
L: Doublets<T>,
§fn constants(&self) -> &LinksConstants<T>
fn constants(&self) -> &LinksConstants<T>
LinksConstants] (any/null/range values).§fn count_links(&self, query: &[T]) -> T
fn count_links(&self, query: &[T]) -> T
query.§fn each_links(
&self,
query: &[T],
handler: &mut dyn FnMut(Link<T>) -> Flow,
) -> Flow
fn each_links( &self, query: &[T], handler: &mut dyn FnMut(Link<T>) -> Flow, ) -> Flow
query, calling handler for each.§fn create_links(
&mut self,
query: &[T],
handler: &mut dyn FnMut(Link<T>, Link<T>) -> Flow,
) -> Result<Flow, Error<T>>
fn create_links( &mut self, query: &[T], handler: &mut dyn FnMut(Link<T>, Link<T>) -> Flow, ) -> Result<Flow, Error<T>>
query and reports each creation via handler.§fn delete_links(
&mut self,
query: &[T],
handler: &mut dyn FnMut(Link<T>, Link<T>) -> Flow,
) -> Result<Flow, Error<T>>
fn delete_links( &mut self, query: &[T], handler: &mut dyn FnMut(Link<T>, Link<T>) -> Flow, ) -> Result<Flow, Error<T>>
Auto Trait Implementations§
impl<T, L> Freeze for CascadeUniquenessAndUsagesResolver<T, L>where
L: Freeze,
impl<T, L> RefUnwindSafe for CascadeUniquenessAndUsagesResolver<T, L>where
L: RefUnwindSafe,
impl<T, L> Send for CascadeUniquenessAndUsagesResolver<T, L>
impl<T, L> Sync for CascadeUniquenessAndUsagesResolver<T, L>
impl<T, L> Unpin for CascadeUniquenessAndUsagesResolver<T, L>where
L: Unpin,
impl<T, L> UnsafeUnpin for CascadeUniquenessAndUsagesResolver<T, L>where
L: UnsafeUnpin,
impl<T, L> UnwindSafe for CascadeUniquenessAndUsagesResolver<T, L>where
L: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, L> DecoratorsExt<T> for Lwhere
T: LinkReference,
L: Doublets<T>,
impl<T, L> DecoratorsExt<T> for Lwhere
T: LinkReference,
L: Doublets<T>,
§fn with_transactions<J>(
self,
journal: J,
) -> Result<TransactionsDecorator<T, Self, J>, Error<T>>where
J: TransitionLog<T>,
fn with_transactions<J>(
self,
journal: J,
) -> Result<TransactionsDecorator<T, Self, J>, Error<T>>where
J: TransitionLog<T>,
TransactionsDecorator and recovers its journal.§fn with_uniqueness<P>(
self,
_policy: P,
) -> <P as UniquenessPolicy>::Decorator<T, Self>where
P: UniquenessPolicy,
fn with_uniqueness<P>(
self,
_policy: P,
) -> <P as UniquenessPolicy>::Decorator<T, Self>where
P: UniquenessPolicy,
§fn with_usages<P>(self, _policy: P) -> <P as UsagesPolicy>::Decorator<T, Self>where
P: UsagesPolicy,
fn with_usages<P>(self, _policy: P) -> <P as UsagesPolicy>::Decorator<T, Self>where
P: UsagesPolicy,
§fn with_usages_validation(self) -> UsagesValidator<T, Self>
fn with_usages_validation(self) -> UsagesValidator<T, Self>
UsagesValidator.§fn with_cascade_usages_resolution(self) -> CascadeUsagesResolver<T, Self>
fn with_cascade_usages_resolution(self) -> CascadeUsagesResolver<T, Self>
CascadeUsagesResolver.§fn with_inner_reference_existence_validation(
self,
) -> InnerReferenceExistenceValidator<T, Self>
fn with_inner_reference_existence_validation( self, ) -> InnerReferenceExistenceValidator<T, Self>
InnerReferenceExistenceValidator.§fn with_non_existent_dependencies_creation(
self,
) -> NonExistentDependenciesCreator<T, Self>
fn with_non_existent_dependencies_creation( self, ) -> NonExistentDependenciesCreator<T, Self>
NonExistentDependenciesCreator.§fn with_non_existent_deletion_resolution(
self,
) -> NonExistentDeletionResolver<T, Self>
fn with_non_existent_deletion_resolution( self, ) -> NonExistentDeletionResolver<T, Self>
NonExistentDeletionResolver, ignoring deletion of missing links.§fn with_itself_constant_resolution(
self,
) -> ItselfConstantToSelfReferenceResolver<T, Self>
fn with_itself_constant_resolution( self, ) -> ItselfConstantToSelfReferenceResolver<T, Self>
ItselfConstantToSelfReferenceResolver.§fn with_null_constant_resolution(
self,
) -> NullConstantToSelfReferenceResolver<T, Self>
fn with_null_constant_resolution( self, ) -> NullConstantToSelfReferenceResolver<T, Self>
NullConstantToSelfReferenceResolver.§fn with_non_null_contents_deletion_resolution(
self,
) -> NonNullContentsLinkDeletionResolver<T, Self>
fn with_non_null_contents_deletion_resolution( self, ) -> NonNullContentsLinkDeletionResolver<T, Self>
NonNullContentsLinkDeletionResolver.§fn with_logging<W>(self, writer: W) -> LoggingDecorator<T, Self, W>
fn with_logging<W>(self, writer: W) -> LoggingDecorator<T, Self, W>
LoggingDecorator, logging every mutation to writer.§fn with_no_exceptions(self) -> NoExceptionsDecorator<T, Self>
fn with_no_exceptions(self) -> NoExceptionsDecorator<T, Self>
NoExceptionsDecorator.§fn with_automatic_uniqueness_and_usages_resolution(
self,
) -> CascadeUniquenessAndUsagesResolver<T, NonNullContentsLinkDeletionResolver<T, CascadeUsagesResolver<T, Self>>>
fn with_automatic_uniqueness_and_usages_resolution( self, ) -> CascadeUniquenessAndUsagesResolver<T, NonNullContentsLinkDeletionResolver<T, CascadeUsagesResolver<T, Self>>>
ILinksExtensions.DecorateWithAutomaticUniquenessAndUsagesResolution:
CascadeUsagesResolver innermost, then NonNullContentsLinkDeletionResolver,
then CascadeUniquenessAndUsagesResolver outermost.
The cascade explicitly resets each nested usage before descending, so handlers
observe resets before the corresponding deletions, as with C#’s facade recursion. Read more§impl<T, All> DoubletsExt<T> for Allwhere
T: LinkReference,
All: Doublets<T>,
impl<T, All> DoubletsExt<T> for Allwhere
T: LinkReference,
All: Doublets<T>,
§fn iter(
&self,
) -> impl Iterator<Item = Link<T>> + ExactSizeIterator + DoubleEndedIterator
fn iter( &self, ) -> impl Iterator<Item = Link<T>> + ExactSizeIterator + DoubleEndedIterator
§fn each_iter(
&self,
query: impl ToQuery<T>,
) -> impl Iterator<Item = Link<T>> + ExactSizeIterator + DoubleEndedIterator
fn each_iter( &self, query: impl ToQuery<T>, ) -> impl Iterator<Item = Link<T>> + ExactSizeIterator + DoubleEndedIterator
query.