Skip to content

Instantly share code, notes, and snippets.

@kognise
Created July 12, 2024 20:07
Show Gist options
  • Save kognise/d45d8317e92814a7d0a697c8198df800 to your computer and use it in GitHub Desktop.
Save kognise/d45d8317e92814a7d0a697c8198df800 to your computer and use it in GitHub Desktop.
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