Cargo fmt

This commit is contained in:
Candifloss 2026-04-22 16:06:28 +05:30
parent 2f597030b5
commit e6737d3b4e
3 changed files with 29 additions and 38 deletions

View File

@ -1,8 +1,8 @@
use rusqlite::{Connection, Result};
use std::sync::Mutex;
use rusqlite::types::Value;
use rusqlite::types::Value;
pub struct Db {
conn: Mutex<Connection>,
}
@ -27,25 +27,25 @@ impl Db {
let col_count = stmt.column_count();
let rows_iter = stmt.query_map([], move |row| {
let mut r = Vec::new();
for i in 0..col_count {
let val: Value = row.get(i)?;
let s = match val {
Value::Null => "<null>".to_string(),
Value::Integer(i) => i.to_string(),
Value::Real(f) => f.to_string(),
Value::Text(t) => t, // already String
Value::Blob(_) => "<blob>".to_string(),
};
r.push(s);
}
Ok(r)
})?;
let rows_iter = stmt.query_map([], move |row| {
let mut r = Vec::new();
for i in 0..col_count {
let val: Value = row.get(i)?;
let s = match val {
Value::Null => "<null>".to_string(),
Value::Integer(i) => i.to_string(),
Value::Real(f) => f.to_string(),
Value::Text(t) => t, // already String
Value::Blob(_) => "<blob>".to_string(),
};
r.push(s);
}
Ok(r)
})?;
let mut rows = Vec::new();
for r in rows_iter {
@ -54,4 +54,4 @@ impl Db {
Ok((columns, rows))
}
}
}

View File

@ -1,4 +1,4 @@
use axum::{routing::get, Router};
use axum::{Router, routing::get};
use clap::Parser;
use std::sync::Arc;
use tokio::net::TcpListener;
@ -20,17 +20,11 @@ async fn main() {
let db = Arc::new(Db::open(&args.db).expect("db open failed"));
let app = Router::new()
.route("/", get(routes::index))
.with_state(db);
let app = Router::new().route("/", get(routes::index)).with_state(db);
let listener = TcpListener::bind("127.0.0.1:8040")
.await
.unwrap();
let listener = TcpListener::bind("127.0.0.1:8040").await.unwrap();
println!("http://127.0.0.1:8040");
axum::serve(listener, app)
.await
.unwrap();
}
axum::serve(listener, app).await.unwrap();
}

View File

@ -1,9 +1,6 @@
use askama::Template; // REQUIRED
use axum::{
extract::State,
response::Html,
};
use axum::{extract::State, response::Html};
use std::sync::Arc;
use crate::db::Db;
@ -26,4 +23,4 @@ pub async fn index(State(db): State<Arc<Db>>) -> Html<String> {
};
Html(tmpl.render().unwrap())
}
}