Created
March 16, 2023 16:54
-
-
Save shtsoft/fbec95185b928713607e1883e5669e81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod reset { | |
pub trait Reset<C> { | |
fn reset<B, K>(self, shift: impl FnOnce(K) -> C, k: K) -> C | |
where | |
K: FnOnce(B) -> C; | |
} | |
pub struct CallBack {} | |
impl<C> Reset<C> for CallBack { | |
fn reset<B, K>(self, shift: impl FnOnce(K) -> C, k: K) -> C | |
where | |
K: FnOnce(B) -> C, | |
{ | |
shift(k) | |
} | |
} | |
pub fn thirteen(reset_handler: impl Reset<usize>) { | |
let shift_k = |k: fn(usize) -> usize| k(1) + k(3); | |
let thirteen = 5 + reset_handler.reset(shift_k, |n| n + 2); | |
println!("Result: {thirteen}",); | |
} | |
} | |
use reset::*; | |
fn main() { | |
thirteen(CallBack {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment