Diffstat (limited to 'src/impls/core/reference_mut.rs')
-rw-r--r--src/impls/core/reference_mut.rs82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/impls/core/reference_mut.rs b/src/impls/core/reference_mut.rs
index 5f0eff7..98427fe 100644
--- a/src/impls/core/reference_mut.rs
+++ b/src/impls/core/reference_mut.rs
@@ -1,15 +1,19 @@
use core::any::Any;
use crate::{
- protocol::{lookup_visit, VisitorMissingProtocol, WalkerMissingProtocol, lookup_hint, ProtocolId, AnyVisit, Visit},
+ build::{Build, Builder},
+ protocol::{
+ lookup_hint, lookup_visit, AnyVisit, ProtocolId, Visit, VisitorMissingProtocol,
+ WalkerMissingProtocol,
+ },
protocols::reference,
- walk::{WalkMut, WalkOnce, Walk},
- Visitor, Walker, ControlFlow, build::{Builder, Build},
+ walk::{Walk, WalkMut, WalkOnce},
+ ControlFlow, Visitor, Walker,
};
impl<'borrow, 'ctx, T> WalkOnce<'ctx> for &'borrow mut T
where
- T: WalkMut<'borrow, 'ctx>
+ T: WalkMut<'borrow, 'ctx>,
{
type Error = T::Error;
@@ -20,18 +24,21 @@ where
}
}
-impl<'borrow, 'ctx, T> WalkMut<'borrow, 'ctx> for &'borrow mut T
-where
- T: WalkMut<'borrow, 'ctx>
+impl<'borrow, 'ctx, T> WalkMut<'borrow, 'ctx> for &'borrow mut T
+where
+ T: WalkMut<'borrow, 'ctx>,
{
- fn walk_mut(&'borrow mut self, visitor: &mut dyn Visitor<'ctx>) -> Result<Self::Value, Self::Error> {
+ fn walk_mut(
+ &'borrow mut self,
+ visitor: &mut dyn Visitor<'ctx>,
+ ) -> Result<Self::Value, Self::Error> {
T::walk_mut(self, visitor)
}
}
-impl<'borrow, 'ctx, T> Walk<'borrow, 'ctx> for &'borrow mut T
-where
- T: Walk<'borrow, 'ctx>
+impl<'borrow, 'ctx, T> Walk<'borrow, 'ctx> for &'borrow mut T
+where
+ T: Walk<'borrow, 'ctx>,
{
fn walk(&'borrow self, visitor: &mut dyn Visitor<'ctx>) -> Result<Self::Value, Self::Error> {
T::walk(self, visitor)
@@ -44,35 +51,27 @@ impl<'ctx, T: ?Sized + Any> Build<'ctx> for &'ctx mut T {
pub struct MutWalker<'ctx, T: ?Sized> {
value: Option<&'ctx mut T>,
- error: Option<VisitorMissingProtocol>,
}
impl<'ctx, T: ?Sized> MutWalker<'ctx, T> {
pub fn new(value: &'ctx mut T) -> Self {
Self {
value: Some(value),
- error: None,
}
}
-
- pub fn into_error(self) -> Option<VisitorMissingProtocol> {
- self.error
- }
}
-impl<'ctx:, T: ?Sized + Any> Walker<'ctx> for MutWalker<'ctx, T> {
- fn walk(&mut self, visitor: &mut dyn Visitor<'ctx>) -> ControlFlow {
+impl<'ctx, T: ?Sized + Any> WalkOnce<'ctx> for MutWalker<'ctx, T> {
+ type Error = VisitorMissingProtocol;
+
+ type Value = ();
+
+ fn walk_once(mut self, visitor: &mut dyn Visitor<'ctx>) -> Result<Self::Value, Self::Error> {
if let Some(value) = self.value.take() {
- match lookup_visit::<reference::ReferenceMut<T>, _>(visitor) {
- Ok(visit) => visit.visit(reference::Mut::Context(value)).to_done(),
- Err(err) => {
- self.error = Some(err);
- ControlFlow::Continue
- },
- }
- } else {
- ControlFlow::Done
+ let visit = lookup_visit::<reference::ReferenceMut<T>, _>(visitor)?;
+ visit.visit(reference::Mut::Context(value));
}
+ Ok(())
}
}
@@ -85,7 +84,7 @@ pub enum Error {
ShortLifetime,
#[error(transparent)]
- MissingProtocol(#[from] WalkerMissingProtocol)
+ MissingProtocol(#[from] WalkerMissingProtocol),
}
pub struct MutBuilder<'ctx, T: ?Sized> {
@@ -119,19 +118,22 @@ impl<'ctx, T: ?Sized + Any> Builder<'ctx> for MutBuilder<'ctx, T> {
impl<'ctx, T: ?Sized + Any> Visitor<'ctx> for MutBuilder<'ctx, T> {
fn request_hint(
&mut self,
- hints: &mut dyn crate::WalkerHints<'ctx>,
+ hints: &mut dyn crate::Walker<'ctx>,
_need_hint: bool,
) -> ControlFlow {
match lookup_hint::<reference::Reference<T>, _>(hints) {
- Ok(hint) => hint.hint(self, reference::Hint {
- kind: Some(reference::Kind::Context),
- min_len: None,
- max_len: None,
- }),
+ Ok(hint) => hint.hint(
+ self,
+ reference::Hint {
+ kind: Some(reference::Kind::Context),
+ min_len: None,
+ max_len: None,
+ },
+ ),
Err(err) => {
self.value = Some(Err(err.into()));
ControlFlow::Error
- },
+ }
}
}
@@ -150,13 +152,11 @@ impl<'ctx, T: ?Sized + Any> Visit<'ctx, reference::ReferenceMut<T>> for MutBuild
reference::Mut::Walking(_) => {
self.value = Some(Err(Error::ShortLifetime));
ControlFlow::Continue
- },
- reference::Mut::Context(value) |
- reference::Mut::Static(value) => {
+ }
+ reference::Mut::Context(value) | reference::Mut::Static(value) => {
self.value = Some(Ok(value));
ControlFlow::Done
- },
+ }
}
-
}
}