Skip to content

Commit

Permalink
Merge pull request #239 from epage/features
Browse files Browse the repository at this point in the history
chore(cli): Allow building without expensive parts
  • Loading branch information
epage authored May 1, 2021
2 parents 14f1532 + 2fc1f54 commit 9883886
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ keywords = ["development", "spelling"]
license = "MIT"
edition = "2018"

[features]
default = ["dict", "vars"]
dict = ["typos-dict"]
vars = ["typos-vars"]

[package.metadata.docs.rs]
no-default-features = true

[package.metadata.release]
pre-release-replacements = [
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1},
Expand All @@ -41,8 +49,9 @@ codecov = { repository = "crate-ci/typos" }

[dependencies]
typos = { version = "^0.4", path = "crates/typos" }
typos-dict = { version = "^0.3", path = "crates/typos-dict" }
typos-vars = { version = "^0.3", path = "crates/typos-vars" }
varcon-core = { version = "1.1.0", path = "crates/varcon-core" }
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"] }
unicase = "2.5"
anyhow = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ stages:
displayName: Check that Cargo.lock is satisfiable
- script: cargo check --workspace --all-targets
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
displayName: Test
jobs:
Expand Down
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ pub enum Locale {
}

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

Expand Down
15 changes: 14 additions & 1 deletion src/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use typos::Status;

#[derive(Default)]
pub struct BuiltIn {
locale: Option<typos_vars::Category>,
locale: Option<varcon_core::Category>,
}

impl BuiltIn {
Expand Down Expand Up @@ -46,6 +46,7 @@ impl BuiltIn {
Some(corrections)
}

#[cfg(feature = "dict")]
// Not using `Status` to avoid the allocations
fn correct_with_dict(&self, word: &str) -> Option<&'static str> {
const WORD_RANGE: std::ops::RangeInclusive<usize> =
Expand All @@ -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>> {
const WORD_RANGE: std::ops::RangeInclusive<usize> =
typos_vars::WORD_MIN..=typos_vars::WORD_MAX;
Expand All @@ -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(
&self,
vars: &'static [(u8, &'static typos_vars::VariantsMap)],
Expand Down

0 comments on commit 9883886

Please sign in to comment.