Created
October 24, 2020 01:10
-
-
Save jayhuang75/7b661b595cf181b4a5915d62fbaa03d5 to your computer and use it in GitHub Desktop.
SMS Alert Covid
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
#[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