Convert emacs wrapper to tokio's Command.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user