Created
February 28, 2026 23:12
-
-
Save brian-pane/a3c001122b5f8c1e168e72b2fa1af730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
| 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