Skip to content

Commit

Permalink
Remove unused newtypes and add documentation for the remaining ones
Browse files Browse the repository at this point in the history
  • Loading branch information
torrancew committed Jul 14, 2024
1 parent bb3ae90 commit 8b4ed03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 12 additions & 58 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocCount> for u32 {
fn from(value: DocCount) -> Self {
value.0.into()
}
}

impl From<DocCount> for ffi::doccount {
fn from(value: DocCount) -> Self {
value.0
}
}

impl From<u32> for DocCount {
fn from(value: u32) -> Self {
Self(value.into())
}
}

impl From<ffi::doccount> for DocCount {
fn from(value: ffi::doccount) -> Self {
Self(value)
}
}

#[derive(Debug, Clone, Copy)]
pub struct DocCountDiff(ffi::doccount_diff);

impl From<i32> for DocCountDiff {
fn from(value: i32) -> Self {
Self(value.into())
}
}

impl From<ffi::doccount_diff> for DocCountDiff {
fn from(value: ffi::doccount_diff) -> Self {
Self(value)
}
}

impl From<DocCountDiff> for i32 {
fn from(value: DocCountDiff) -> Self {
value.0.into()
}
}

impl From<DocCountDiff> 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<u32>) -> Option<Self> {
NonZeroU32::new(value.into()).map(Self)
}
Expand Down Expand Up @@ -136,6 +86,8 @@ impl From<Position> 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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -264,13 +218,13 @@ impl From<u32> for Slot {
}

impl From<Slot> for u32 {
fn from(s: Slot) -> Self {
s.into()
fn from(slot: Slot) -> Self {
u32::from(slot.0)
}
}

impl From<Slot> for ffi::valueno {
fn from(s: Slot) -> Self {
s.0
fn from(slot: Slot) -> Self {
slot.0
}
}

0 comments on commit 8b4ed03

Please sign in to comment.