Skip to content

Commit

Permalink
refactor features
Browse files Browse the repository at this point in the history
noib3 committed Dec 2, 2023

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
1 parent 5fd107b commit 92dc405
Showing 8 changed files with 45 additions and 22 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@nightly
- run: cargo test --features tests --no-fail-fast
- run: cargo test --all-features --no-fail-fast

bench:
name: bench
@@ -27,8 +27,8 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
- run: cargo bench --all-features --no-run

clippy:
name: clippy
clippy-all-features:
name: clippy-all-features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@@ -37,6 +37,16 @@ jobs:
components: clippy
- run: cargo clippy --all-features --all-targets -- -D warnings

clippy-no-features:
name: clippy-no-features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- run: cargo clippy --all-targets -- -D warnings

docs:
name: docs
runs-on: ubuntu-latest
25 changes: 15 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -5,42 +5,47 @@ edition = "2021"
authors = ["Riccardo Mazzarini <me@noib3.dev>"]

[features]
fzf-v1 = []
fzf-v2 = []
fzf-v1 = ["__any-metric"]
fzf-v2 = ["__any-metric"]

# Private features.
bench = ["tests"]
into-score = []
tests = ["fzf-v1", "fzf-v2"]
__any-metric = []
__benches = []
__into-score = []
__tests = []

[dependencies]
memchr = "2"

[dev-dependencies]
criterion = "0.5"

[[test]]
name = "fzf_common"
required-features = ["__tests"]

[[test]]
name = "fzf_v1"
required-features = ["tests"]
required-features = ["__tests"]

[[test]]
name = "fzf_v2"
required-features = ["tests"]
required-features = ["__tests"]

[[bench]]
name = "fzf_common"
harness = false
required-features = ["bench"]
required-features = ["__benches"]

[[bench]]
name = "fzf_v1"
harness = false
required-features = ["bench"]
required-features = ["__benches"]

[[bench]]
name = "fzf_v2"
harness = false
required-features = ["bench"]
required-features = ["__benches"]

[[example]]
name = "cities"
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -81,16 +81,24 @@

extern crate alloc;

#[cfg(feature = "__any-metric")]
mod candidate;
mod case_sensitivity;
#[cfg(feature = "__any-metric")]
mod matched_ranges;
mod metric;
#[cfg(feature = "__any-metric")]
mod metrics;
#[cfg(feature = "__any-metric")]
mod normalize;
#[cfg(feature = "__any-metric")]
mod utils;

#[cfg(feature = "__any-metric")]
use candidate::{Candidate, CandidateMatches};
pub use case_sensitivity::CaseSensitivity;
#[cfg(feature = "__any-metric")]
use matched_ranges::MatchedRanges;
pub use metric::Metric;
#[cfg(feature = "__any-metric")]
pub use metrics::*;
2 changes: 1 addition & 1 deletion src/metrics/fzf/distance.rs
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ impl FzfDistance {
/// This is not part of the public API and should not be relied upon.
///
/// It's only used internally for testing and debugging purposes.
#[cfg(any(feature = "into-score", feature = "tests"))]
#[cfg(any(feature = "__into-score", feature = "__tests"))]
#[inline(always)]
pub fn into_score(self) -> Score {
self.0
2 changes: 1 addition & 1 deletion src/metrics/fzf/fzf_v1.rs
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ impl FzfV1 {
}

/// Returns the current scoring scheme. This is only used for testing.
#[cfg(feature = "tests")]
#[cfg(feature = "__tests")]
pub fn scheme(&self) -> &Scheme {
&self.scoring_scheme
}
2 changes: 1 addition & 1 deletion src/metrics/fzf/fzf_v2.rs
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ impl FzfV2 {
}

/// Returns the current scoring scheme. This is only used for testing.
#[cfg(feature = "tests")]
#[cfg(feature = "__tests")]
pub fn scheme(&self) -> &Scheme {
&self.scoring_scheme
}
4 changes: 2 additions & 2 deletions src/metrics/fzf/parser.rs
Original file line number Diff line number Diff line change
@@ -396,7 +396,7 @@ impl<'buf> Iterator for Words<'buf, '_> {
}

/// TODO: docs
#[cfg(feature = "tests")]
#[cfg(feature = "__tests")]
#[doc(hidden)]
pub fn parse(s: &str) -> FzfQuery<'static> {
let parser = Box::leak(Box::new(FzfParser::new()));
@@ -561,7 +561,7 @@ mod patterns_tests {
}
}

#[cfg(feature = "tests")]
#[cfg(feature = "__tests")]
#[doc(hidden)]
pub fn words(s: &str) -> impl Iterator<Item = String> {
let mut buf = Vec::new();
8 changes: 4 additions & 4 deletions tests/fzf_common.rs
Original file line number Diff line number Diff line change
@@ -579,12 +579,12 @@ mod utils {
}

fn scheme(&self) -> &norm::fzf::Scheme {
#[cfg(feature = "tests")]
#[cfg(feature = "__tests")]
{
self.scheme()
}

#[cfg(not(feature = "tests"))]
#[cfg(not(feature = "__tests"))]
{
unreachable!()
}
@@ -600,12 +600,12 @@ mod utils {
}

fn scheme(&self) -> &norm::fzf::Scheme {
#[cfg(feature = "tests")]
#[cfg(feature = "__tests")]
{
self.scheme()
}

#[cfg(not(feature = "tests"))]
#[cfg(not(feature = "__tests"))]
{
unreachable!()
}

0 comments on commit 92dc405

Please sign in to comment.