Skip to content

Commit 3d954a2

Browse files
committed
fix: resolve clippy warnings and apply cargo fmt for v1.3
1 parent f8fcb3a commit 3d954a2

4 files changed

Lines changed: 58 additions & 40 deletions

File tree

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct HttpConfig {
4141
pub enabled: bool,
4242
pub port: u16,
4343
pub host: String,
44-
pub rate_limit: u32, // requests per minute per key, 0 = unlimited
44+
pub rate_limit: u32, // requests per minute per key, 0 = unlimited
4545
pub cors_origins: Vec<String>,
4646
pub api_keys: Vec<ApiKeyConfig>,
4747
}

src/http.rs

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ use std::time::Instant;
44

55
use axum::extract::{Path, Query, State};
66
use axum::http::{HeaderMap, HeaderValue, Method};
7-
use axum::{Json, Router, http::StatusCode, response::IntoResponse, routing::{get, post}};
7+
use axum::{
8+
Json, Router,
9+
http::StatusCode,
10+
response::IntoResponse,
11+
routing::{get, post},
12+
};
813
use serde::Deserialize;
914
use tokio::sync::Mutex;
1015
use tower_http::cors::{Any, CorsLayer};
@@ -334,10 +339,7 @@ fn cors_layer(origins: &[String]) -> CorsLayer {
334339
.allow_methods(Any)
335340
.allow_headers(Any);
336341
}
337-
let origins: Vec<HeaderValue> = origins
338-
.iter()
339-
.filter_map(|o| o.parse().ok())
340-
.collect();
342+
let origins: Vec<HeaderValue> = origins.iter().filter_map(|o| o.parse().ok()).collect();
341343
CorsLayer::new()
342344
.allow_origin(origins)
343345
.allow_methods([Method::GET, Method::POST, Method::OPTIONS])
@@ -433,8 +435,8 @@ async fn handle_read(
433435
vault_path: &state.vault_path,
434436
profile: state.profile.as_ref().as_ref(),
435437
};
436-
let note = context::context_read(&ctx, &file)
437-
.map_err(|e| ApiError::internal(&format!("{e:#}")))?;
438+
let note =
439+
context::context_read(&ctx, &file).map_err(|e| ApiError::internal(&format!("{e:#}")))?;
438440
Ok(Json(serde_json::json!(note)))
439441
}
440442

@@ -485,8 +487,7 @@ async fn handle_vault_map(
485487
vault_path: &state.vault_path,
486488
profile: state.profile.as_ref().as_ref(),
487489
};
488-
let map = context::vault_map(&ctx)
489-
.map_err(|e| ApiError::internal(&format!("{e:#}")))?;
490+
let map = context::vault_map(&ctx).map_err(|e| ApiError::internal(&format!("{e:#}")))?;
490491
Ok(Json(serde_json::json!(map)))
491492
}
492493

@@ -502,8 +503,8 @@ async fn handle_who(
502503
vault_path: &state.vault_path,
503504
profile: state.profile.as_ref().as_ref(),
504505
};
505-
let person = context::context_who(&ctx, &name)
506-
.map_err(|e| ApiError::internal(&format!("{e:#}")))?;
506+
let person =
507+
context::context_who(&ctx, &name).map_err(|e| ApiError::internal(&format!("{e:#}")))?;
507508
Ok(Json(serde_json::json!(person)))
508509
}
509510

@@ -519,8 +520,8 @@ async fn handle_project(
519520
vault_path: &state.vault_path,
520521
profile: state.profile.as_ref().as_ref(),
521522
};
522-
let proj = context::context_project(&ctx, &name)
523-
.map_err(|e| ApiError::internal(&format!("{e:#}")))?;
523+
let proj =
524+
context::context_project(&ctx, &name).map_err(|e| ApiError::internal(&format!("{e:#}")))?;
524525
Ok(Json(serde_json::json!(proj)))
525526
}
526527

