Merge a2db02bbc0
into 1bd7691d47
commit
f7b95f8f9b
@ -1,23 +1,91 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "argparse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37bb99f5e39ee8b23b6e227f5b8f024207e8616f44aa4b8c76ecd828011667ef"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "0.5.3"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "displaydoc"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fingertips"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"argparse 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"argparse",
|
||||
"byteorder",
|
||||
"displaydoc",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum argparse 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37bb99f5e39ee8b23b6e227f5b8f024207e8616f44aa4b8c76ecd828011667ef"
|
||||
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
@ -0,0 +1,45 @@
|
||||
//! `fingertips` creates an inverted index for a set of text files.
|
||||
//!
|
||||
//! Most of the actual work is done by the modules `index`, `read`, `write`,
|
||||
//! and `merge`. In this file, `main.rs`, we put the pieces together in two
|
||||
//! different ways.
|
||||
//!
|
||||
//! * `run_single_threaded` simply does everything in one thread, in
|
||||
//! the most straightforward possible way.
|
||||
//!
|
||||
//! * Then, we break the work into a five-stage pipeline so that we can run
|
||||
//! it on multiple CPUs. `run_pipeline` puts the five stages together.
|
||||
//!
|
||||
//! This is the `main` function that handles command-line arguments. It calls one
|
||||
//! of the two functions above to do the work.
|
||||
|
||||
use argparse::{ArgumentParser, Collect, StoreTrue};
|
||||
use fingertips::run;
|
||||
|
||||
fn main() {
|
||||
let mut single_threaded = false;
|
||||
let mut filenames = vec![];
|
||||
|
||||
{
|
||||
let mut ap = ArgumentParser::new();
|
||||
ap.set_description("Make an inverted index for searching documents.");
|
||||
_ = ap.refer(&mut single_threaded).add_option(
|
||||
&["-1", "--single-threaded"],
|
||||
StoreTrue,
|
||||
"Do all the work on a single thread.",
|
||||
);
|
||||
_ = ap.refer(&mut filenames).add_argument(
|
||||
"filenames",
|
||||
Collect,
|
||||
"Names of files/directories to index. \
|
||||
For directories, all .txt files immediately \
|
||||
under the directory are indexed.",
|
||||
);
|
||||
ap.parse_args_or_exit();
|
||||
}
|
||||
|
||||
match run(filenames, single_threaded) {
|
||||
Ok(()) => {}
|
||||
Err(err) => println!("error: {err}"),
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
use std::error::Error;
|
||||
|
||||
/// Result type that is being returned from methods that can fail and thus have [`FingertipsError`]s.
|
||||
pub type FingertipsResult<T> = Result<T, FingertipsError>;
|
||||
|
||||
/// Errors that can result from Fingertips.
|
||||
// [`Error`] is public, but opaque and easy to keep compatible.
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
#[error(transparent)]
|
||||
pub struct FingertipsError(#[from] FingertipsErrorKind);
|
||||
|
||||
// Accessors for anything we do want to expose publicly.
|
||||
impl FingertipsError {
|
||||
/// Expose the inner error kind.
|
||||
///
|
||||
/// This is useful for matching on the error kind.
|
||||
pub fn into_inner(self) -> FingertipsErrorKind {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// [`FingertipsErrorKind`] describes the errors that can happen while executing a high-level command.
|
||||
///
|
||||
/// This is a non-exhaustive enum, so additional variants may be added in future. It is
|
||||
/// recommended to match against the wildcard `_` instead of listing all possible variants,
|
||||
/// to avoid problems when new variants are added.
|
||||
#[non_exhaustive]
|
||||
#[derive(thiserror::Error, Debug, displaydoc::Display)]
|
||||
pub enum FingertipsErrorKind {
|
||||
/// An error occurred while reading from or writing to a file.
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
/// An error occurred while parsing a file
|
||||
TermEmpty,
|
||||
/// An error occured in the algorithm
|
||||
AlgorithmError,
|
||||
/// No entry to move
|
||||
NoEntryToMove,
|
||||
/// Computer not big enough to hold index entry, you may be on 32bit platform
|
||||
PlatformLimitExceeded,
|
||||
}
|
||||
|
||||
trait FingertipsErrorMarker: Error {}
|
||||
|
||||
// impl FingertipsErrorMarker for FingertipErrorsInTheCodeBase {}
|
||||
|
||||
impl<E> From<E> for FingertipsError
|
||||
where
|
||||
E: FingertipsErrorMarker,
|
||||
FingertipsErrorKind: From<E>,
|
||||
{
|
||||
fn from(value: E) -> Self {
|
||||
Self(FingertipsErrorKind::from(value))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue