This commit is contained in:
Edward Shen 2022-06-02 22:46:10 -07:00
parent 90ff4461a6
commit f1d7797637
Signed by: edward
GPG key ID: 19182661E818369F
7 changed files with 868 additions and 895 deletions

View file

@ -1,3 +0,0 @@
tab_spaces = 2
use_field_init_shorthand = true
max_width = 80

View file

@ -287,9 +287,9 @@ pub fn get_config_data() -> Result<FileData, BunBunError> {
file,
});
}
Err(e) => debug!(
"Tried to open a new file at '{location:?}' but failed due to error: {e}",
),
Err(e) => {
debug!("Tried to open a new file at '{location:?}' but failed due to error: {e}",)
}
}
}
@ -298,9 +298,7 @@ pub fn get_config_data() -> Result<FileData, BunBunError> {
/// Assumes that the user knows what they're talking about and will only try
/// to load the config at the given path.
pub fn load_custom_file(
path: impl Into<PathBuf>,
) -> Result<FileData, BunBunError> {
pub fn load_custom_file(path: impl Into<PathBuf>) -> Result<FileData, BunBunError> {
let path = path.into();
let file = OpenOptions::new()
.read(true)
@ -310,10 +308,7 @@ pub fn load_custom_file(
Ok(FileData { path, file })
}
pub fn load_file(
mut config_file: File,
large_config: bool,
) -> Result<Config, BunBunError> {
pub fn load_file(mut config_file: File, large_config: bool) -> Result<Config, BunBunError> {
trace!("Loading config file.");
let file_size = config_file.metadata()?.len();
@ -414,8 +409,7 @@ mod read_config {
let size_to_write = (LARGE_FILE_SIZE_THRESHOLD + 1) as usize;
config_file.write(&[0].repeat(size_to_write))?;
match load_file(config_file, false) {
Err(BunBunError::ConfigTooLarge(size))
if size as usize == size_to_write => {}
Err(BunBunError::ConfigTooLarge(size)) if size as usize == size_to_write => {}
Err(BunBunError::ConfigTooLarge(size)) => {
panic!("Mismatched size: {size} != {size_to_write}")
}

View file

@ -6,9 +6,7 @@
//! search engine and quick-jump tool in one small binary. For information on
//! usage, please take a look at the readme.
use crate::config::{
get_config_data, load_custom_file, load_file, FileData, Route, RouteGroup,
};
use crate::config::{get_config_data, load_custom_file, load_file, FileData, Route, RouteGroup};
use anyhow::Result;
use arc_swap::ArcSwap;
use axum::routing::get;
@ -85,8 +83,7 @@ async fn main() -> Result<()> {
/// verbose flags is non-zero then the quiet flag is zero, and vice versa.
#[cfg(not(tarpaulin_include))]
fn init_logger(num_verbose_flags: u8, num_quiet_flags: u8) -> Result<()> {
let log_level =
match min(num_verbose_flags, 3) as i8 - min(num_quiet_flags, 2) as i8 {
let log_level = match min(num_verbose_flags, 3) as i8 - min(num_quiet_flags, 2) as i8 {
-2 => None,
-1 => Some(log::LevelFilter::Error),
0 => Some(log::LevelFilter::Warn),
@ -197,9 +194,7 @@ fn start_watch(
match watch_result {
Ok(_) => info!("Watcher is now watching {path:?}"),
Err(e) => {
warn!(
"Couldn't watch {path:?}: {e}. Changes to this file won't be seen!"
);
warn!("Couldn't watch {path:?}: {e}. Changes to this file won't be seen!");
}
}
@ -244,9 +239,7 @@ mod cache_routes {
use super::*;
use std::iter::FromIterator;
fn generate_external_routes(
routes: &[(&'static str, &'static str)],
) -> HashMap<String, Route> {
fn generate_external_routes(routes: &[(&'static str, &'static str)]) -> HashMap<String, Route> {
HashMap::from_iter(
routes
.into_iter()
@ -277,12 +270,7 @@ mod cache_routes {
assert_eq!(
cache_routes(vec![group1, group2]),
generate_external_routes(&[
("a", "b"),
("c", "d"),
("1", "2"),
("3", "4")
])
generate_external_routes(&[("a", "b"), ("c", "d"), ("1", "2"), ("3", "4")])
);
}

View file

@ -108,10 +108,7 @@ pub async fn hop(
let rendered = handlebars
.render_template(
&path,
&template_args::query(utf8_percent_encode(
&args,
FRAGMENT_ENCODE_SET,
)),
&template_args::query(utf8_percent_encode(&args, FRAGMENT_ENCODE_SET)),
)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Response::builder()
@ -243,10 +240,7 @@ mod resolve_hop {
use super::*;
use anyhow::Result;
fn generate_route_result<'a>(
keyword: &'a Route,
args: &str,
) -> RouteResolution<'a> {
fn generate_route_result<'a>(keyword: &'a Route, args: &str) -> RouteResolution<'a> {
RouteResolution::Resolved {
route: keyword,
args: String::from(args),