Skip to content

Commit 0e51e8f

Browse files
committed
fix: used tokio api over std for fs and removed the dbg code
1 parent 752026a commit 0e51e8f

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/main.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use notify::event::RemoveKind;
33
use notify_debouncer_full::DebouncedEvent;
44
use notify_debouncer_full::{DebounceEventResult, new_debouncer, notify::*};
55
use pulldown_cmark::Options;
6-
use std::fs;
76
use std::path::Path;
7+
use tokio::fs;
88
use tokio::time::Duration;
99
mod args;
1010
use actix_web::App;
@@ -97,8 +97,7 @@ async fn ws_handler(
9797
break;
9898
}
9999
if matches!(event.kind, EventKind::Modify(ModifyKind::Data(_))) {
100-
println!("File modified");
101-
let latest_markdown = match get_markdown(&file_path) {
100+
let latest_markdown = match get_markdown(&file_path).await {
102101
Ok(md) => md,
103102
Err(e) => {
104103
eprintln!("Error reading markdown file: {e}");
@@ -117,8 +116,8 @@ async fn ws_handler(
117116
Ok(response)
118117
}
119118

120-
pub fn get_markdown(file_path: &String) -> std::io::Result<String> {
121-
let markdown_input: String = fs::read_to_string(file_path)?;
119+
async fn get_markdown(file_path: &String) -> std::io::Result<String> {
120+
let markdown_input: String = fs::read_to_string(file_path).await?;
122121
let options = Options::all();
123122
let parser = pulldown_cmark::Parser::new_ext(&markdown_input, options);
124123

@@ -130,11 +129,11 @@ pub fn get_markdown(file_path: &String) -> std::io::Result<String> {
130129

131130
#[derive(Template)]
132131
#[template(path = "main.html")]
133-
pub struct Mdwatch {
134-
pub content: String,
135-
pub title: String,
136-
pub style: String,
137-
pub script: String,
132+
struct Mdwatch {
133+
content: String,
134+
title: String,
135+
style: String,
136+
script: String,
138137
}
139138

140139
#[get("/")]
@@ -162,7 +161,7 @@ async fn home(file: web::Data<String>) -> actix_web::Result<HttpResponse> {
162161
));
163162
};
164163

165-
let html_output = match get_markdown(&file.as_str().to_string()) {
164+
let html_output = match get_markdown(&file.as_str().to_string()).await {
166165
Ok(html) => html,
167166
Err(e) => {
168167
eprintln!("Error processing markdown file: {e}");

0 commit comments

Comments
 (0)