diff options
| author | Andreas Grois <andi@grois.info> | 2023-04-02 21:59:22 +0200 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2023-04-02 21:59:22 +0200 |
| commit | cebdd3be32d50be379663e92d4428e6bba19ba51 (patch) | |
| tree | 8c5b57f2e2ed3c089e0546fdb95ef8c2082d1952 /tests/with_lifetimes.rs | |
| parent | 418f514fc46f45ae2901753e3398adb33664bed9 (diff) | |
Run cargo fmt
I think readability was better before that...
Diffstat (limited to 'tests/with_lifetimes.rs')
| -rw-r--r-- | tests/with_lifetimes.rs | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/tests/with_lifetimes.rs b/tests/with_lifetimes.rs index 697fc74..ee35274 100644 --- a/tests/with_lifetimes.rs +++ b/tests/with_lifetimes.rs @@ -3,34 +3,47 @@ //! Test for the case that the Functor the Free Monad is based on has lifetime parameters that do not depend on the //! lifetime of the mapping function in the Functor implementation. +use higher::{Apply, Bind, Functor}; use higher_free_macro::free; -use higher::{Functor, Bind, Apply}; #[derive(Functor, Clone)] -struct WithLifetimes<'a,'b, A>{ - s1 : &'a str, - s2 : &'b str, - next : A +struct WithLifetimes<'a, 'b, A> { + s1: &'a str, + s2: &'b str, + next: A, } -free!(FreeWithLifetimes<'a,'b,A>, WithLifetimes<'a,'b,FreeWithLifetimes<'a,'b,A>>); +free!( + FreeWithLifetimes<'a, 'b, A>, + WithLifetimes<'a, 'b, FreeWithLifetimes<'a, 'b, A>> +); -fn lifetime_helper<'a,'b>(s1 : &'a str, s2 : &'b str) -> FreeWithLifetimes<'a, 'b, u32>{ - let fv = FreeWithLifetimes::lift_f(WithLifetimes{ s1, s2, next: 15}); - fv.fmap(|x| x+1) +fn lifetime_helper<'a, 'b>(s1: &'a str, s2: &'b str) -> FreeWithLifetimes<'a, 'b, u32> { + let fv = FreeWithLifetimes::lift_f(WithLifetimes { s1, s2, next: 15 }); + fv.fmap(|x| x + 1) } #[test] -fn test_with_lifetimes(){ +fn test_with_lifetimes() { let s1 = "First"; let s2 = "Second"; let fv = lifetime_helper(s1, s2); let s3 = "Third"; let s4 = "Fourth"; - let fv = fv.bind(|x| FreeWithLifetimes::lift_f(WithLifetimes{ s1: s3, s2: s4, next : x+2})); + let fv = fv.bind(|x| { + FreeWithLifetimes::lift_f(WithLifetimes { + s1: s3, + s2: s4, + next: x + 2, + }) + }); let s5 = "Fifth"; let s6 = "Sixth"; - let fa = FreeWithLifetimes::lift_f(WithLifetimes{s1: s5, s2: s6, next : (|x| x+3).into()}); + let fa = FreeWithLifetimes::lift_f(WithLifetimes { + s1: s5, + s2: s6, + next: (|x| x + 3).into(), + }); let fv = fv.apply(fa); match fv { FreeWithLifetimes::Free(v) => { @@ -48,15 +61,15 @@ fn test_with_lifetimes(){ FreeWithLifetimes::Free(_) => unreachable!(), FreeWithLifetimes::Pure(a) => { assert_eq!(a, 21); - }, + } } - }, + } FreeWithLifetimes::Pure(_) => unreachable!(), } - }, + } FreeWithLifetimes::Pure(_) => unreachable!(), } - }, - FreeWithLifetimes::Pure(_) => unreachable!() + } + FreeWithLifetimes::Pure(_) => unreachable!(), } -}
\ No newline at end of file +} |
