legit-hasher 0.1.6

Every legit-hashes definition, images and text, for callers in any language: a command-line runner over JSON lines with resumable batches, and with the `serve` feature a worker that takes hashing tasks from Redis Streams
Documentation
//! One implementation of the [`legit_hashes`] definitions for callers in any language: requests in
//! and results out as JSON lines, from a command line or, with the `serve` feature, Redis Streams.
//!
//! The `legit-hasher` binary is a thin shell around this library. The core is [`hash`], one
//! [`Request`] in and one [`Outcome`] out, which never panics and turns every failure into an
//! error result. [`run`] drives a batch of requests on a pool of threads with bounded memory,
//! skipping those an earlier run's output already answers ([`Finished`]). [`distances`] compares
//! stored hashes and signatures, and [`Info`] reports the definitions, the limits and the CPU.
//!
//! ```
//! use legit_hasher::{Request, Settings, Status, hash};
//!
//! let line = br#"{"id": "greeting", "text": "hello there, world",
//!     "options": {"format": 1, "definitions": [{"id": "minhash-v1", "shingle": 5, "band_keys": 16}]}}"#;
//! let request = Request::from_json(line).map_err(|outcome| outcome.to_json())?;
//! let outcome = hash(&request, Settings::default());
//! assert_eq!(outcome.status, Status::Success);
//! let result = &outcome.hashes.as_ref().expect("a successful result has hashes")[0];
//! assert!(result.value.as_deref().is_some_and(|value| value.starts_with("minhash-v1:")));
//! assert_eq!(result.band_keys.as_ref().map(Vec::len), Some(16));
//! # Ok::<(), String>(())
//! ```
//!
//! A definition's output is the same on every machine. The runner detects the CPU only to report
//! it; nothing it detects changes a hash.

#![forbid(unsafe_code)]

mod base64;
mod definition;
mod distance;
mod error;
mod hasher;
mod info;
mod inspect;
mod orient;
mod outcome;
mod request;
mod resume;
mod run;
#[cfg(feature = "serve")]
pub mod serve;

pub use definition::{Definition, DefinitionFailure, Input, MAX_SHINGLE, Plan, Tokens};
pub use distance::{Comparison, DistanceError, compare, distances};
pub use error::{Error, Result};
pub use hasher::{MAX_METADATA_BYTES, Settings, hash};
pub use info::{Cpu, DefinitionInfo, Info, Limits, MALLOC_VARIABLE, Malloc, PEAK_BYTES_PER_PIXEL, ServeInfo};
pub use outcome::{
    DecodeFacts, DefinitionError, HashOutcome, Outcome, RUNNER, RequestError, Runner, SourceFacts, Status, Timings,
};
pub use request::{Entry, Id, MAX_DEFINITIONS, MAX_OPTIONS_BYTES, Options, Orientation, Request, Source};
pub use resume::Finished;
pub use run::{DEFAULT_MAX_LINE_BYTES, RunConfig, Summary, run};

/// The version of the request and result formats: `1`. Every result line and `info` carry it,
/// and a request's `options` must name it. A breaking change to either format raises it.
pub const FORMAT: u32 = 1;

/// The README's examples, compiled and run as doctests.
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;