Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/zrx-id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ mod builder;
mod convert;
mod error;
pub mod expression;
pub mod filter;
pub mod format;
mod macros;
pub mod matcher;
pub mod selector;
pub mod sequence;
pub mod specificity;
pub mod uri;

Expand Down
8 changes: 8 additions & 0 deletions crates/zrx-id/src/id/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ impl TryToId for Id {
}
}

impl TryToId for &Id {
/// Attempts to convert to an identifier.
#[inline]
fn try_to_id(&self) -> Result<Cow<'_, Id>> {
TryToId::try_to_id(*self)
}
}

// ----------------------------------------------------------------------------
// Blanket implementations
// ----------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions crates/zrx-id/src/id/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@

use std::vec::IntoIter;

use zrx_scheduler::Value;

mod builder;
mod error;
pub mod filter;
mod operand;

pub use builder::Builder;
pub use error::{Error, Result};
pub use filter::Filter;
pub use operand::{Operand, Operator, Term};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -114,6 +118,10 @@ impl Expression {
// Trait implementations
// ----------------------------------------------------------------------------

impl Value for Expression {}

// ----------------------------------------------------------------------------

impl<T> From<T> for Expression
where
T: Into<Term>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

use slab::Slab;

use super::matcher::Matcher;
use crate::id::matcher::Matcher;

mod builder;
mod candidates;
Expand Down Expand Up @@ -60,12 +60,21 @@ pub use terms::Terms;
/// the condition set is the second stage, which checks whether the remaining
/// expressions are actually satisfied by the identifier.
///
/// Additionally, the [`Filter`] contains two indexing structures:
///
/// - [`Filter::negations`]: Contains the indices of all conditions that have
/// at least one negation in ascending order for efficient pruning.
///
/// - [`Filter::mapping`]: Contains one item per term per condition, which maps
/// the indices of terms matched by the matcher to the containing conditions.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{selector, Expression, Filter, Id};
/// use zrx_id::expression::Filter;
/// use zrx_id::{selector, Expression, Id};
///
/// // Create filter builder and insert expression
/// let mut builder = Filter::builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Filter {
/// # Examples
///
/// ```
/// use zrx_id::Filter;
/// use zrx_id::expression::Filter;
///
/// // Create filter builder
/// let mut builder = Filter::builder();
Expand All @@ -79,7 +79,7 @@ impl Filter {
/// # Examples
///
/// ```
/// use zrx_id::Filter;
/// use zrx_id::expression::Filter;
///
/// // Create filter
/// let filter = Filter::default();
Expand All @@ -99,22 +99,21 @@ impl Filter {
impl Builder {
/// Inserts an expression into the filter and returns its index.
///
/// This method adds an [`Expression`][] to the filter builder, and returns
/// This method adds an [`Expression`] to the filter builder, and returns
/// the index of the inserted condition, which can be used to remove it.
///
/// Note that the expression is immediately converted into a [`Condition`]
/// for performance reasons, which means it cannot be recovered. If we'd
/// store expressions directly, removing or inserting new expressions into
/// the filter would mandate recompilation of all expressions.
///
/// [`Expression`]: crate::id::expression::Expression
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{selector, Expression, Filter};
/// use zrx_id::expression::Filter;
/// use zrx_id::{selector, Expression};
///
/// // Create filter builder and insert expression
/// let mut builder = Filter::builder();
Expand All @@ -141,7 +140,8 @@ impl Builder {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{selector, Expression, Filter};
/// use zrx_id::expression::Filter;
/// use zrx_id::{selector, Expression};
///
/// // Create filter builder and insert expression
/// let mut builder = Filter::builder();
Expand All @@ -166,14 +166,15 @@ impl Builder {
///
/// Returns [`Error::Matcher`][] if the underlying matcher can't be built.
///
/// [`Error::Matcher`]: crate::id::filter::Error::Matcher
/// [`Error::Matcher`]: crate::id::expression::filter::Error::Matcher
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{selector, Expression, Filter};
/// use zrx_id::expression::Filter;
/// use zrx_id::{selector, Expression};
///
/// // Create filter builder and insert expression
/// let mut builder = Filter::builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ impl Filter {
///
/// Returns [`Error::Matcher`][] if the identifier is invalid.
///
/// [`Error::Matcher`]: crate::id::filter::Error::Matcher
/// [`Error::Matcher`]: crate::id::expression::filter::Error::Matcher
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{selector, Expression, Filter, Id};
/// use zrx_id::expression::Filter;
/// use zrx_id::{selector, Expression, Id};
///
/// // Create filter builder and insert expression
/// let mut builder = Filter::builder();
Expand Down Expand Up @@ -193,8 +194,8 @@ impl Iterator for Candidates<'_> {
mod tests {

mod matches {
use crate::id::expression::filter::{Filter, Result};
use crate::id::expression::Expression;
use crate::id::filter::{Filter, Result};
use crate::selector;

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod builder;
mod group;
mod instruction;

pub use instruction::Instruction;
use instruction::Instruction;

// ----------------------------------------------------------------------------
// Structs
Expand Down Expand Up @@ -133,8 +133,8 @@ impl Condition {
mod tests {

mod satisfies {
use crate::id::expression::filter::Condition;
use crate::id::expression::{Expression, Result};
use crate::id::filter::Condition;
use crate::id::matcher::Matches;
use crate::selector;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use crate::id::expression::{Expression, Operand, Operator, Term};
use crate::id::matcher::Matches;

use super::group::Group;
use super::{Condition, Instruction};
use super::instruction::Instruction;
use super::Condition;

// ----------------------------------------------------------------------------
// Structs
Expand All @@ -56,7 +57,7 @@ impl Condition {
/// extracting all terms along the way. The resulting builder can then be
/// transformed into a [`Condition`], which is used in a [`Filter`][].
///
/// [`Filter`]: crate::id::filter::Filter
/// [`Filter`]: crate::id::expression::filter::Filter
#[inline]
#[must_use]
pub fn builder<T>(expr: T) -> Builder
Expand All @@ -75,6 +76,7 @@ impl Condition {

impl Builder {
/// Builds the condition.
#[must_use]
pub fn build(self) -> Condition {
let mut input = Vec::from([(self.group, None)]);
let mut stack = Vec::new();
Expand Down Expand Up @@ -238,9 +240,9 @@ fn optimize_hoistable(group: Group) -> Group {
mod tests {

mod builder {
use crate::id::expression::filter::condition::group::Group;
use crate::id::expression::filter::Condition;
use crate::id::expression::{Expression, Operator, Result, Term};
use crate::id::filter::condition::group::Group;
use crate::id::filter::Condition;
use crate::selector;

#[test]
Expand Down Expand Up @@ -302,9 +304,9 @@ mod tests {
}

mod optimize {
use crate::id::expression::filter::condition::group::Group;
use crate::id::expression::filter::Condition;
use crate::id::expression::{Expression, Operator, Result};
use crate::id::filter::condition::group::Group;
use crate::id::filter::Condition;
use crate::id::matcher::Matches;
use crate::selector;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl Filter {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{selector, Expression, Filter};
/// use zrx_id::expression::Filter;
/// use zrx_id::{selector, Expression};
///
/// // Create filter builder and insert expression
/// let mut builder = Filter::builder();
Expand Down
11 changes: 7 additions & 4 deletions crates/zrx-id/src/id/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ pub use matches::Matches;
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{Id, Matcher};
/// use zrx_id::matcher::Matcher;
/// use zrx_id::Id;
///
/// // Create matcher builder and add selector
/// let mut builder = Matcher::builder();
Expand Down Expand Up @@ -117,7 +118,8 @@ impl Matcher {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{Id, Matcher};
/// use zrx_id::matcher::Matcher;
/// use zrx_id::Id;
///
/// // Create matcher builder and add selector
/// let mut builder = Matcher::builder();
Expand Down Expand Up @@ -161,7 +163,8 @@ impl Matcher {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::{Id, Matcher, Matches};
/// use zrx_id::matcher::{Matcher, Matches};
/// use zrx_id::Id;
///
/// // Create matcher builder and add selector
/// let mut builder = Matcher::builder();
Expand Down Expand Up @@ -242,7 +245,7 @@ impl FromStr for Matcher {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::Matcher;
/// use zrx_id::matcher::Matcher;
///
/// // Create matcher from string
/// let matcher: Matcher = "zrs:::::**/*.md:".parse()?;
Expand Down
8 changes: 4 additions & 4 deletions crates/zrx-id/src/id/matcher/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Matcher {
/// # Examples
///
/// ```
/// use zrx_id::Matcher;
/// use zrx_id::matcher::Matcher;
///
/// // Create matcher builder
/// let mut builder = Matcher::builder();
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Builder {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::Matcher;
/// use zrx_id::matcher::Matcher;
///
/// // Create matcher builder with selector
/// let mut builder = Matcher::builder().with(&"zrs:::::**/*.md:")?;
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Builder {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::Matcher;
/// use zrx_id::matcher::Matcher;
///
/// // Create matcher builder and add selector
/// let mut builder = Matcher::builder();
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Builder {
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_id::Matcher;
/// use zrx_id::matcher::Matcher;
///
/// // Create matcher builder and add selector
/// let mut builder = Matcher::builder();
Expand Down
Loading
Loading