Skip to main content

mant_query/
scope_query.rs

1//! Pure queries over an already-loaded, caller-owned document snapshot.
2mod input;
3mod search;
4pub use input::{QueryScopeView, ScopeInputError};
5pub use search::search_scope;
6
7use std::{error::Error, fmt};
8
9/// Query failures independent of catalog resolution and source I/O.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum ScopeExecutionError {
12    /// The explanation request is invalid.
13    Explanation(crate::ExplanationError),
14    /// The search request or matcher is invalid.
15    Search(crate::SearchError),
16    /// None of the supplied snapshots contains readable explanation content.
17    NoReadableDocuments {
18        /// Per-document content failures in the supplied stable order.
19        reasons: Vec<String>,
20    },
21}
22
23impl fmt::Display for ScopeExecutionError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            Self::Explanation(error) => error.fmt(f),
27            Self::Search(error) => error.fmt(f),
28            Self::NoReadableDocuments { reasons } => {
29                f.write_str("none of the supplied documents contains readable content")?;
30                if !reasons.is_empty() {
31                    write!(f, ": {}", reasons.join("; "))?;
32                }
33                Ok(())
34            }
35        }
36    }
37}
38
39impl Error for ScopeExecutionError {
40    fn source(&self) -> Option<&(dyn Error + 'static)> {
41        match self {
42            Self::Explanation(error) => Some(error),
43            Self::Search(error) => Some(error),
44            Self::NoReadableDocuments { .. } => None,
45        }
46    }
47}
48
49/// Explain across existing snapshots with global classification and paging.
50/// No catalog lookup, parsing or source acquisition is performed.
51///
52/// # Errors
53/// Returns invalid explanation bounds or failures when all content is unreadable.
54pub fn explain_scope(
55    input: QueryScopeView<'_>,
56    query: &mant_protocol::ExplanationQuery,
57) -> Result<mant_protocol::ScopeExplanation, ScopeExecutionError> {
58    crate::explanation::explain_scope(input, query)
59}