pub mod answer;
mod cancel;
pub mod cell;
pub mod decode;
pub mod handshake;
mod lower;
pub mod plane;
mod readout;
pub mod relay;
#[cfg(unix)]
pub mod session;
pub mod shell;
pub mod sys;
mod verify;
#[cfg(test)]
mod fixture;
#[cfg(unix)]
pub use session::{Session, default_socket_path, warm_eligible};
use std::fmt;
use std::os::raw::c_void;
pub use answer::{Batch, BatchIter, RowIter, Rows, Stats, Tier};
pub use cancel::CancelToken;
pub use cell::{OwnedRow, OwnedValue, RowSeq, Texts, Value};
pub use decode::Row;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
NotFound(String),
UnsupportedPattern(String),
BadPattern(String),
Failed(String),
Unrepresentable(String),
SchemaDrift(String),
Decode(String),
Uncancellable,
Io(std::io::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotFound(m) => write!(f, "irregex: {m}"),
Self::UnsupportedPattern(m) => write!(f, "unsupported pattern: {m}"),
Self::BadPattern(m) => write!(f, "malformed pattern: {m}"),
Self::Failed(m) => write!(f, "gist search failed: {m}"),
Self::Unrepresentable(m) => write!(f, "option not representable in-process: {m}"),
Self::SchemaDrift(m) => write!(f, "analytic schema drift: {m}"),
Self::Decode(m) => write!(f, "analytic row does not match its schema: {m}"),
Self::Uncancellable => write!(
f,
"this process has no in-process analytic plane to cancel; \
every verb still answers through the subprocess tier"
),
Self::Io(e) => write!(f, "gist io error: {e}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
pub trait Query {
fn op(&self) -> u32;
fn wire(&self) -> Wire<'_>;
fn argv(&self) -> Result<relay::Invocation>;
fn roots(&self) -> &[std::path::PathBuf];
fn texts(&self) -> Vec<&str> {
Vec::new()
}
fn cwd(&self) -> Option<&std::path::Path> {
None
}
}
pub enum Wire<'a> {
Kinship(sys::KinshipParams, std::marker::PhantomData<&'a ()>),
Retrieval(sys::RetrievalParams, std::marker::PhantomData<&'a ()>),
Sweep(sys::SweepParams, std::marker::PhantomData<&'a ()>),
Compose(sys::ComposeParams, std::marker::PhantomData<&'a ()>),
Rank(sys::RankParams, std::marker::PhantomData<&'a ()>),
}
impl<'a> Wire<'a> {
pub fn bind(&mut self, texts: &'a [sys::Text]) {
let (ptr, n) = (texts.as_ptr(), texts.len());
match self {
Self::Sweep(p, _) => (p.patterns, p.npatterns) = (ptr, n),
Self::Compose(p, _) => (p.patterns, p.npatterns) = (ptr, n),
_ => {},
}
}
pub fn as_ptr(&self) -> *const c_void {
match self {
Self::Kinship(p, _) => std::ptr::from_ref(p).cast(),
Self::Retrieval(p, _) => std::ptr::from_ref(p).cast(),
Self::Sweep(p, _) => std::ptr::from_ref(p).cast(),
Self::Compose(p, _) => std::ptr::from_ref(p).cast(),
Self::Rank(p, _) => std::ptr::from_ref(p).cast(),
}
}
}
pub fn struct_size<T>() -> u32 {
u32::try_from(std::mem::size_of::<T>()).unwrap_or(u32::MAX)
}
pub fn answer(query: &impl Query) -> Result<Rows> {
match plane::run(query)? {
Some(rows) => Ok(rows),
None => relay::run(query),
}
}