changed
| -rw-r--r-- | src/impls/core/str.rs | 22 | ||||
| -rw-r--r-- | tests/demo.rs | 14 |
2 files changed, 20 insertions, 16 deletions
diff --git a/src/impls/core/str.rs b/src/impls/core/str.rs index 77ef5cc..6eec1e1 100644 --- a/src/impls/core/str.rs +++ b/src/impls/core/str.rs @@ -17,8 +17,8 @@ use super::reference::BuilderRefValue; pub struct Walker<'value>(&'value str); -impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> crate::Walker<'value, 'ctx, VisitorErr> - for Walker<'borrow> +impl<'value, 'ctx: 'value, VisitorErr: 'value> crate::Walker<'value, 'ctx, VisitorErr> + for Walker<'ctx> { type Error = BasicError; @@ -28,7 +28,7 @@ impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> crate::Walker<' ) -> Result<crate::WalkStatus, UniError<Self::Error, VisitorErr>> { match lookup_visit::<Reference<str>, _, _>(visitor).map_err(UniError::Walker)? { Some(visitor) => { - visitor.visit(reference::Ref::Value(self.0))?; + visitor.visit(reference::Ref::Context(self.0))?; Ok(crate::WalkStatus::Continue) } None => Err(UniError::Walker(BasicError::new( @@ -45,8 +45,8 @@ impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> crate::Walker<' } } -impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> WalkerHints<'value, 'ctx, VisitorErr> - for Walker<'borrow> +impl<'value, 'ctx: 'value, VisitorErr: 'value> WalkerHints<'value, 'ctx, VisitorErr> + for Walker<'ctx> { type Error = BasicError; @@ -61,8 +61,8 @@ impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> WalkerHints<'va } } -impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> Hint<'value, 'ctx, Reference<str>, VisitorErr> - for Walker<'borrow> +impl<'value, 'ctx: 'value, VisitorErr: 'value> Hint<'value, 'ctx, Reference<str>, VisitorErr> + for Walker<'ctx> { type Error = BasicError; @@ -76,7 +76,7 @@ impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> Hint<'value, 'c .ok_or_else(|| { UniError::Walker(BasicError::new("visitor is missing the str protocol")) })? - .visit(reference::Ref::Value(self.0))?; + .visit(reference::Ref::Context(self.0))?; Ok(HintGiven) } @@ -111,11 +111,11 @@ impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> Hint<'value, 'c // } // } -impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> Walk<'value, 'borrow, 'ctx, VisitorErr> for str { +impl<'value, 'borrow: 'value, 'ctx: 'borrow, VisitorErr: 'value> Walk<'value, 'ctx, 'ctx, VisitorErr> for str { type Error = BasicError; - type Walker = Walker<'borrow>; + type Walker = Walker<'ctx>; - fn walker(&'borrow self) -> Self::Walker { + fn walker(&'ctx self) -> Self::Walker { Walker(self) } } diff --git a/tests/demo.rs b/tests/demo.rs index 27a3782..c0fe77e 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -6,6 +6,8 @@ fn demo() { // let y: &str = build_from_ref::<'_, 'static, BuilderRefValue<str>, _, _>(&*x).unwrap(); let y: &str = uniserde::transform::from_ref(&*x).unwrap(); dbg!(y); + let y: &str = example(&&&&&&&*x); + dbg!(y); // let y: &String = uniserde::transform::from(&*x).unwrap(); // dbg!(y); @@ -13,8 +15,10 @@ fn demo() { todo!(); } -// #[no_mangle] -// pub fn example<'a>(a: &&&&&&'a str) -> &'a str { -// // uniserde::transform::from(a).unwrap() -// build_from::<BuilderRefContext<str>, _, _>(a).unwrap() -// } +#[no_mangle] +pub fn example<'a>(a: &&&&&&'a str) -> &'a str { + // uniserde::transform::from(a).unwrap() + build_from_ref::<BuilderRefContext<str>, _, _>(a).unwrap() +} + +// default everything to value, have wrappers for context and static borrows |