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 better way to remeber the previously added taxonomy Rank #19

Open
jeanmanguy opened this issue Oct 24, 2020 · 0 comments
Open
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jeanmanguy
Copy link
Owner

spideog/src/taxonomy.rs

Lines 9 to 10 in 1f8583a

static LAST_TAXONOMY_RANK_PARSED: Lazy<Mutex<Option<TaxonomyRank>>> =
Lazy::new(|| Mutex::new(None));

spideog/src/taxonomy.rs

Lines 47 to 62 in 1f8583a

impl TaxonomyRank {
pub fn plus_one(self) -> Self {
match self {
Self::Unclassified(i) => Self::Unclassified(i.checked_add(1).unwrap()),
Self::Root(i) => Self::Root(i.checked_add(1).unwrap()),
Self::Domain(i) => Self::Domain(i.checked_add(1).unwrap()),
Self::Kingdom(i) => Self::Kingdom(i.checked_add(1).unwrap()),
Self::Phylum(i) => Self::Phylum(i.checked_add(1).unwrap()),
Self::Class(i) => Self::Class(i.checked_add(1).unwrap()),
Self::Order(i) => Self::Order(i.checked_add(1).unwrap()),
Self::Family(i) => Self::Family(i.checked_add(1).unwrap()),
Self::Genus(i) => Self::Genus(i.checked_add(1).unwrap()),
Self::Species(i) => Self::Species(i.checked_add(1).unwrap()),
}
}
}

spideog/src/taxonomy.rs

Lines 103 to 110 in 1f8583a

if let Some(previous_tax_rank) = *LAST_TAXONOMY_RANK_PARSED.lock().unwrap() {
// TODO: there has to be a better way to do that, maybe without the mutex business
Ok(previous_tax_rank.plus_one())
} else {
Err(ErrorKind::TaxRankParsingCannotInferRank(String::from(
string,
)))
}

@jeanmanguy jeanmanguy added the enhancement New feature or request label Oct 24, 2020
@jeanmanguy jeanmanguy self-assigned this Oct 24, 2020
@jeanmanguy jeanmanguy added the help wanted Extra attention is needed label Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant