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