Skip to content

Instantly share code, notes, and snippets.

@brian-pane
Created February 28, 2026 23:12
Show Gist options
  • Select an option

  • Save brian-pane/a3c001122b5f8c1e168e72b2fa1af730 to your computer and use it in GitHub Desktop.

Select an option

Save brian-pane/a3c001122b5f8c1e168e72b2fa1af730 to your computer and use it in GitHub Desktop.
struct Container {
inner: u32,
}
impl<'a> Container {
fn new() -> Self {
Self { inner: 1 }
}
fn expensive_lookup(&'a self) -> &'a u32 {
&self.inner
}
}
struct PreCached<'a> {
container: Container,
value: &'a u32
}
fn create<'a>() -> PreCached<'a> {
let container = Container::new();
let value = container.expensive_lookup();
PreCached { container, value: &value }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment