Skip to content

Instantly share code, notes, and snippets.

@felipesere
Created September 26, 2021 21:33
Show Gist options
  • Save felipesere/77e82b5e0bea3d40da6e210063211deb to your computer and use it in GitHub Desktop.
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...
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