mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-08 14:00:37 +00:00
Run cargo fmt
across repository
This commit is contained in:
parent
78451d9ba0
commit
454e47d2ac
@ -17,13 +17,13 @@ use custom::CustomAdapterConfig;
|
|||||||
use log::*;
|
use log::*;
|
||||||
use tokio::io::AsyncRead;
|
use tokio::io::AsyncRead;
|
||||||
|
|
||||||
|
use core::fmt::Debug;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use core::fmt::Debug;
|
|
||||||
|
|
||||||
pub type ReadBox = Pin<Box<dyn AsyncRead + Send>>;
|
pub type ReadBox = Pin<Box<dyn AsyncRead + Send>>;
|
||||||
pub struct AdapterMeta {
|
pub struct AdapterMeta {
|
||||||
@ -78,7 +78,7 @@ impl AdapterMeta {
|
|||||||
pub trait GetMetadata {
|
pub trait GetMetadata {
|
||||||
fn metadata(&self) -> &AdapterMeta;
|
fn metadata(&self) -> &AdapterMeta;
|
||||||
}
|
}
|
||||||
pub trait FileAdapter: GetMetadata + Send + Sync{
|
pub trait FileAdapter: GetMetadata + Send + Sync {
|
||||||
/// adapt a file.
|
/// adapt a file.
|
||||||
///
|
///
|
||||||
/// detection_reason is the Matcher that was used to identify this file. Unless --rga-accurate was given, it is always a FastMatcher
|
/// detection_reason is the Matcher that was used to identify this file. Unless --rga-accurate was given, it is always a FastMatcher
|
||||||
|
@ -4,19 +4,17 @@
|
|||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use async_stream::stream;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use encoding_rs_io::DecodeReaderBytesBuilder;
|
use encoding_rs_io::DecodeReaderBytesBuilder;
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt};
|
use std::cmp::min;
|
||||||
use async_stream::stream;
|
|
||||||
use tokio_util::io::ReaderStream;
|
|
||||||
use tokio_util::io::StreamReader;
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::{
|
use tokio::io::{AsyncRead, AsyncReadExt};
|
||||||
cmp::min,
|
use tokio_util::io::ReaderStream;
|
||||||
};
|
use tokio_util::io::StreamReader;
|
||||||
|
|
||||||
use crate::adapted_iter::{AdaptedFilesIterBox};
|
use crate::adapted_iter::AdaptedFilesIterBox;
|
||||||
|
|
||||||
use super::{AdaptInfo, AdapterMeta, FileAdapter, GetMetadata};
|
use super::{AdaptInfo, AdapterMeta, FileAdapter, GetMetadata};
|
||||||
|
|
||||||
@ -177,18 +175,30 @@ pub fn postproc_pagebreaks(line_prefix: &str, inp: impl AsyncRead) -> impl Async
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tokio::pin;
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
use tokio::pin;
|
||||||
|
|
||||||
async fn test_from_strs(pagebreaks: bool, line_prefix: &str, a: &'static str, b: &str) -> Result<()> {
|
async fn test_from_strs(
|
||||||
|
pagebreaks: bool,
|
||||||
|
line_prefix: &str,
|
||||||
|
a: &'static str,
|
||||||
|
b: &str,
|
||||||
|
) -> Result<()> {
|
||||||
test_from_bytes(pagebreaks, line_prefix, a.as_bytes(), b).await
|
test_from_bytes(pagebreaks, line_prefix, a.as_bytes(), b).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn test_from_bytes(pagebreaks: bool, line_prefix: &str, a: &'static [u8], b: &str) -> Result<()> {
|
async fn test_from_bytes(
|
||||||
|
pagebreaks: bool,
|
||||||
|
line_prefix: &str,
|
||||||
|
a: &'static [u8],
|
||||||
|
b: &str,
|
||||||
|
) -> Result<()> {
|
||||||
let mut oup = Vec::new();
|
let mut oup = Vec::new();
|
||||||
let inp = postproc_encoding("", a)?;
|
let inp = postproc_encoding("", a)?;
|
||||||
if pagebreaks {
|
if pagebreaks {
|
||||||
postproc_pagebreaks(line_prefix, inp).read_to_end(&mut oup).await?;
|
postproc_pagebreaks(line_prefix, inp)
|
||||||
|
.read_to_end(&mut oup)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
let x = postproc_prefix(line_prefix, inp);
|
let x = postproc_prefix(line_prefix, inp);
|
||||||
pin!(x);
|
pin!(x);
|
||||||
@ -231,7 +241,8 @@ mod tests {
|
|||||||
"foo:",
|
"foo:",
|
||||||
"this is a test \n\n \0 foo",
|
"this is a test \n\n \0 foo",
|
||||||
"foo:[rga: binary data]",
|
"foo:[rga: binary data]",
|
||||||
).await?;
|
)
|
||||||
|
.await?;
|
||||||
test_from_strs(false, "foo:", "\0", "foo:[rga: binary data]").await?;
|
test_from_strs(false, "foo:", "\0", "foo:[rga: binary data]").await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_stream::{stream, AsyncStream};
|
use async_stream::{stream, AsyncStream};
|
||||||
|
@ -5,7 +5,7 @@ use ripgrep_all as rga;
|
|||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::{time::Instant};
|
use std::time::Instant;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -20,7 +20,9 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
std::env::current_dir()?.join(&filepath)
|
std::env::current_dir()?.join(&filepath)
|
||||||
};
|
};
|
||||||
|
|
||||||
let i = File::open(&path).await.context("Specified input file not found")?;
|
let i = File::open(&path)
|
||||||
|
.await
|
||||||
|
.context("Specified input file not found")?;
|
||||||
let mut o = tokio::io::stdout();
|
let mut o = tokio::io::stdout();
|
||||||
let ai = AdaptInfo {
|
let ai = AdaptInfo {
|
||||||
inp: Box::pin(i),
|
inp: Box::pin(i),
|
||||||
|
@ -17,11 +17,11 @@ use crate::adapters::ReadBox;
|
|||||||
* unless more than max_cache_size bytes is written, then the cache is dropped and it is pure passthrough.
|
* unless more than max_cache_size bytes is written, then the cache is dropped and it is pure passthrough.
|
||||||
*/
|
*/
|
||||||
pub fn async_read_and_write_to_cache<'a>(
|
pub fn async_read_and_write_to_cache<'a>(
|
||||||
inp: impl AsyncRead + Send +'a,
|
inp: impl AsyncRead + Send + 'a,
|
||||||
max_cache_size: usize,
|
max_cache_size: usize,
|
||||||
compression_level: i32,
|
compression_level: i32,
|
||||||
on_finish: Box<dyn FnOnce((u64, Option<Vec<u8>>)) -> Result<()> + Send>,
|
on_finish: Box<dyn FnOnce((u64, Option<Vec<u8>>)) -> Result<()> + Send>,
|
||||||
) -> Result<Pin<Box<dyn AsyncRead + Send +'a>>> {
|
) -> Result<Pin<Box<dyn AsyncRead + Send + 'a>>> {
|
||||||
let inp = Box::pin(inp);
|
let inp = Box::pin(inp);
|
||||||
let mut zstd_writer = Some(ZstdEncoder::with_quality(
|
let mut zstd_writer = Some(ZstdEncoder::with_quality(
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{adapters::custom::CustomAdapterConfig, project_dirs};
|
use crate::{adapters::custom::CustomAdapterConfig, project_dirs};
|
||||||
use anyhow::{Result, Context};
|
use anyhow::{Context, Result};
|
||||||
use derive_more::FromStr;
|
use derive_more::FromStr;
|
||||||
use log::*;
|
use log::*;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
@ -237,7 +237,7 @@ pub struct CacheConfig {
|
|||||||
default_value,
|
default_value,
|
||||||
long = "--rga-cache-path",
|
long = "--rga-cache-path",
|
||||||
hidden_short_help = true,
|
hidden_short_help = true,
|
||||||
require_equals = true,
|
require_equals = true
|
||||||
)]
|
)]
|
||||||
pub path: CachePath,
|
pub path: CachePath,
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ use async_compression::tokio::bufread::ZstdDecoder;
|
|||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
use log::*;
|
use log::*;
|
||||||
use path_clean::PathClean;
|
use path_clean::PathClean;
|
||||||
use std::sync::Arc;
|
|
||||||
use postproc::PostprocPrefix;
|
use postproc::PostprocPrefix;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::sync::Arc;
|
||||||
use tokio::io::AsyncBufRead;
|
use tokio::io::AsyncBufRead;
|
||||||
use tokio::io::AsyncBufReadExt;
|
use tokio::io::AsyncBufReadExt;
|
||||||
use tokio::io::BufReader;
|
use tokio::io::BufReader;
|
||||||
|
@ -3,10 +3,7 @@ use tokio_util::io::{ReaderStream, StreamReader};
|
|||||||
use crate::{adapted_iter::AdaptedFilesIterBox, adapters::*};
|
use crate::{adapted_iter::AdaptedFilesIterBox, adapters::*};
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
|
|
||||||
|
pub fn concat_read_streams(input: AdaptedFilesIterBox) -> ReadBox {
|
||||||
pub fn concat_read_streams(
|
|
||||||
input: AdaptedFilesIterBox,
|
|
||||||
) -> ReadBox {
|
|
||||||
let s = stream! {
|
let s = stream! {
|
||||||
for await output in input {
|
for await output in input {
|
||||||
let stream = ReaderStream::new(output.inp);
|
let stream = ReaderStream::new(output.inp);
|
||||||
@ -16,4 +13,4 @@ pub fn concat_read_streams(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Box::pin(StreamReader::new(s))
|
Box::pin(StreamReader::new(s))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user