Switch to using CustomError because a boxed StdError is not Send.
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use tokio::task::JoinHandle;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::error::CustomError;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct BlogPost {
|
||||
pub(crate) struct BlogPost {
|
||||
id: String,
|
||||
}
|
||||
|
||||
@@ -7,11 +15,8 @@ impl BlogPost {
|
||||
pub(crate) async fn load_blog_post<P: AsRef<Path>, R: AsRef<Path>>(
|
||||
root_dir: R,
|
||||
post_dir: P,
|
||||
) -> Result<BlogPost, Box<dyn std::error::Error>> {
|
||||
async fn inner(
|
||||
root_dir: &Path,
|
||||
post_dir: &Path,
|
||||
) -> Result<BlogPost, Box<dyn std::error::Error>> {
|
||||
) -> Result<BlogPost, CustomError> {
|
||||
async fn inner(root_dir: &Path, post_dir: &Path) -> Result<BlogPost, CustomError> {
|
||||
let org_files = {
|
||||
let mut ret = Vec::new();
|
||||
let org_files_iter = get_org_files(post_dir)?;
|
||||
@@ -23,7 +28,8 @@ impl BlogPost {
|
||||
let parsed_org_files = {
|
||||
let mut ret = Vec::new();
|
||||
for (path, contents) in org_files.iter() {
|
||||
let parsed = organic::parser::parse_file(contents.as_str(), Some(path))?;
|
||||
let parsed = organic::parser::parse_file(contents.as_str(), Some(path))
|
||||
.map_err(|_| CustomError::Static("Failed to parse org-mode document."))?;
|
||||
ret.push((path, contents, parsed));
|
||||
}
|
||||
ret
|
||||
@@ -37,6 +43,11 @@ impl BlogPost {
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_file(path: PathBuf) -> std::io::Result<(PathBuf, String)> {
|
||||
let contents = tokio::fs::read_to_string(&path).await?;
|
||||
Ok((path, contents))
|
||||
}
|
||||
|
||||
fn get_org_files<P: AsRef<Path>>(
|
||||
root_dir: P,
|
||||
) -> Result<impl Iterator<Item = JoinHandle<std::io::Result<(PathBuf, String)>>>, walkdir::Error> {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
mod definition;
|
||||
pub(crate) use definition::BlogPost;
|
||||
|
||||
Reference in New Issue
Block a user