Starting the owner tree module.
This commit is contained in:
parent
65aba3c993
commit
40bf188c5a
21
src/main.rs
21
src/main.rs
@ -1,7 +1,7 @@
|
|||||||
#![feature(exit_status_error)]
|
#![feature(exit_status_error)]
|
||||||
use axum::{http::StatusCode, routing::post, Json, Router};
|
use axum::{http::StatusCode, routing::post, Json, Router};
|
||||||
|
use owner_tree::{build_owner_tree, OwnerTree};
|
||||||
use parse::emacs_parse_org_document;
|
use parse::emacs_parse_org_document;
|
||||||
use serde::Serialize;
|
|
||||||
use tower_http::services::{ServeDir, ServeFile};
|
use tower_http::services::{ServeDir, ServeFile};
|
||||||
|
|
||||||
mod owner_tree;
|
mod owner_tree;
|
||||||
@ -18,13 +18,18 @@ async fn main() {
|
|||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn parse_org_mode(body: String) -> Result<(StatusCode, Json<OwnerTree>), (StatusCode, String)> {
|
async fn parse_org_mode(
|
||||||
let ast = emacs_parse_org_document(&body).await.map_err(|e| (StatusCode::BAD_REQUEST, e.to_string()))?;
|
body: String,
|
||||||
let ret = OwnerTree { input_source: body };
|
) -> Result<(StatusCode, Json<OwnerTree>), (StatusCode, String)> {
|
||||||
Ok((StatusCode::OK, Json(ret)))
|
_parse_org_mode(body)
|
||||||
|
.await
|
||||||
|
.map_err(|e| (StatusCode::BAD_REQUEST, e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
async fn _parse_org_mode(
|
||||||
struct OwnerTree {
|
body: String,
|
||||||
input_source: String,
|
) -> Result<(StatusCode, Json<OwnerTree>), Box<dyn std::error::Error>> {
|
||||||
|
let ast = emacs_parse_org_document(&body).await?;
|
||||||
|
let owner_tree = build_owner_tree(body)?;
|
||||||
|
Ok((StatusCode::OK, Json(owner_tree)))
|
||||||
}
|
}
|
||||||
|
@ -1 +1,15 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
pub fn build_owner_tree<C>(file_contents: C) -> Result<OwnerTree, Box<dyn std::error::Error>>
|
||||||
|
where
|
||||||
|
C: AsRef<str>,
|
||||||
|
{
|
||||||
|
Ok(OwnerTree {
|
||||||
|
input_source: file_contents.as_ref().to_owned(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct OwnerTree {
|
||||||
|
input_source: String,
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user