Skip to content

Instantly share code, notes, and snippets.

@shtsoft
Created March 16, 2023 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shtsoft/fbec95185b928713607e1883e5669e81 to your computer and use it in GitHub Desktop.
Save shtsoft/fbec95185b928713607e1883e5669e81 to your computer and use it in GitHub Desktop.
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