Created
July 12, 2024 20:07
-
-
Save kognise/d45d8317e92814a7d0a697c8198df800 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
struct Container<'a> { | |
process: &'a mut dyn FnMut(), | |
} | |
// ... | |
struct ContainerOwner<'a> { | |
container: Container<'a>, | |
} | |
impl<'a> ContainerOwner<'a> { | |
fn new(container: Container<'a>) -> Self { | |
Self { container } | |
} | |
} | |
fn use_container(owner: &mut ContainerOwner) { | |
(owner.container.process)(); | |
} | |
// ... | |
fn foo() {} | |
fn main() { | |
let mut x = ContainerOwner::new(Container { process: &mut foo }); | |
use_container(&mut x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment