Reformat
This commit is contained in:
parent
90ff4461a6
commit
f1d7797637
7 changed files with 868 additions and 895 deletions
|
@ -1,3 +0,0 @@
|
||||||
tab_spaces = 2
|
|
||||||
use_field_init_shorthand = true
|
|
||||||
max_width = 80
|
|
|
@ -287,9 +287,9 @@ pub fn get_config_data() -> Result<FileData, BunBunError> {
|
||||||
file,
|
file,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(e) => debug!(
|
Err(e) => {
|
||||||
"Tried to open a new file at '{location:?}' but failed due to error: {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
|
/// Assumes that the user knows what they're talking about and will only try
|
||||||
/// to load the config at the given path.
|
/// to load the config at the given path.
|
||||||
pub fn load_custom_file(
|
pub fn load_custom_file(path: impl Into<PathBuf>) -> Result<FileData, BunBunError> {
|
||||||
path: impl Into<PathBuf>,
|
|
||||||
) -> Result<FileData, BunBunError> {
|
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let file = OpenOptions::new()
|
let file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
|
@ -310,10 +308,7 @@ pub fn load_custom_file(
|
||||||
Ok(FileData { path, file })
|
Ok(FileData { path, file })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_file(
|
pub fn load_file(mut config_file: File, large_config: bool) -> Result<Config, BunBunError> {
|
||||||
mut config_file: File,
|
|
||||||
large_config: bool,
|
|
||||||
) -> Result<Config, BunBunError> {
|
|
||||||
trace!("Loading config file.");
|
trace!("Loading config file.");
|
||||||
let file_size = config_file.metadata()?.len();
|
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;
|
let size_to_write = (LARGE_FILE_SIZE_THRESHOLD + 1) as usize;
|
||||||
config_file.write(&[0].repeat(size_to_write))?;
|
config_file.write(&[0].repeat(size_to_write))?;
|
||||||
match load_file(config_file, false) {
|
match load_file(config_file, false) {
|
||||||
Err(BunBunError::ConfigTooLarge(size))
|
Err(BunBunError::ConfigTooLarge(size)) if size as usize == size_to_write => {}
|
||||||
if size as usize == size_to_write => {}
|
|
||||||
Err(BunBunError::ConfigTooLarge(size)) => {
|
Err(BunBunError::ConfigTooLarge(size)) => {
|
||||||
panic!("Mismatched size: {size} != {size_to_write}")
|
panic!("Mismatched size: {size} != {size_to_write}")
|
||||||
}
|
}
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -6,9 +6,7 @@
|
||||||
//! search engine and quick-jump tool in one small binary. For information on
|
//! search engine and quick-jump tool in one small binary. For information on
|
||||||
//! usage, please take a look at the readme.
|
//! usage, please take a look at the readme.
|
||||||
|
|
||||||
use crate::config::{
|
use crate::config::{get_config_data, load_custom_file, load_file, FileData, Route, RouteGroup};
|
||||||
get_config_data, load_custom_file, load_file, FileData, Route, RouteGroup,
|
|
||||||
};
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use arc_swap::ArcSwap;
|
use arc_swap::ArcSwap;
|
||||||
use axum::routing::get;
|
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.
|
/// verbose flags is non-zero then the quiet flag is zero, and vice versa.
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn init_logger(num_verbose_flags: u8, num_quiet_flags: u8) -> Result<()> {
|
fn init_logger(num_verbose_flags: u8, num_quiet_flags: u8) -> Result<()> {
|
||||||
let log_level =
|
let log_level = match min(num_verbose_flags, 3) as i8 - min(num_quiet_flags, 2) as i8 {
|
||||||
match min(num_verbose_flags, 3) as i8 - min(num_quiet_flags, 2) as i8 {
|
|
||||||
-2 => None,
|
-2 => None,
|
||||||
-1 => Some(log::LevelFilter::Error),
|
-1 => Some(log::LevelFilter::Error),
|
||||||
0 => Some(log::LevelFilter::Warn),
|
0 => Some(log::LevelFilter::Warn),
|
||||||
|
@ -197,9 +194,7 @@ fn start_watch(
|
||||||
match watch_result {
|
match watch_result {
|
||||||
Ok(_) => info!("Watcher is now watching {path:?}"),
|
Ok(_) => info!("Watcher is now watching {path:?}"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!(
|
warn!("Couldn't watch {path:?}: {e}. Changes to this file won't be seen!");
|
||||||
"Couldn't watch {path:?}: {e}. Changes to this file won't be seen!"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,9 +239,7 @@ mod cache_routes {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
fn generate_external_routes(
|
fn generate_external_routes(routes: &[(&'static str, &'static str)]) -> HashMap<String, Route> {
|
||||||
routes: &[(&'static str, &'static str)],
|
|
||||||
) -> HashMap<String, Route> {
|
|
||||||
HashMap::from_iter(
|
HashMap::from_iter(
|
||||||
routes
|
routes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -277,12 +270,7 @@ mod cache_routes {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cache_routes(vec![group1, group2]),
|
cache_routes(vec![group1, group2]),
|
||||||
generate_external_routes(&[
|
generate_external_routes(&[("a", "b"), ("c", "d"), ("1", "2"), ("3", "4")])
|
||||||
("a", "b"),
|
|
||||||
("c", "d"),
|
|
||||||
("1", "2"),
|
|
||||||
("3", "4")
|
|
||||||
])
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,10 +108,7 @@ pub async fn hop(
|
||||||
let rendered = handlebars
|
let rendered = handlebars
|
||||||
.render_template(
|
.render_template(
|
||||||
&path,
|
&path,
|
||||||
&template_args::query(utf8_percent_encode(
|
&template_args::query(utf8_percent_encode(&args, FRAGMENT_ENCODE_SET)),
|
||||||
&args,
|
|
||||||
FRAGMENT_ENCODE_SET,
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
Response::builder()
|
Response::builder()
|
||||||
|
@ -243,10 +240,7 @@ mod resolve_hop {
|
||||||
use super::*;
|
use super::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
fn generate_route_result<'a>(
|
fn generate_route_result<'a>(keyword: &'a Route, args: &str) -> RouteResolution<'a> {
|
||||||
keyword: &'a Route,
|
|
||||||
args: &str,
|
|
||||||
) -> RouteResolution<'a> {
|
|
||||||
RouteResolution::Resolved {
|
RouteResolution::Resolved {
|
||||||
route: keyword,
|
route: keyword,
|
||||||
args: String::from(args),
|
args: String::from(args),
|
||||||
|
|
Loading…
Reference in a new issue