Created
September 20, 2021 07:33
-
-
Save felipesere/b135230c5ea053f5df5a40cb31cf6e34 to your computer and use it in GitHub Desktop.
Show how I want to track homogenous resources in a provider but still return a specific type so users can still interact with it - even if read-only.
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
pub struct AwsProvider(Inner); | |
struct Inner { | |
creds: Credentials, | |
region: String, | |
tracked_resources: RwLock<Vec<Box<dyn Resource<Aws>>>>, | |
} | |
// TODO: it would be nice if this could magically put the | |
// reosurce on the heap (Arc<Box<...>>) and then return | |
// something like Arc<Box<T>>, assuming `track<T>` | |
pub fn track(&mut self, resource: Box<dyn Resource<Aws>>) { | |
self.0.tracked_resources.write().unwrap().push(resource); | |
} | |
// ----------------------------------------------------------- | |
// different file... | |
// ----------------------------------------------------------- | |
// This is the end of a "builder" that will stash away the resource for later usage: | |
pub fn build(mut self) -> Option<Arc<Box<Bucket>>> { | |
let bucket = Bucket { Bucket | |
name: self.name, | |
acl: self.acl, | |
website: self.website, | |
tags: self.tags, | |
}; | |
// TODO: this is annoying! | |
// receive a Arc<Box<Bucket>> in return. | |
// `track(...)` needs to work with `dyn Resource<C: Cloud>` though. | |
let to_be_stashed_away: Box<dyn Resource<Aws>> = Box::new(bucket.clone()); | |
self.provider.track(to_be_stashed_away); | |
Some(Arc::new(Box::new(bucket))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have left out the
aysnc
part fromasync_trait
thinking it might have something to do with it but no 😢And the error is: