Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a method to extract the current test/vaccine/recovery data from a DgcContainer #10

Open
lmammino opened this issue Nov 21, 2021 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers low priority

Comments

@lmammino
Copy link
Member

First of all, it would be convenient to have a way to distinguish between test, recovery and vaccine data through an enum. This might look like the following code:

#[derive(Debug)]
pub enum CertData<'a> {
    RecoveryData(&'a Recovery),
    TestData(&'a Test),
    VaccinationData(&'a Vaccination),
}

Once we have this, DgcContainer could implement a method like get_first_cert() which might work as follows (untested):

impl DgcContainer {
    pub fn get_first_cert(&self) -> Option<CertData<'_>> {
        for (_, certs) in self.certs.iter() {
            if let Some(v) = certs.v.first() {
                return Some(CertData::VaccinationData(v));
            }

            if let Some(t) = certs.t.first() {
                return Some(CertData::TestData(t));
            }

            if let Some(r) = certs.r.first() {
                return Some(CertData::RecoveryData(r));
            }
        }

        None
    }
}

A structurally valid Dgc should contain only one entry, so we can use this method to extract that easily.

@lmammino lmammino added enhancement New feature or request low priority labels Nov 21, 2021
@lu-zero
Copy link
Collaborator

lu-zero commented Nov 24, 2021

A get_best_cert() and get_last_cert() might be of use?

@lmammino lmammino added the good first issue Good for newcomers label Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers low priority
Projects
None yet
Development

No branches or pull requests

2 participants