Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Created October 24, 2020 01:10
Show Gist options
  • Save jayhuang75/7b661b595cf181b4a5915d62fbaa03d5 to your computer and use it in GitHub Desktop.
Save jayhuang75/7b661b595cf181b4a5915d62fbaa03d5 to your computer and use it in GitHub Desktop.
SMS Alert Covid
#[async_trait(?Send)]
pub trait Producer {
async fn run(&self, covid: &CovidReport) -> Result<(), Box<dyn Error>>;
}
pub struct CovidReport {
pub report: Vec<CovidStats>,
// any type inside a Box must implement the Producer trait.
producer: Box<dyn Producer>,
}
#[derive(Debug, Default, Clone)]
pub struct CovidStats {
pub pruid: String,
pub prname: String,
pub date: String,
pub numtoday: u64,
pub numdeathstoday: u64,
}
impl CovidReport {
pub async fn producer(&self) {
let _p = self.producer.run(&self).await;
}
pub fn new(report: Vec<CovidStats>, producer: Box<dyn Producer>) -> Self {
CovidReport { report, producer }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment