diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58592c8..02b9936 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Install dependencies run: | - sudo apt-get update && sudo apt-get install -y libxapian-dev + sudo apt-get update && sudo apt-get install -y libxapian-dev libxapian30 - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: diff --git a/Cargo.lock b/Cargo.lock index 7cfa3f6..1958800 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,7 +1104,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "xapian-rs" -version = "0.1.0" +version = "0.1.1-dev" dependencies = [ "anyhow", "autocxx", diff --git a/src/lib.rs b/src/lib.rs index a96f920..861548d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,64 +24,14 @@ pub use search::{ mod term; pub use term::{Stem, StemStrategy, Stopper, Term, TermGenerator}; -#[derive(Debug, Clone, Copy)] -pub struct DocCount(ffi::doccount); - -impl From for u32 { - fn from(value: DocCount) -> Self { - value.0.into() - } -} - -impl From for ffi::doccount { - fn from(value: DocCount) -> Self { - value.0 - } -} - -impl From for DocCount { - fn from(value: u32) -> Self { - Self(value.into()) - } -} - -impl From for DocCount { - fn from(value: ffi::doccount) -> Self { - Self(value) - } -} - -#[derive(Debug, Clone, Copy)] -pub struct DocCountDiff(ffi::doccount_diff); - -impl From for DocCountDiff { - fn from(value: i32) -> Self { - Self(value.into()) - } -} - -impl From for DocCountDiff { - fn from(value: ffi::doccount_diff) -> Self { - Self(value) - } -} - -impl From for i32 { - fn from(value: DocCountDiff) -> Self { - value.0.into() - } -} - -impl From for ffi::doccount_diff { - fn from(value: DocCountDiff) -> Self { - value.0 - } -} - +/// A newtype wrapper representing a valid (non-zero) Xapian document ID #[derive(Debug, Clone, Copy)] pub struct DocId(NonZeroU32); impl DocId { + /// Attempt to create a `DocId` from the provided `u32` + /// Returns `None` if the `u32` is `0`, to match Xapian's + /// document ID semantics pub fn new(value: impl Into) -> Option { NonZeroU32::new(value.into()).map(Self) } @@ -136,6 +86,8 @@ impl From for ffi::termpos { } } +/// A trait representing the ability to be stored as a Xapian document value. Useful for features +/// such as faceting and other forms of advanced field-level filtering. pub trait ToValue: Clone { fn serialize(&self) -> Bytes; } @@ -199,6 +151,7 @@ impl ToValue for &String { } } +/// A trait representing the ability to be loaded from a Xapian document value. pub trait FromValue: Clone + PartialEq + PartialOrd + Sized { type Error: std::error::Error; @@ -254,6 +207,7 @@ impl FromValue for String { } } +/// A newtype wrapper representing a valid Xapian slot number (aka `valueno`) #[derive(Debug, Clone, Copy)] pub struct Slot(ffi::valueno); @@ -264,13 +218,13 @@ impl From for Slot { } impl From for u32 { - fn from(s: Slot) -> Self { - s.into() + fn from(slot: Slot) -> Self { + u32::from(slot.0) } } impl From for ffi::valueno { - fn from(s: Slot) -> Self { - s.0 + fn from(slot: Slot) -> Self { + slot.0 } }