Merge pull request #239 from epage/features

chore(cli): Allow building without expensive parts
This commit is contained in:
Ed Page 2021-05-01 08:54:00 -05:00 committed by GitHub
commit 9883886664
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 8 deletions

1
Cargo.lock generated
View file

@ -1558,6 +1558,7 @@ dependencies = [
"typos-vars", "typos-vars",
"unicase", "unicase",
"unicode-segmentation", "unicode-segmentation",
"varcon-core",
] ]
[[package]] [[package]]

View file

@ -21,6 +21,14 @@ keywords = ["development", "spelling"]
license = "MIT" license = "MIT"
edition = "2018" edition = "2018"
[features]
default = ["dict", "vars"]
dict = ["typos-dict"]
vars = ["typos-vars"]
[package.metadata.docs.rs]
no-default-features = true
[package.metadata.release] [package.metadata.release]
pre-release-replacements = [ pre-release-replacements = [
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1}, {file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1},
@ -41,8 +49,9 @@ codecov = { repository = "crate-ci/typos" }
[dependencies] [dependencies]
typos = { version = "^0.4", path = "crates/typos" } typos = { version = "^0.4", path = "crates/typos" }
typos-dict = { version = "^0.3", path = "crates/typos-dict" } varcon-core = { version = "1.1.0", path = "crates/varcon-core" }
typos-vars = { version = "^0.3", path = "crates/typos-vars" } typos-dict = { version = "^0.3", path = "crates/typos-dict", optional = true }
typos-vars = { version = "^0.3", path = "crates/typos-vars", optional = true }
phf = { version = "0.8", features = ["unicase"] } phf = { version = "0.8", features = ["unicase"] }
unicase = "2.5" unicase = "2.5"
anyhow = "1.0" anyhow = "1.0"

View file

@ -41,6 +41,10 @@ stages:
displayName: Check that Cargo.lock is satisfiable displayName: Check that Cargo.lock is satisfiable
- script: cargo check --workspace --all-targets - script: cargo check --workspace --all-targets
displayName: Default features displayName: Default features
- script: cargo check --all-targets --no-default-features
displayName: No features
- script: cargo check --all-targets --all-features
displayName: All features
- stage: test - stage: test
displayName: Test displayName: Test
jobs: jobs:

View file

@ -353,13 +353,13 @@ pub enum Locale {
} }
impl Locale { impl Locale {
pub const fn category(self) -> Option<typos_vars::Category> { pub const fn category(self) -> Option<varcon_core::Category> {
match self { match self {
Locale::En => None, Locale::En => None,
Locale::EnUs => Some(typos_vars::Category::American), Locale::EnUs => Some(varcon_core::Category::American),
Locale::EnGb => Some(typos_vars::Category::BritishIse), Locale::EnGb => Some(varcon_core::Category::BritishIse),
Locale::EnCa => Some(typos_vars::Category::Canadian), Locale::EnCa => Some(varcon_core::Category::Canadian),
Locale::EnAu => Some(typos_vars::Category::Australian), Locale::EnAu => Some(varcon_core::Category::Australian),
} }
} }

View file

@ -8,7 +8,7 @@ use typos::Status;
#[derive(Default)] #[derive(Default)]
pub struct BuiltIn { pub struct BuiltIn {
locale: Option<typos_vars::Category>, locale: Option<varcon_core::Category>,
} }
impl BuiltIn { impl BuiltIn {
@ -46,6 +46,7 @@ impl BuiltIn {
Some(corrections) Some(corrections)
} }
#[cfg(feature = "dict")]
// Not using `Status` to avoid the allocations // Not using `Status` to avoid the allocations
fn correct_with_dict(&self, word: &str) -> Option<&'static str> { fn correct_with_dict(&self, word: &str) -> Option<&'static str> {
const WORD_RANGE: std::ops::RangeInclusive<usize> = const WORD_RANGE: std::ops::RangeInclusive<usize> =
@ -57,6 +58,12 @@ impl BuiltIn {
} }
} }
#[cfg(not(feature = "dict"))]
fn correct_with_dict(&self, _word: &str) -> Option<&'static str> {
None
}
#[cfg(feature = "vars")]
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> { fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
const WORD_RANGE: std::ops::RangeInclusive<usize> = const WORD_RANGE: std::ops::RangeInclusive<usize> =
typos_vars::WORD_MIN..=typos_vars::WORD_MAX; typos_vars::WORD_MIN..=typos_vars::WORD_MAX;
@ -68,6 +75,12 @@ impl BuiltIn {
} }
} }
#[cfg(not(feature = "vars"))]
fn correct_with_vars(&self, _word: &str) -> Option<Status<'static>> {
None
}
#[cfg(feature = "vars")]
fn select_variant( fn select_variant(
&self, &self,
vars: &'static [(u8, &'static typos_vars::VariantsMap)], vars: &'static [(u8, &'static typos_vars::VariantsMap)],