cleanup and file error
This commit is contained in:
parent
ea7cd57c07
commit
ad557e822f
|
|
@ -10,6 +10,11 @@ pub struct File {
|
||||||
pub date: NaiveDate,
|
pub date: NaiveDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum FileError{
|
||||||
|
//IOError(&'static str),
|
||||||
|
ParseError(&'static str)
|
||||||
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
fn capture_as_number<T: FromStr>(capture: ®ex::Captures, name: &str) -> Result<T, String> {
|
fn capture_as_number<T: FromStr>(capture: ®ex::Captures, name: &str) -> Result<T, String> {
|
||||||
Ok(capture
|
Ok(capture
|
||||||
|
|
@ -37,7 +42,7 @@ impl File {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<DirEntry> for File {
|
impl TryFrom<DirEntry> for File {
|
||||||
type Error = String;
|
type Error = FileError;
|
||||||
|
|
||||||
fn try_from(direntry: DirEntry) -> Result<Self, Self::Error> {
|
fn try_from(direntry: DirEntry) -> Result<Self, Self::Error> {
|
||||||
let re = File::get_file_regex();
|
let re = File::get_file_regex();
|
||||||
|
|
@ -59,10 +64,6 @@ impl TryFrom<DirEntry> for File {
|
||||||
date: NaiveDate::from_ymd_opt(year, month, day).unwrap(),
|
date: NaiveDate::from_ymd_opt(year, month, day).unwrap(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Err(format!(
|
Err(FileError::ParseError("Could not parse file name"))
|
||||||
"Could not parse file name => {{ name: {:?}, re: {:?} }}",
|
|
||||||
file_name, re
|
|
||||||
)
|
|
||||||
.to_string())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ pub struct TaskGroup {
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
pub status: Status,
|
pub status: Status,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
level: u8,
|
// level: u8,
|
||||||
pub subtasks: Option<Vec<Task>>,
|
pub subtasks: Option<Vec<Task>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,17 +31,6 @@ pub enum TaskError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
fn find_text<'a>(node: &'a AstNode<'a>) -> String {
|
|
||||||
let mut text = String::new();
|
|
||||||
for child in node.descendants() {
|
|
||||||
let data_ref = child.data.borrow();
|
|
||||||
if let NodeValue::Text(contents) = &data_ref.value {
|
|
||||||
text.push_str(format!("{}\n ", &contents.clone()).as_str());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
text
|
|
||||||
}
|
|
||||||
|
|
||||||
fn extract_text<'a>(node: &'a AstNode<'a>) -> Result<String, TaskError> {
|
fn extract_text<'a>(node: &'a AstNode<'a>) -> Result<String, TaskError> {
|
||||||
let data_ref = node.data.borrow();
|
let data_ref = node.data.borrow();
|
||||||
if let NodeValue::Text(contents) = &data_ref.value {
|
if let NodeValue::Text(contents) = &data_ref.value {
|
||||||
|
|
@ -144,7 +133,7 @@ impl<'a> TryFrom<&'a AstNode<'a>> for Task {
|
||||||
status,
|
status,
|
||||||
text,
|
text,
|
||||||
subtasks,
|
subtasks,
|
||||||
level: 1,
|
// level: 1,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(TaskError::ParsingError(
|
Err(TaskError::ParsingError(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue