mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-20 15:14:18 +02:00
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:
parent
49f2f8a3dd
commit
cdbca5c53b
2 changed files with 15 additions and 2 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue