Add FindFrom extension trait to str to start searching at a byte offset.

This also moves the contents of `dedup.rs` into a shared module `extensions`.
This commit is contained in:
Niklas Mohrin 2021-05-21 12:36:32 +02:00
commit cdbca5c53b
No known key found for this signature in database
GPG key ID: 0ACD89A5C1DEB3EB
2 changed files with 15 additions and 2 deletions

View file

@ -18,3 +18,16 @@ impl<T: PartialEq + Clone> Dedup<T> for Vec<T> {
}
}
}
/// Like `str::find`, but starts searching at `start`.
pub(crate) trait FindFrom {
fn find_from(&self, needle: &Self, start: usize) -> Option<usize>;
}
impl FindFrom for str {
fn find_from(&self, needle: &Self, start: usize) -> Option<usize> {
self.get(start..)
.and_then(|s| s.find(needle))
.map(|i| i + start)
}
}

View file

@ -31,16 +31,16 @@ use serde_derive::Deserialize;
mod cache;
mod config;
mod dedup;
mod error;
pub mod extensions;
mod formatter;
mod tokenizer;
mod types;
use crate::cache::{Cache, PageLookupResult};
use crate::config::{get_config_dir, get_config_path, make_default_config, Config, MAX_CACHE_AGE};
use crate::dedup::Dedup;
use crate::error::TealdeerError::ConfigError;
use crate::extensions::Dedup;
use crate::formatter::print_lines;
use crate::tokenizer::Tokenizer;
use crate::types::{ColorOptions, OsType};