Created
September 26, 2021 21:33
-
-
Save felipesere/77e82b5e0bea3d40da6e210063211deb to your computer and use it in GitHub Desktop.
Desire to build a clean API will stashing away resources for later use...
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 Provider<A> { | |
api: A, | |
tracked_resources: TrackedResources, | |
} | |
struct Api { ...}; | |
impl Api { | |
fn create_thing() -> ThingBuilder {...} | |
} | |
impl Deref for Provider<A> { | |
type Target = A | |
... | |
} | |
impl DerefMut for Provider<A> { | |
... | |
} | |
fn main() { | |
let api = ...; | |
let provider = Provider::new(api); | |
let thing: Arc<Thing> = provider.create_thing().foo(1).bar("yay!").build(); | |
// At this point, it would be nice if provider.tracked_resources contained an Arc<Thing> in its collection... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment