Convert emacs wrapper to tokio's Command.
This commit is contained in:
parent
0d2a13739a
commit
65aba3c993
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -524,6 +524,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.4.9"
|
||||
@ -573,6 +582,7 @@ dependencies = [
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2 0.5.3",
|
||||
"tokio-macros",
|
||||
"windows-sys",
|
||||
|
@ -7,5 +7,5 @@ edition = "2021"
|
||||
axum = { git = "https://github.com/tokio-rs/axum.git", rev = "52a90390195e884bcc12ff5bd9fd805cac806447" }
|
||||
nom = "7.1.1"
|
||||
serde = { version = "1.0.183", features = ["derive"] }
|
||||
tokio = { version = "1.30.0", default-features = false, features = ["macros", "rt", "rt-multi-thread"] }
|
||||
tokio = { version = "1.30.0", default-features = false, features = ["macros", "process", "rt", "rt-multi-thread"] }
|
||||
tower-http = { version = "0.4.3", features = ["fs"] }
|
||||
|
@ -1,8 +1,10 @@
|
||||
#![feature(exit_status_error)]
|
||||
use axum::{http::StatusCode, routing::post, Json, Router};
|
||||
use parse::emacs_parse_org_document;
|
||||
use serde::Serialize;
|
||||
use tower_http::services::{ServeDir, ServeFile};
|
||||
|
||||
mod owner_tree;
|
||||
mod parse;
|
||||
|
||||
#[tokio::main]
|
||||
@ -16,9 +18,10 @@ async fn main() {
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
||||
async fn parse_org_mode(body: String) -> (StatusCode, Json<OwnerTree>) {
|
||||
async fn parse_org_mode(body: String) -> Result<(StatusCode, Json<OwnerTree>), (StatusCode, String)> {
|
||||
let ast = emacs_parse_org_document(&body).await.map_err(|e| (StatusCode::BAD_REQUEST, e.to_string()))?;
|
||||
let ret = OwnerTree { input_source: body };
|
||||
(StatusCode::OK, Json(ret))
|
||||
Ok((StatusCode::OK, Json(ret)))
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
1
src/owner_tree.rs
Normal file
1
src/owner_tree.rs
Normal file
@ -0,0 +1 @@
|
||||
|
12
src/parse.rs
12
src/parse.rs
@ -1,6 +1,8 @@
|
||||
use std::process::Command;
|
||||
use tokio::process::Command;
|
||||
|
||||
pub fn emacs_parse_org_document<C>(file_contents: C) -> Result<String, Box<dyn std::error::Error>>
|
||||
pub async fn emacs_parse_org_document<C>(
|
||||
file_contents: C,
|
||||
) -> Result<String, Box<dyn std::error::Error>>
|
||||
where
|
||||
C: AsRef<str>,
|
||||
{
|
||||
@ -22,10 +24,10 @@ where
|
||||
.arg("--batch")
|
||||
.arg("--eval")
|
||||
.arg(elisp_script);
|
||||
let out = proc.output()?;
|
||||
|
||||
let out = proc.output().await?;
|
||||
out.status.exit_ok()?;
|
||||
let org_sexp = out.stderr;
|
||||
Ok(String::from_utf8(org_sexp)?)
|
||||
Ok(String::from_utf8(out.stderr)?)
|
||||
}
|
||||
|
||||
fn escape_elisp_string<C>(file_contents: C) -> String
|
||||
|
Loading…
Reference in New Issue
Block a user