@@ -576,55 +577,64 @@ async fn record_write(recent_writes: &RecentWrites, path: &std::path::Path) {
576577
fn parse_frontmatter_ops(operations: &[serde_json::Value]) -> Result<Vec<FrontmatterOp>, ApiError> {
577578
let mut ops = Vec::with_capacity(operations.len());
578579
for op_val in operations {
579-
let op_str = op_val
580-
.get("op")
581-
.and_then(|v| v.as_str())
582-
.ok_or_else(|| ApiError::bad_request("each operation must have an \"op\" string field"))?;
580+
let op_str = op_val.get("op").and_then(|v| v.as_str()).ok_or_else(|| {
581+
ApiError::bad_request("each operation must have an \"op\" string field")
582+
})?;
583583
match op_str {
584584
"set" => {
585-
let key = op_val
586-
.get("key")
587-
.and_then(|v| v.as_str())
588-
.ok_or_else(|| ApiError::bad_request("\"set\" operation requires a \"key\" field"))?;
585+
let key = op_val.get("key").and_then(|v| v.as_str()).ok_or_else(|| {
586+
ApiError::bad_request("\"set\" operation requires a \"key\" field")
587+
})?;
589588
let value = op_val
590589
.get("value")
591590
.and_then(|v| v.as_str())
592-
.ok_or_else(|| ApiError::bad_request("\"set\" operation requires a \"value\" field"))?;
591+
.ok_or_else(|| {
592+
ApiError::bad_request("\"set\" operation requires a \"value\" field")
593+
})?;
593594
ops.push(FrontmatterOp::Set(key.to_string(), value.to_string()));
594595
}
595596
"remove" => {
596-
let key = op_val
597-
.get("key")
598-
.and_then(|v| v.as_str())
599-
.ok_or_else(|| ApiError::bad_request("\"remove\" operation requires a \"key\" field"))?;
597+
let key = op_val.get("key").and_then(|v| v.as_str()).ok_or_else(|| {
598+
ApiError::bad_request("\"remove\" operation requires a \"key\" field")
599+
})?;
600600
ops.push(FrontmatterOp::Remove(key.to_string()));
601601
}
602602
"add_tag" => {
603603
let value = op_val
604604
.get("value")
605605
.and_then(|v| v.as_str())
606-
.ok_or_else(|| ApiError::bad_request("\"add_tag\" operation requires a \"value\" field"))?;
606+
.ok_or_else(|| {
607+
ApiError::bad_request("\"add_tag\" operation requires a \"value\" field")
608+
})?;
607609
ops.push(FrontmatterOp::AddTag(value.to_string()));
608610
}
609611
"remove_tag" => {
610612
let value = op_val
611613
.get("value")
612614
.and_then(|v| v.as_str())
613-
.ok_or_else(|| ApiError::bad_request("\"remove_tag\" operation requires a \"value\" field"))?;
615+
.ok_or_else(|| {
616+
ApiError::bad_request("\"remove_tag\" operation requires a \"value\" field")
617+
})?;
614618
ops.push(FrontmatterOp::RemoveTag(value.to_string()));
615619
}
616620
"add_alias" => {
617621
let value = op_val
618622
.get("value")
619623
.and_then(|v| v.as_str())
620-
.ok_or_else(|| ApiError::bad_request("\"add_alias\" operation requires a \"value\" field"))?;
624+
.ok_or_else(|| {
625+
ApiError::bad_request("\"add_alias\" operation requires a \"value\" field")
626+
})?;
621627
ops.push(FrontmatterOp::AddAlias(value.to_string()));
622628
}
623629
"remove_alias" => {
624630
let value = op_val
625631
.get("value")
626632
.and_then(|v| v.as_str())
627-
.ok_or_else(|| ApiError::bad_request("\"remove_alias\" operation requires a \"value\" field"))?;
633+
.ok_or_else(|| {
634+
ApiError::bad_request(
635+
"\"remove_alias\" operation requires a \"value\" field",
636+
)
637+
})?;
628638
ops.push(FrontmatterOp::RemoveAlias(value.to_string()));
629639
}
630640
unknown => {
@@ -905,7 +915,9 @@ mod tests {
905915
let rate_limiter = Arc::new(RateLimiter::new(config.rate_limit));
906916
ApiState {
907917
store: Arc::new(Mutex::new(store)),
908-
embedder: Arc::new(Mutex::new(Box::new(DummyEmbedder) as Box<dyn EmbedModel + Send>)),
918+
embedder: Arc::new(Mutex::new(
919+
Box::new(DummyEmbedder) as Box<dyn EmbedModel + Send>
920+
)),
909921
vault_path: Arc::new(PathBuf::from("/tmp/test-vault")),
910922
profile: Arc::new(None),
911923
orchestrator: None,

src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,12 @@ async fn main() -> Result<()> {
11311131
}
11321132
}
11331133

1134-
Command::Serve { http, port, host, no_auth } => {
1134+
Command::Serve {
1135+
http,
1136+
port,
1137+
host,
1138+
no_auth,
1139+
} => {
11351140
if !index_exists(&data_dir) {
11361141
eprintln!("No index found. Run 'engraph index <path>' first.");
11371142
std::process::exit(1);

src/serve.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,14 @@ pub struct HttpServeOpts {
745745
// ---------------------------------------------------------------------------
746746

747747
pub async fn run_serve(data_dir: &Path, http_opts: Option<HttpServeOpts>) -> Result<()> {
748-
if let Some(ref opts) = http_opts {
749-
if opts.no_auth && opts.host != "127.0.0.1" {
750-
anyhow::bail!(
751-
"--no-auth cannot be used with --host {} (only 127.0.0.1 is allowed)",
752-
opts.host
753-
);
754-
}
748+
if let Some(ref opts) = http_opts
749+
&& opts.no_auth
750+
&& opts.host != "127.0.0.1"
751+
{
752+
anyhow::bail!(
753+
"--no-auth cannot be used with --host {} (only 127.0.0.1 is allowed)",
754+
opts.host
755+
);
755756
}
756757

757758
let db_path = data_dir.join("engraph.db");

0 commit comments

Comments
 (0)